summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/man/EVP_DigestInit.3207
1 files changed, 129 insertions, 78 deletions
diff --git a/src/lib/libcrypto/man/EVP_DigestInit.3 b/src/lib/libcrypto/man/EVP_DigestInit.3
index c327164bc0..9e2f3d0665 100644
--- a/src/lib/libcrypto/man/EVP_DigestInit.3
+++ b/src/lib/libcrypto/man/EVP_DigestInit.3
@@ -1,8 +1,9 @@
1.\" $OpenBSD: EVP_DigestInit.3,v 1.6 2017/03/25 17:54:04 schwarze Exp $ 1.\" $OpenBSD: EVP_DigestInit.3,v 1.7 2018/02/18 20:11:16 schwarze Exp $
2.\" OpenSSL d2a56999 Sep 24 13:37:16 2016 +0200 2.\" full merge up to: OpenSSL 7f572e95 Dec 2 13:57:04 2015 +0000
3.\" OpenSSL 7f572e95 Dec 2 13:57:04 2015 +0000 3.\" selective merge up to: OpenSSL a95d7574 Jul 2 12:16:38 2017 -0400
4.\" 4.\"
5.\" This file was written by Dr. Stephen Henson <steve@openssl.org>. 5.\" This file was written by Dr. Stephen Henson <steve@openssl.org>
6.\" and Richard Levitte <levitte@openssl.org>.
6.\" Copyright (c) 2000-2004, 2009, 2012-2016 The OpenSSL Project. 7.\" Copyright (c) 2000-2004, 2009, 2012-2016 The OpenSSL Project.
7.\" All rights reserved. 8.\" All rights reserved.
8.\" 9.\"
@@ -50,18 +51,21 @@
50.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 51.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51.\" OF THE POSSIBILITY OF SUCH DAMAGE. 52.\" OF THE POSSIBILITY OF SUCH DAMAGE.
52.\" 53.\"
53.Dd $Mdocdate: March 25 2017 $ 54.Dd $Mdocdate: February 18 2018 $
54.Dt EVP_DIGESTINIT 3 55.Dt EVP_DIGESTINIT 3
55.Os 56.Os
56.Sh NAME 57.Sh NAME
58.Nm EVP_MD_CTX_new ,
59.Nm EVP_MD_CTX_reset ,
60.Nm EVP_MD_CTX_free ,
57.Nm EVP_MD_CTX_init , 61.Nm EVP_MD_CTX_init ,
58.Nm EVP_MD_CTX_create , 62.Nm EVP_MD_CTX_create ,
63.Nm EVP_MD_CTX_cleanup ,
64.Nm EVP_MD_CTX_destroy ,
59.Nm EVP_MD_CTX_ctrl , 65.Nm EVP_MD_CTX_ctrl ,
60.Nm EVP_DigestInit_ex , 66.Nm EVP_DigestInit_ex ,
61.Nm EVP_DigestUpdate , 67.Nm EVP_DigestUpdate ,
62.Nm EVP_DigestFinal_ex , 68.Nm EVP_DigestFinal_ex ,
63.Nm EVP_MD_CTX_cleanup ,
64.Nm EVP_MD_CTX_destroy ,
65.Nm EVP_MD_CTX_copy_ex , 69.Nm EVP_MD_CTX_copy_ex ,
66.Nm EVP_DigestInit , 70.Nm EVP_DigestInit ,
67.Nm EVP_DigestFinal , 71.Nm EVP_DigestFinal ,
@@ -93,13 +97,31 @@
93.Nd EVP digest routines 97.Nd EVP digest routines
94.Sh SYNOPSIS 98.Sh SYNOPSIS
95.In openssl/evp.h 99.In openssl/evp.h
100.Ft EVP_MD_CTX *
101.Fn EVP_MD_CTX_new void
102.Ft int
103.Fo EVP_MD_CTX_reset
104.Fa "EVP_MD_CTX *ctx"
105.Fc
106.Ft void
107.Fo EVP_MD_CTX_free
108.Fa "EVP_MD_CTX *ctx"
109.Fc
96.Ft void 110.Ft void
97.Fo EVP_MD_CTX_init 111.Fo EVP_MD_CTX_init
98.Fa "EVP_MD_CTX *ctx" 112.Fa "EVP_MD_CTX *ctx"
99.Fc 113.Fc
100.Ft EVP_MD_CTX * 114.Ft EVP_MD_CTX *
101.Fn EVP_MD_CTX_create void 115.Fn EVP_MD_CTX_create void
116.Ft int
117.Fo EVP_MD_CTX_cleanup
118.Fa "EVP_MD_CTX *ctx"
119.Fc
102.Ft void 120.Ft void
121.Fo EVP_MD_CTX_destroy
122.Fa "EVP_MD_CTX *ctx"
123.Fc
124.Ft int
103.Fo EVP_MD_CTX_ctrl 125.Fo EVP_MD_CTX_ctrl
104.Fa "EVP_MD_CTX *ctx" 126.Fa "EVP_MD_CTX *ctx"
105.Fa "int cmd" 127.Fa "int cmd"
@@ -125,14 +147,6 @@
125.Fa "unsigned int *s" 147.Fa "unsigned int *s"
126.Fc 148.Fc
127.Ft int 149.Ft int
128.Fo EVP_MD_CTX_cleanup
129.Fa "EVP_MD_CTX *ctx"
130.Fc
131.Ft void
132.Fo EVP_MD_CTX_destroy
133.Fa "EVP_MD_CTX *ctx"
134.Fc
135.Ft int
136.Fo EVP_MD_CTX_copy_ex 150.Fo EVP_MD_CTX_copy_ex
137.Fa "EVP_MD_CTX *out" 151.Fa "EVP_MD_CTX *out"
138.Fa "const EVP_MD_CTX *in" 152.Fa "const EVP_MD_CTX *in"
@@ -223,29 +237,57 @@
223.Fa "const ASN1_OBJECT *o" 237.Fa "const ASN1_OBJECT *o"
224.Fc 238.Fc
225.Sh DESCRIPTION 239.Sh DESCRIPTION
226The EVP digest routines are a high level interface to message digests. 240The EVP digest routines are a high level interface to message digests
241and should be used instead of the cipher-specific functions.
242.Pp
243.Fn EVP_MD_CTX_new
244allocates a new, empty digest context.
245.Pp
246.Fn EVP_MD_CTX_reset
247cleans up
248.Fa ctx
249and resets it to the state it had after
250.Fn EVP_MD_CTX_new ,
251such that it can be reused.
252It is also suitable for digest contexts on the stack that were
253used and are no longer needed.
254.Pp
255.Fn EVP_MD_CTX_free
256cleans up
257.Fa ctx
258and frees the space allocated to it.
227.Pp 259.Pp
228.Fn EVP_MD_CTX_init 260.Fn EVP_MD_CTX_init
229initializes the digest context 261is a deprecated function to clear a digest context on the stack
230.Fa ctx . 262before use.
263Do not use it on a digest context returned from
264.Fn EVP_MD_CTX_new
265or one one that was already used.
231.Pp 266.Pp
232.Fn EVP_MD_CTX_create 267.Fn EVP_MD_CTX_create ,
233allocates, initializes, and returns a digest context. 268.Fn EVP_MD_CTX_cleanup ,
269and
270.Fn EVP_MD_CTX_destroy
271are deprecated aliases for
272.Fn EVP_MD_CTX_new ,
273.Fn EVP_MD_CTX_reset ,
274and
275.Fn EVP_MD_CTX_free ,
276respectively.
234.Pp 277.Pp
235.Fn EVP_MD_CTX_ctrl 278.Fn EVP_MD_CTX_ctrl
236performs digest-specific control actions on the context 279performs digest-specific control actions on the context
237.Fa ctx . 280.Fa ctx .
238.Pp 281.Pp
239.Fn EVP_DigestInit_ex 282.Fn EVP_DigestInit_ex
240sets up digest context 283sets up the digest context
241.Fa ctx 284.Fa ctx
242to use a digest 285to use a digest
243.Fa type 286.Fa type
244from 287from
245.Vt ENGINE 288.Vt ENGINE
246.Fa impl . 289.Fa impl .
247.Fa ctx 290The
248must be initialized before calling this function.
249.Fa type 291.Fa type
250will typically be supplied by a function such as 292will typically be supplied by a function such as
251.Fn EVP_sha1 . 293.Fn EVP_sha1 .
@@ -256,6 +298,11 @@ is
256then the default implementation of digest 298then the default implementation of digest
257.Fa type 299.Fa type
258is used. 300is used.
301If
302.Fa ctx
303points to an unused object on the stack, it must be initialized with
304.Fn EVP_MD_CTX_init
305before calling this function.
259.Pp 306.Pp
260.Fn EVP_DigestUpdate 307.Fn EVP_DigestUpdate
261hashes 308hashes
@@ -291,18 +338,6 @@ can be made, but
291.Fn EVP_DigestInit_ex 338.Fn EVP_DigestInit_ex
292can be called to initialize a new digest operation. 339can be called to initialize a new digest operation.
293.Pp 340.Pp
294.Fn EVP_MD_CTX_cleanup
295cleans up the digest context
296.Fa ctx .
297It should be called after a digest context is no longer needed.
298.Pp
299.Fn EVP_MD_CTX_destroy
300cleans up the digest context
301.Fa ctx
302and frees up the space allocated to it.
303It should be called only on a context created using
304.Fn EVP_MD_CTX_create .
305.Pp
306.Fn EVP_MD_CTX_copy_ex 341.Fn EVP_MD_CTX_copy_ex
307can be used to copy the message digest state from 342can be used to copy the message digest state from
308.Fa in 343.Fa in
@@ -310,30 +345,36 @@ to
310.Fa out . 345.Fa out .
311This is useful if large amounts of data are to be hashed which only 346This is useful if large amounts of data are to be hashed which only
312differ in the last few bytes. 347differ in the last few bytes.
348If
313.Fa out 349.Fa out
314must be initialized before calling this function. 350points to an unused object on the stack, it must be initialized with
351.Fn EVP_MD_CTX_init
352before calling this function.
315.Pp 353.Pp
316.Fn EVP_DigestInit 354.Fn EVP_DigestInit
317behaves in the same way as 355is a deprecated function behaving like
318.Fn EVP_DigestInit_ex 356.Fn EVP_DigestInit_ex
319except the passed context 357except that it always uses the default digest implementation
320.Fa ctx 358and that it requires
321does not have to be initialized, and it always uses the default digest 359.Fn EVP_MD_CTX_reset
322implementation. 360before it can be used on a context that was already used.
323.Pp 361.Pp
324.Fn EVP_DigestFinal 362.Fn EVP_DigestFinal
325is similar to 363is a deprecated function behaving like
326.Fn EVP_DigestFinal_ex 364.Fn EVP_DigestFinal_ex
327except the digest context 365except that the digest context
328.Fa ctx 366.Fa ctx
329is automatically cleaned up. 367is automatically cleaned up after use by calling
368.Fn EVP_MD_CTX_reset
369internally.
330.Pp 370.Pp
331.Fn EVP_MD_CTX_copy 371.Fn EVP_MD_CTX_copy
332is similar to 372is a deprecated function behaving like
333.Fn EVP_MD_CTX_copy_ex 373.Fn EVP_MD_CTX_copy_ex
334except the destination 374except that it requires
335.Fa out 375.Fn EVP_MD_CTX_reset
336does not have to be initialized. 376before a context that was already used can be passed as
377.Fa out .
337.Pp 378.Pp
338.Fn EVP_MD_size 379.Fn EVP_MD_size
339and 380and
@@ -366,12 +407,6 @@ returns
366.Dv NID_sha1 . 407.Dv NID_sha1 .
367This function is normally used when setting ASN.1 OIDs. 408This function is normally used when setting ASN.1 OIDs.
368.Pp 409.Pp
369.Fn EVP_MD_CTX_md
370returns the
371.Vt EVP_MD
372structure corresponding to the passed
373.Vt EVP_MD_CTX .
374.Pp
375.Fn EVP_MD_pkey_type 410.Fn EVP_MD_pkey_type
376returns the NID of the public key signing algorithm associated with this 411returns the NID of the public key signing algorithm associated with this
377digest. 412digest.
@@ -465,40 +500,37 @@ because they can efficiently reuse a digest context instead of
465initializing and cleaning it up on each call and allow non-default 500initializing and cleaning it up on each call and allow non-default
466implementations of digests to be specified. 501implementations of digests to be specified.
467.Pp 502.Pp
468In OpenSSL 0.9.7 and later if digest contexts are not cleaned up after 503If digest contexts are not cleaned up after use, memory leaks will occur.
469use memory leaks will occur. 504.Sh RETURN VALUES
470.Pp 505.Fn EVP_MD_CTX_new
471Stack allocation of 506and
507.Fn EVP_MD_CTX_create
508return the new
472.Vt EVP_MD_CTX 509.Vt EVP_MD_CTX
473structures is common, for example: 510object or
474.Bd -literal -offset indent 511.Dv NULL
475EVP_MD_CTX mctx; 512for failure.
476EVP_MD_CTX_init(&mctx); 513.Pp
477.Ed 514.Fn EVP_MD_CTX_reset
515and
516.Fn EVP_MD_CTX_cleanup
517always return 1.
478.Pp 518.Pp
479This will cause binary compatibility issues if the size of
480.Vt EVP_MD_CTX
481structure changes (this will only happen with a major release of OpenSSL).
482Applications wishing to avoid this should use
483.Fn EVP_MD_CTX_create
484instead:
485.Bd -literal -offset indent
486EVP_MD_CTX *mctx;
487mctx = EVP_MD_CTX_create();
488.Ed
489.Sh RETURN VALUES
490.Fn EVP_MD_CTX_ctrl , 519.Fn EVP_MD_CTX_ctrl ,
491.Fn EVP_DigestInit_ex , 520.Fn EVP_DigestInit_ex ,
492.Fn EVP_DigestUpdate , 521.Fn EVP_DigestUpdate ,
493.Fn EVP_DigestFinal_ex , 522.Fn EVP_DigestFinal_ex ,
523.Fn EVP_MD_CTX_copy_ex ,
524.Fn EVP_DigestInit ,
525.Fn EVP_DigestFinal ,
494and 526and
495.Fn EVP_MD_CTX_copy_ex 527.Fn EVP_MD_CTX_copy
496return 1 for success or 0 for failure. 528return 1 for success or 0 for failure.
497.Pp 529.Pp
498.Fn EVP_MD_type , 530.Fn EVP_MD_type ,
499.Fn EVP_MD_pkey_type , 531.Fn EVP_MD_pkey_type ,
500and 532and
501.Fn EVP_MD_type 533.Fn EVP_MD_CTX_type
502return the NID of the corresponding OBJECT IDENTIFIER or 534return the NID of the corresponding OBJECT IDENTIFIER or
503.Dv NID_undef 535.Dv NID_undef
504if none exists. 536if none exists.
@@ -510,6 +542,18 @@ and
510.Fn EVP_MD_CTX_block_size 542.Fn EVP_MD_CTX_block_size
511return the digest or block size in bytes. 543return the digest or block size in bytes.
512.Pp 544.Pp
545.Fn EVP_MD_CTX_md
546returns the
547.Vt EVP_MD
548object used by
549.Fa ctx ,
550or
551.Dv NULL
552if
553.Fa ctx
554is
555.Dv NULL .
556.Pp
513.Fn EVP_md_null , 557.Fn EVP_md_null ,
514.Fn EVP_md2 , 558.Fn EVP_md2 ,
515.Fn EVP_md5 , 559.Fn EVP_md5 ,
@@ -562,17 +606,19 @@ main(int argc, char *argv[])
562 exit(1); 606 exit(1);
563 } 607 }
564 608
565 mdctx = EVP_MD_CTX_create(); 609 mdctx = EVP_MD_CTX_new();
566 EVP_DigestInit_ex(mdctx, md, NULL); 610 EVP_DigestInit_ex(mdctx, md, NULL);
567 EVP_DigestUpdate(mdctx, mess1, strlen(mess1)); 611 EVP_DigestUpdate(mdctx, mess1, strlen(mess1));
568 EVP_DigestUpdate(mdctx, mess2, strlen(mess2)); 612 EVP_DigestUpdate(mdctx, mess2, strlen(mess2));
569 EVP_DigestFinal_ex(mdctx, md_value, &md_len); 613 EVP_DigestFinal_ex(mdctx, md_value, &md_len);
570 EVP_MD_CTX_destroy(mdctx); 614 EVP_MD_CTX_free(mdctx);
571 615
572 printf("Digest is: "); 616 printf("Digest is: ");
573 for(i = 0; i < md_len; i++) 617 for(i = 0; i < md_len; i++)
574 printf("%02x", md_value[i]); 618 printf("%02x", md_value[i]);
575 printf("\en"); 619 printf("\en");
620
621 return 0;
576} 622}
577.Ed 623.Ed
578.Sh SEE ALSO 624.Sh SEE ALSO
@@ -606,6 +652,11 @@ were changed to return truly const
606.Vt EVP_MD 652.Vt EVP_MD
607pointers in OpenSSL 0.9.7. 653pointers in OpenSSL 0.9.7.
608.Pp 654.Pp
655.Fn EVP_MD_CTX_new
656and
657.Fn EVP_MD_CTX_free
658first appeared in OpenSSL 1.1.0.
659.Pp
609The link between digests and signing algorithms was fixed in OpenSSL 1.0 660The link between digests and signing algorithms was fixed in OpenSSL 1.0
610and later, so now 661and later, so now
611.Fn EVP_sha1 662.Fn EVP_sha1