diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/man/EVP_DigestInit.3 | 207 |
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 |
226 | The EVP digest routines are a high level interface to message digests. | 240 | The EVP digest routines are a high level interface to message digests |
241 | and should be used instead of the cipher-specific functions. | ||
242 | .Pp | ||
243 | .Fn EVP_MD_CTX_new | ||
244 | allocates a new, empty digest context. | ||
245 | .Pp | ||
246 | .Fn EVP_MD_CTX_reset | ||
247 | cleans up | ||
248 | .Fa ctx | ||
249 | and resets it to the state it had after | ||
250 | .Fn EVP_MD_CTX_new , | ||
251 | such that it can be reused. | ||
252 | It is also suitable for digest contexts on the stack that were | ||
253 | used and are no longer needed. | ||
254 | .Pp | ||
255 | .Fn EVP_MD_CTX_free | ||
256 | cleans up | ||
257 | .Fa ctx | ||
258 | and frees the space allocated to it. | ||
227 | .Pp | 259 | .Pp |
228 | .Fn EVP_MD_CTX_init | 260 | .Fn EVP_MD_CTX_init |
229 | initializes the digest context | 261 | is a deprecated function to clear a digest context on the stack |
230 | .Fa ctx . | 262 | before use. |
263 | Do not use it on a digest context returned from | ||
264 | .Fn EVP_MD_CTX_new | ||
265 | or one one that was already used. | ||
231 | .Pp | 266 | .Pp |
232 | .Fn EVP_MD_CTX_create | 267 | .Fn EVP_MD_CTX_create , |
233 | allocates, initializes, and returns a digest context. | 268 | .Fn EVP_MD_CTX_cleanup , |
269 | and | ||
270 | .Fn EVP_MD_CTX_destroy | ||
271 | are deprecated aliases for | ||
272 | .Fn EVP_MD_CTX_new , | ||
273 | .Fn EVP_MD_CTX_reset , | ||
274 | and | ||
275 | .Fn EVP_MD_CTX_free , | ||
276 | respectively. | ||
234 | .Pp | 277 | .Pp |
235 | .Fn EVP_MD_CTX_ctrl | 278 | .Fn EVP_MD_CTX_ctrl |
236 | performs digest-specific control actions on the context | 279 | performs 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 |
240 | sets up digest context | 283 | sets up the digest context |
241 | .Fa ctx | 284 | .Fa ctx |
242 | to use a digest | 285 | to use a digest |
243 | .Fa type | 286 | .Fa type |
244 | from | 287 | from |
245 | .Vt ENGINE | 288 | .Vt ENGINE |
246 | .Fa impl . | 289 | .Fa impl . |
247 | .Fa ctx | 290 | The |
248 | must be initialized before calling this function. | ||
249 | .Fa type | 291 | .Fa type |
250 | will typically be supplied by a function such as | 292 | will typically be supplied by a function such as |
251 | .Fn EVP_sha1 . | 293 | .Fn EVP_sha1 . |
@@ -256,6 +298,11 @@ is | |||
256 | then the default implementation of digest | 298 | then the default implementation of digest |
257 | .Fa type | 299 | .Fa type |
258 | is used. | 300 | is used. |
301 | If | ||
302 | .Fa ctx | ||
303 | points to an unused object on the stack, it must be initialized with | ||
304 | .Fn EVP_MD_CTX_init | ||
305 | before calling this function. | ||
259 | .Pp | 306 | .Pp |
260 | .Fn EVP_DigestUpdate | 307 | .Fn EVP_DigestUpdate |
261 | hashes | 308 | hashes |
@@ -291,18 +338,6 @@ can be made, but | |||
291 | .Fn EVP_DigestInit_ex | 338 | .Fn EVP_DigestInit_ex |
292 | can be called to initialize a new digest operation. | 339 | can be called to initialize a new digest operation. |
293 | .Pp | 340 | .Pp |
294 | .Fn EVP_MD_CTX_cleanup | ||
295 | cleans up the digest context | ||
296 | .Fa ctx . | ||
297 | It should be called after a digest context is no longer needed. | ||
298 | .Pp | ||
299 | .Fn EVP_MD_CTX_destroy | ||
300 | cleans up the digest context | ||
301 | .Fa ctx | ||
302 | and frees up the space allocated to it. | ||
303 | It 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 |
307 | can be used to copy the message digest state from | 342 | can 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 . |
311 | This is useful if large amounts of data are to be hashed which only | 346 | This is useful if large amounts of data are to be hashed which only |
312 | differ in the last few bytes. | 347 | differ in the last few bytes. |
348 | If | ||
313 | .Fa out | 349 | .Fa out |
314 | must be initialized before calling this function. | 350 | points to an unused object on the stack, it must be initialized with |
351 | .Fn EVP_MD_CTX_init | ||
352 | before calling this function. | ||
315 | .Pp | 353 | .Pp |
316 | .Fn EVP_DigestInit | 354 | .Fn EVP_DigestInit |
317 | behaves in the same way as | 355 | is a deprecated function behaving like |
318 | .Fn EVP_DigestInit_ex | 356 | .Fn EVP_DigestInit_ex |
319 | except the passed context | 357 | except that it always uses the default digest implementation |
320 | .Fa ctx | 358 | and that it requires |
321 | does not have to be initialized, and it always uses the default digest | 359 | .Fn EVP_MD_CTX_reset |
322 | implementation. | 360 | before it can be used on a context that was already used. |
323 | .Pp | 361 | .Pp |
324 | .Fn EVP_DigestFinal | 362 | .Fn EVP_DigestFinal |
325 | is similar to | 363 | is a deprecated function behaving like |
326 | .Fn EVP_DigestFinal_ex | 364 | .Fn EVP_DigestFinal_ex |
327 | except the digest context | 365 | except that the digest context |
328 | .Fa ctx | 366 | .Fa ctx |
329 | is automatically cleaned up. | 367 | is automatically cleaned up after use by calling |
368 | .Fn EVP_MD_CTX_reset | ||
369 | internally. | ||
330 | .Pp | 370 | .Pp |
331 | .Fn EVP_MD_CTX_copy | 371 | .Fn EVP_MD_CTX_copy |
332 | is similar to | 372 | is a deprecated function behaving like |
333 | .Fn EVP_MD_CTX_copy_ex | 373 | .Fn EVP_MD_CTX_copy_ex |
334 | except the destination | 374 | except that it requires |
335 | .Fa out | 375 | .Fn EVP_MD_CTX_reset |
336 | does not have to be initialized. | 376 | before 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 |
339 | and | 380 | and |
@@ -366,12 +407,6 @@ returns | |||
366 | .Dv NID_sha1 . | 407 | .Dv NID_sha1 . |
367 | This function is normally used when setting ASN.1 OIDs. | 408 | This function is normally used when setting ASN.1 OIDs. |
368 | .Pp | 409 | .Pp |
369 | .Fn EVP_MD_CTX_md | ||
370 | returns the | ||
371 | .Vt EVP_MD | ||
372 | structure corresponding to the passed | ||
373 | .Vt EVP_MD_CTX . | ||
374 | .Pp | ||
375 | .Fn EVP_MD_pkey_type | 410 | .Fn EVP_MD_pkey_type |
376 | returns the NID of the public key signing algorithm associated with this | 411 | returns the NID of the public key signing algorithm associated with this |
377 | digest. | 412 | digest. |
@@ -465,40 +500,37 @@ because they can efficiently reuse a digest context instead of | |||
465 | initializing and cleaning it up on each call and allow non-default | 500 | initializing and cleaning it up on each call and allow non-default |
466 | implementations of digests to be specified. | 501 | implementations of digests to be specified. |
467 | .Pp | 502 | .Pp |
468 | In OpenSSL 0.9.7 and later if digest contexts are not cleaned up after | 503 | If digest contexts are not cleaned up after use, memory leaks will occur. |
469 | use memory leaks will occur. | 504 | .Sh RETURN VALUES |
470 | .Pp | 505 | .Fn EVP_MD_CTX_new |
471 | Stack allocation of | 506 | and |
507 | .Fn EVP_MD_CTX_create | ||
508 | return the new | ||
472 | .Vt EVP_MD_CTX | 509 | .Vt EVP_MD_CTX |
473 | structures is common, for example: | 510 | object or |
474 | .Bd -literal -offset indent | 511 | .Dv NULL |
475 | EVP_MD_CTX mctx; | 512 | for failure. |
476 | EVP_MD_CTX_init(&mctx); | 513 | .Pp |
477 | .Ed | 514 | .Fn EVP_MD_CTX_reset |
515 | and | ||
516 | .Fn EVP_MD_CTX_cleanup | ||
517 | always return 1. | ||
478 | .Pp | 518 | .Pp |
479 | This will cause binary compatibility issues if the size of | ||
480 | .Vt EVP_MD_CTX | ||
481 | structure changes (this will only happen with a major release of OpenSSL). | ||
482 | Applications wishing to avoid this should use | ||
483 | .Fn EVP_MD_CTX_create | ||
484 | instead: | ||
485 | .Bd -literal -offset indent | ||
486 | EVP_MD_CTX *mctx; | ||
487 | mctx = 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 , | ||
494 | and | 526 | and |
495 | .Fn EVP_MD_CTX_copy_ex | 527 | .Fn EVP_MD_CTX_copy |
496 | return 1 for success or 0 for failure. | 528 | return 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 , |
500 | and | 532 | and |
501 | .Fn EVP_MD_type | 533 | .Fn EVP_MD_CTX_type |
502 | return the NID of the corresponding OBJECT IDENTIFIER or | 534 | return the NID of the corresponding OBJECT IDENTIFIER or |
503 | .Dv NID_undef | 535 | .Dv NID_undef |
504 | if none exists. | 536 | if none exists. |
@@ -510,6 +542,18 @@ and | |||
510 | .Fn EVP_MD_CTX_block_size | 542 | .Fn EVP_MD_CTX_block_size |
511 | return the digest or block size in bytes. | 543 | return the digest or block size in bytes. |
512 | .Pp | 544 | .Pp |
545 | .Fn EVP_MD_CTX_md | ||
546 | returns the | ||
547 | .Vt EVP_MD | ||
548 | object used by | ||
549 | .Fa ctx , | ||
550 | or | ||
551 | .Dv NULL | ||
552 | if | ||
553 | .Fa ctx | ||
554 | is | ||
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 |
607 | pointers in OpenSSL 0.9.7. | 653 | pointers in OpenSSL 0.9.7. |
608 | .Pp | 654 | .Pp |
655 | .Fn EVP_MD_CTX_new | ||
656 | and | ||
657 | .Fn EVP_MD_CTX_free | ||
658 | first appeared in OpenSSL 1.1.0. | ||
659 | .Pp | ||
609 | The link between digests and signing algorithms was fixed in OpenSSL 1.0 | 660 | The link between digests and signing algorithms was fixed in OpenSSL 1.0 |
610 | and later, so now | 661 | and later, so now |
611 | .Fn EVP_sha1 | 662 | .Fn EVP_sha1 |