diff options
author | schwarze <> | 2016-11-03 09:35:34 +0000 |
---|---|---|
committer | schwarze <> | 2016-11-03 09:35:34 +0000 |
commit | 4d607f17ea3eb38ed9f7703afd423f6055c686d4 (patch) | |
tree | 58d82d0d7f6aeee380eaadbcfaa231ecbe6b90a0 /src/lib/libcrypto/man/EVP_DigestInit.3 | |
parent | cf67afe5881727d740e9f6c772aa478123f7d698 (diff) | |
download | openbsd-4d607f17ea3eb38ed9f7703afd423f6055c686d4.tar.gz openbsd-4d607f17ea3eb38ed9f7703afd423f6055c686d4.tar.bz2 openbsd-4d607f17ea3eb38ed9f7703afd423f6055c686d4.zip |
convert EVP manuals from pod to mdoc
Diffstat (limited to 'src/lib/libcrypto/man/EVP_DigestInit.3')
-rw-r--r-- | src/lib/libcrypto/man/EVP_DigestInit.3 | 520 |
1 files changed, 520 insertions, 0 deletions
diff --git a/src/lib/libcrypto/man/EVP_DigestInit.3 b/src/lib/libcrypto/man/EVP_DigestInit.3 new file mode 100644 index 0000000000..9bcf79241c --- /dev/null +++ b/src/lib/libcrypto/man/EVP_DigestInit.3 | |||
@@ -0,0 +1,520 @@ | |||
1 | .Dd $Mdocdate: November 3 2016 $ | ||
2 | .Dt EVP_DIGESTINIT 3 | ||
3 | .Os | ||
4 | .Sh NAME | ||
5 | .Nm EVP_MD_CTX_init , | ||
6 | .Nm EVP_MD_CTX_create , | ||
7 | .Nm EVP_DigestInit_ex , | ||
8 | .Nm EVP_DigestUpdate , | ||
9 | .Nm EVP_DigestFinal_ex , | ||
10 | .Nm EVP_MD_CTX_cleanup , | ||
11 | .Nm EVP_MD_CTX_destroy , | ||
12 | .Nm EVP_MAX_MD_SIZE , | ||
13 | .Nm EVP_MD_CTX_copy_ex , | ||
14 | .Nm EVP_MD_CTX_copy , | ||
15 | .Nm EVP_MD_type , | ||
16 | .Nm EVP_MD_pkey_type , | ||
17 | .Nm EVP_MD_size , | ||
18 | .Nm EVP_MD_block_size , | ||
19 | .Nm EVP_MD_CTX_md , | ||
20 | .Nm EVP_MD_CTX_size , | ||
21 | .Nm EVP_MD_CTX_block_size , | ||
22 | .Nm EVP_MD_CTX_type , | ||
23 | .Nm EVP_md_null , | ||
24 | .Nm EVP_md2 , | ||
25 | .Nm EVP_md5 , | ||
26 | .Nm EVP_sha1 , | ||
27 | .Nm EVP_sha224 , | ||
28 | .Nm EVP_sha256 , | ||
29 | .Nm EVP_sha384 , | ||
30 | .Nm EVP_sha512 , | ||
31 | .Nm EVP_dss , | ||
32 | .Nm EVP_dss1 , | ||
33 | .Nm EVP_ripemd160 , | ||
34 | .Nm EVP_get_digestbyname , | ||
35 | .Nm EVP_get_digestbynid , | ||
36 | .Nm EVP_get_digestbyobj , | ||
37 | .Nm EVP_DigestInit , | ||
38 | .Nm EVP_DigestFinal | ||
39 | .Nd EVP digest routines | ||
40 | .Sh SYNOPSIS | ||
41 | .In openssl/evp.h | ||
42 | .Ft void | ||
43 | .Fo EVP_MD_CTX_init | ||
44 | .Fa "EVP_MD_CTX *ctx" | ||
45 | .Fc | ||
46 | .Ft EVP_MD_CTX * | ||
47 | .Fn EVP_MD_CTX_create void | ||
48 | .Ft int | ||
49 | .Fo EVP_DigestInit_ex | ||
50 | .Fa "EVP_MD_CTX *ctx" | ||
51 | .Fa "const EVP_MD *type" | ||
52 | .Fa "ENGINE *impl" | ||
53 | .Fc | ||
54 | .Ft int | ||
55 | .Fo EVP_DigestUpdate | ||
56 | .Fa "EVP_MD_CTX *ctx" | ||
57 | .Fa "const void *d" | ||
58 | .Fa "size_t cnt" | ||
59 | .Fc | ||
60 | .Ft int | ||
61 | .Fo EVP_DigestFinal_ex | ||
62 | .Fa "EVP_MD_CTX *ctx" | ||
63 | .Fa "unsigned char *md" | ||
64 | .Fa "unsigned int *s" | ||
65 | .Fc | ||
66 | .Ft int | ||
67 | .Fo EVP_MD_CTX_cleanup | ||
68 | .Fa "EVP_MD_CTX *ctx" | ||
69 | .Fc | ||
70 | .Ft void | ||
71 | .Fo EVP_MD_CTX_destroy | ||
72 | .Fa "EVP_MD_CTX *ctx" | ||
73 | .Fc | ||
74 | .Ft int | ||
75 | .Fo EVP_MD_CTX_copy_ex | ||
76 | .Fa "EVP_MD_CTX *out" | ||
77 | .Fa "const EVP_MD_CTX *in" | ||
78 | .Fc | ||
79 | .Ft int | ||
80 | .Fo EVP_DigestInit | ||
81 | .Fa "EVP_MD_CTX *ctx" | ||
82 | .Fa "const EVP_MD *type" | ||
83 | .Fc | ||
84 | .Ft int | ||
85 | .Fo EVP_DigestFinal | ||
86 | .Fa "EVP_MD_CTX *ctx" | ||
87 | .Fa "unsigned char *md" | ||
88 | .Fa "unsigned int *s" | ||
89 | .Fc | ||
90 | .Ft int | ||
91 | .Fo EVP_MD_CTX_copy | ||
92 | .Fa "EVP_MD_CTX *out" | ||
93 | .Fa "EVP_MD_CTX *in" | ||
94 | .Fc | ||
95 | .Fd #define EVP_MAX_MD_SIZE 64 /* SHA512 */ | ||
96 | .Ft int | ||
97 | .Fo EVP_MD_type | ||
98 | .Fa "const EVP_MD *md" | ||
99 | .Fc | ||
100 | .Ft int | ||
101 | .Fo EVP_MD_pkey_type | ||
102 | .Fa "const EVP_MD *md" | ||
103 | .Fc | ||
104 | .Ft int | ||
105 | .Fo EVP_MD_size | ||
106 | .Fa "const EVP_MD *md" | ||
107 | .Fc | ||
108 | .Ft int | ||
109 | .Fo EVP_MD_block_size | ||
110 | .Fa "const EVP_MD *md" | ||
111 | .Fc | ||
112 | .Ft const EVP_MD * | ||
113 | .Fo EVP_MD_CTX_md | ||
114 | .Fa "const EVP_MD_CTX *ctx" | ||
115 | .Fc | ||
116 | .Fd #define EVP_MD_CTX_size(e) EVP_MD_size(EVP_MD_CTX_md(e)) | ||
117 | .Fd #define EVP_MD_CTX_block_size(e) EVP_MD_block_size((e)->digest) | ||
118 | .Fd #define EVP_MD_CTX_type(e) EVP_MD_type((e)->digest) | ||
119 | .Ft const EVP_MD * | ||
120 | .Fn EVP_md_null void | ||
121 | .Ft const EVP_MD * | ||
122 | .Fn EVP_md2 void | ||
123 | .Ft const EVP_MD * | ||
124 | .Fn EVP_md5 void | ||
125 | .Ft const EVP_MD * | ||
126 | .Fn EVP_sha1 void | ||
127 | .Ft const EVP_MD * | ||
128 | .Fn EVP_dss void | ||
129 | .Ft const EVP_MD * | ||
130 | .Fn EVP_dss1 void | ||
131 | .Ft const EVP_MD * | ||
132 | .Fn EVP_ripemd160 void | ||
133 | .Ft const EVP_MD * | ||
134 | .Fn EVP_sha224 void | ||
135 | .Ft const EVP_MD * | ||
136 | .Fn EVP_sha256 void | ||
137 | .Ft const EVP_MD * | ||
138 | .Fn EVP_sha384 void | ||
139 | .Ft const EVP_MD * | ||
140 | .Fn EVP_sha512 void | ||
141 | .Ft const EVP_MD * | ||
142 | .Fo EVP_get_digestbyname | ||
143 | .Fa "const char *name" | ||
144 | .Fc | ||
145 | .Fd #define EVP_get_digestbynid(a) EVP_get_digestbyname(OBJ_nid2sn(a)) | ||
146 | .Fd #define EVP_get_digestbyobj(a) EVP_get_digestbynid(OBJ_obj2nid(a)) | ||
147 | .Sh DESCRIPTION | ||
148 | The EVP digest routines are a high level interface to message digests. | ||
149 | .Pp | ||
150 | .Fn EVP_MD_CTX_init | ||
151 | initializes the digest context | ||
152 | .Fa ctx . | ||
153 | .Pp | ||
154 | .Fn EVP_MD_CTX_create | ||
155 | allocates, initializes, and returns a digest context. | ||
156 | .Pp | ||
157 | .Fn EVP_DigestInit_ex | ||
158 | sets up digest context | ||
159 | .Fa ctx | ||
160 | to use a digest | ||
161 | .Fa type | ||
162 | from | ||
163 | .Vt ENGINE | ||
164 | .Fa impl . | ||
165 | .Fa ctx | ||
166 | must be initialized before calling this function. | ||
167 | .Fa type | ||
168 | will typically be supplied by a function such as | ||
169 | .Fn EVP_sha1 . | ||
170 | If | ||
171 | .Fa impl | ||
172 | is | ||
173 | .Dv NULL , | ||
174 | then the default implementation of digest | ||
175 | .Fa type | ||
176 | is used. | ||
177 | .Pp | ||
178 | .Fn EVP_DigestUpdate | ||
179 | hashes | ||
180 | .Fa cnt | ||
181 | bytes of data at | ||
182 | .Fa d | ||
183 | into the digest context | ||
184 | .Fa ctx . | ||
185 | This function can be called several times on the same | ||
186 | .Fa ctx | ||
187 | to hash additional data. | ||
188 | .Pp | ||
189 | .Fn EVP_DigestFinal_ex | ||
190 | retrieves the digest value from | ||
191 | .Fa ctx | ||
192 | and places it in | ||
193 | .Fa md . | ||
194 | If the | ||
195 | .Fa s | ||
196 | parameter is not | ||
197 | .Dv NULL , | ||
198 | then the number of bytes of data written (i.e. the length of the | ||
199 | digest) will be written to the integer at | ||
200 | .Fa s , | ||
201 | at most | ||
202 | .Dv EVP_MAX_MD_SIZE | ||
203 | bytes will be written. | ||
204 | After calling | ||
205 | .Fn EVP_DigestFinal_ex , | ||
206 | no additional calls to | ||
207 | .Fn EVP_DigestUpdate | ||
208 | can be made, but | ||
209 | .Fn EVP_DigestInit_ex | ||
210 | can be called to initialize a new digest operation. | ||
211 | .Pp | ||
212 | .Fn EVP_MD_CTX_cleanup | ||
213 | cleans up the digest context | ||
214 | .Fa ctx . | ||
215 | It should be called after a digest context is no longer needed. | ||
216 | .Pp | ||
217 | .Fn EVP_MD_CTX_destroy | ||
218 | cleans up the digest context | ||
219 | .Fa ctx | ||
220 | and frees up the space allocated to it. | ||
221 | It should be called only on a context created using | ||
222 | .Fn EVP_MD_CTX_create . | ||
223 | .Pp | ||
224 | .Fn EVP_MD_CTX_copy_ex | ||
225 | can be used to copy the message digest state from | ||
226 | .Fa in | ||
227 | to | ||
228 | .Fa out . | ||
229 | This is useful if large amounts of data are to be hashed which only | ||
230 | differ in the last few bytes. | ||
231 | .Fa out | ||
232 | must be initialized before calling this function. | ||
233 | .Pp | ||
234 | .Fn EVP_DigestInit | ||
235 | behaves in the same way as | ||
236 | .Fn EVP_DigestInit_ex | ||
237 | except the passed context | ||
238 | .Fa ctx | ||
239 | does not have to be initialized, and it always uses the default digest | ||
240 | implementation. | ||
241 | .Pp | ||
242 | .Fn EVP_DigestFinal | ||
243 | is similar to | ||
244 | .Fn EVP_DigestFinal_ex | ||
245 | except the digest context | ||
246 | .Fa ctx | ||
247 | is automatically cleaned up. | ||
248 | .Pp | ||
249 | .Fn EVP_MD_CTX_copy | ||
250 | is similar to | ||
251 | .Fn EVP_MD_CTX_copy_ex | ||
252 | except the destination | ||
253 | .Fa out | ||
254 | does not have to be initialized. | ||
255 | .Pp | ||
256 | .Fn EVP_MD_size | ||
257 | and | ||
258 | .Fn EVP_MD_CTX_size | ||
259 | return the size of the message digest when passed an | ||
260 | .Vt EVP_MD | ||
261 | or an | ||
262 | .Vt EVP_MD_CTX | ||
263 | structure, i.e. the size of the hash. | ||
264 | .Pp | ||
265 | .Fn EVP_MD_block_size | ||
266 | and | ||
267 | .Fn EVP_MD_CTX_block_size | ||
268 | return the block size of the message digest when passed an | ||
269 | .Vt EVP_MD | ||
270 | or an | ||
271 | .Vt EVP_MD_CTX | ||
272 | structure. | ||
273 | .Pp | ||
274 | .Fn EVP_MD_type | ||
275 | and | ||
276 | .Fn EVP_MD_CTX_type | ||
277 | return the NID of the OBJECT IDENTIFIER representing the given message | ||
278 | digest when passed an | ||
279 | .Vt EVP_MD | ||
280 | structure. | ||
281 | For example | ||
282 | .Fn EVP_MD_type EVP_sha1() | ||
283 | returns | ||
284 | .Dv NID_sha1 . | ||
285 | This function is normally used when setting ASN1 OIDs. | ||
286 | .Pp | ||
287 | .Fn EVP_MD_CTX_md | ||
288 | returns the | ||
289 | .Vt EVP_MD | ||
290 | structure corresponding to the passed | ||
291 | .Vt EVP_MD_CTX . | ||
292 | .Pp | ||
293 | .Fn EVP_MD_pkey_type | ||
294 | returns the NID of the public key signing algorithm associated with this | ||
295 | digest. | ||
296 | For example | ||
297 | .Fn EVP_sha1 | ||
298 | is associated with RSA so this will return | ||
299 | .Dv NID_sha1WithRSAEncryption . | ||
300 | Since digests and signature algorithms are no longer linked this | ||
301 | function is only retained for compatibility reasons. | ||
302 | .Pp | ||
303 | .Fn EVP_md2 , | ||
304 | .Fn EVP_md5 , | ||
305 | .Fn EVP_sha1 , | ||
306 | .Fn EVP_sha224 , | ||
307 | .Fn EVP_sha256 , | ||
308 | .Fn EVP_sha384 , | ||
309 | .Fn EVP_sha512 , | ||
310 | and | ||
311 | .Fn EVP_ripemd160 | ||
312 | return | ||
313 | .Vt EVP_MD | ||
314 | structures for the MD2, MD5, SHA1, SHA224, SHA256, SHA384, SHA512 and | ||
315 | RIPEMD160 digest algorithms respectively. | ||
316 | .Pp | ||
317 | .Fn EVP_dss | ||
318 | and | ||
319 | .Fn EVP_dss1 | ||
320 | return | ||
321 | .Vt EVP_MD | ||
322 | structures for SHA1 digest algorithms but using DSS (DSA) for the | ||
323 | signature algorithm. | ||
324 | Note: there is no need to use these pseudo-digests in OpenSSL 1.0.0 and | ||
325 | later, they are however retained for compatibility. | ||
326 | .Pp | ||
327 | .Fn EVP_md_null | ||
328 | is a "null" message digest that does nothing: | ||
329 | i.e. the hash it returns is of zero length. | ||
330 | .Pp | ||
331 | .Fn EVP_get_digestbyname , | ||
332 | .Fn EVP_get_digestbynid , | ||
333 | and | ||
334 | .Fn EVP_get_digestbyobj | ||
335 | return an | ||
336 | .Vt EVP_MD | ||
337 | structure when passed a digest name, a digest NID, or an ASN1_OBJECT | ||
338 | structure respectively. | ||
339 | The digest table must be initialized using, for example, | ||
340 | .Xr OpenSSL_add_all_digests 3 | ||
341 | for these functions to work. | ||
342 | .Pp | ||
343 | The EVP interface to message digests should almost always be used | ||
344 | in preference to the low level interfaces. | ||
345 | This is because the code then becomes transparent to the digest used and | ||
346 | much more flexible. | ||
347 | .Pp | ||
348 | New applications should use the SHA2 digest algorithms such as SHA256. | ||
349 | The other digest algorithms are still in common use. | ||
350 | .Pp | ||
351 | For most applications the | ||
352 | .Fa impl | ||
353 | parameter to | ||
354 | .Fn EVP_DigestInit_ex | ||
355 | will be set to NULL to use the default digest implementation. | ||
356 | .Pp | ||
357 | The functions | ||
358 | .Fn EVP_DigestInit , | ||
359 | .Fn EVP_DigestFinal , | ||
360 | and | ||
361 | .Fn EVP_MD_CTX_copy | ||
362 | are obsolete but are retained to maintain compatibility with existing | ||
363 | code. | ||
364 | New applications should use | ||
365 | .Fn EVP_DigestInit_ex , | ||
366 | .Fn EVP_DigestFinal_ex , | ||
367 | and | ||
368 | .Fn EVP_MD_CTX_copy_ex | ||
369 | because they can efficiently reuse a digest context instead of | ||
370 | initializing and cleaning it up on each call and allow non default | ||
371 | implementations of digests to be specified. | ||
372 | .Pp | ||
373 | In OpenSSL 0.9.7 and later if digest contexts are not cleaned up after | ||
374 | use memory leaks will occur. | ||
375 | .Pp | ||
376 | Stack allocation of | ||
377 | .Vt EVP_MD_CTX | ||
378 | structures is common, for example: | ||
379 | .Bd -literal -offset indent | ||
380 | EVP_MD_CTX mctx; | ||
381 | EVP_MD_CTX_init(&mctx); | ||
382 | .Ed | ||
383 | .Pp | ||
384 | This will cause binary compatibility issues if the size of | ||
385 | .Vt EVP_MD_CTX | ||
386 | structure changes (this will only happen with a major release of OpenSSL). | ||
387 | Applications wishing to avoid this should use | ||
388 | .Fn EVP_MD_CTX_create | ||
389 | instead: | ||
390 | .Bd -literal -offset indent | ||
391 | EVP_MD_CTX *mctx; | ||
392 | mctx = EVP_MD_CTX_create(); | ||
393 | .Ed | ||
394 | .Sh RETURN VALUES | ||
395 | .Fn EVP_DigestInit_ex , | ||
396 | .Fn EVP_DigestUpdate , | ||
397 | .Fn EVP_DigestFinal_ex , | ||
398 | and | ||
399 | .Fn EVP_MD_CTX_copy_ex | ||
400 | return 1 for success or 0 for failure. | ||
401 | .Pp | ||
402 | .Fn EVP_MD_type , | ||
403 | .Fn EVP_MD_pkey_type , | ||
404 | and | ||
405 | .Fn EVP_MD_type | ||
406 | return the NID of the corresponding OBJECT IDENTIFIER or | ||
407 | .Dv NID_undef | ||
408 | if none exists. | ||
409 | .Pp | ||
410 | .Fn EVP_MD_size , | ||
411 | .Fn EVP_MD_block_size , | ||
412 | .Fn EVP_MD_CTX_size , | ||
413 | and | ||
414 | .Fn EVP_MD_CTX_block_size | ||
415 | return the digest or block size in bytes. | ||
416 | .Pp | ||
417 | .Fn EVP_md_null , | ||
418 | .Fn EVP_md2 , | ||
419 | .Fn EVP_md5 , | ||
420 | .Fn EVP_sha1 , | ||
421 | .Fn EVP_dss , | ||
422 | .Fn EVP_dss1 , | ||
423 | and | ||
424 | .Fn EVP_ripemd160 | ||
425 | return pointers to the corresponding | ||
426 | .Vt EVP_MD | ||
427 | structures. | ||
428 | .Pp | ||
429 | .Fn EVP_get_digestbyname , | ||
430 | .Fn EVP_get_digestbynid , | ||
431 | and | ||
432 | .Fn EVP_get_digestbyobj | ||
433 | return either an | ||
434 | .Vt EVP_MD | ||
435 | structure or | ||
436 | .Dv NULL | ||
437 | if an error occurs. | ||
438 | .Sh EXAMPLES | ||
439 | This example digests the data "Test Message\en" and "Hello World\en", | ||
440 | using the digest name passed on the command line. | ||
441 | .Bd -literal | ||
442 | #include <stdio.h> | ||
443 | #include <openssl/evp.h> | ||
444 | |||
445 | int | ||
446 | main(int argc, char *argv[]) | ||
447 | { | ||
448 | EVP_MD_CTX *mdctx; | ||
449 | const EVP_MD *md; | ||
450 | const char mess1[] = "Test Message\en"; | ||
451 | const char mess2[] = "Hello World\en"; | ||
452 | unsigned char md_value[EVP_MAX_MD_SIZE]; | ||
453 | int md_len, i; | ||
454 | |||
455 | OpenSSL_add_all_digests(); | ||
456 | |||
457 | if (argc <= 1) { | ||
458 | printf("Usage: mdtest digestname\en"); | ||
459 | exit(1); | ||
460 | } | ||
461 | |||
462 | md = EVP_get_digestbyname(argv[1]); | ||
463 | if (md == NULL) { | ||
464 | printf("Unknown message digest %s\en", argv[1]); | ||
465 | exit(1); | ||
466 | } | ||
467 | |||
468 | mdctx = EVP_MD_CTX_create(); | ||
469 | EVP_DigestInit_ex(mdctx, md, NULL); | ||
470 | EVP_DigestUpdate(mdctx, mess1, strlen(mess1)); | ||
471 | EVP_DigestUpdate(mdctx, mess2, strlen(mess2)); | ||
472 | EVP_DigestFinal_ex(mdctx, md_value, &md_len); | ||
473 | EVP_MD_CTX_destroy(mdctx); | ||
474 | |||
475 | printf("Digest is: "); | ||
476 | for(i = 0; i < md_len; i++) | ||
477 | printf("%02x", md_value[i]); | ||
478 | printf("\en"); | ||
479 | } | ||
480 | .Ed | ||
481 | .Sh SEE ALSO | ||
482 | .Xr evp 3 | ||
483 | .Sh HISTORY | ||
484 | .Fn EVP_DigestInit , | ||
485 | .Fn EVP_DigestUpdate , | ||
486 | and | ||
487 | .Fn EVP_DigestFinal | ||
488 | are available in all versions of SSLeay and OpenSSL. | ||
489 | .Pp | ||
490 | .Fn EVP_MD_CTX_init , | ||
491 | .Fn EVP_MD_CTX_create , | ||
492 | .Fn EVP_MD_CTX_copy_ex , | ||
493 | .Fn EVP_MD_CTX_cleanup , | ||
494 | .Fn EVP_MD_CTX_destroy , | ||
495 | .Fn EVP_DigestInit_ex , | ||
496 | and | ||
497 | .Fn EVP_DigestFinal_ex | ||
498 | were added in OpenSSL 0.9.7. | ||
499 | .Pp | ||
500 | .Fn EVP_md_null , | ||
501 | .Fn EVP_md2 , | ||
502 | .Fn EVP_md5 , | ||
503 | .Fn EVP_sha1 , | ||
504 | .Fn EVP_dss , | ||
505 | .Fn EVP_dss1 , | ||
506 | and | ||
507 | .Fn EVP_ripemd160 | ||
508 | were changed to return truely const | ||
509 | .Vt EVP_MD | ||
510 | pointers in OpenSSL 0.9.7. | ||
511 | .Pp | ||
512 | The link between digests and signing algorithms was fixed in OpenSSL 1.0 | ||
513 | and later, so now | ||
514 | .Fn EVP_sha1 | ||
515 | can be used with RSA and DSA, there is no need to use | ||
516 | .Fn EVP_dss1 | ||
517 | any more. | ||
518 | .Pp | ||
519 | OpenSSL 1.0 and later does not include the MD2 digest algorithm in the | ||
520 | default configuration due to its security weaknesses. | ||