summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/man/EVP_DigestInit.3
diff options
context:
space:
mode:
authorschwarze <>2016-11-03 09:35:34 +0000
committerschwarze <>2016-11-03 09:35:34 +0000
commit4d607f17ea3eb38ed9f7703afd423f6055c686d4 (patch)
tree58d82d0d7f6aeee380eaadbcfaa231ecbe6b90a0 /src/lib/libcrypto/man/EVP_DigestInit.3
parentcf67afe5881727d740e9f6c772aa478123f7d698 (diff)
downloadopenbsd-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.3520
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
148The EVP digest routines are a high level interface to message digests.
149.Pp
150.Fn EVP_MD_CTX_init
151initializes the digest context
152.Fa ctx .
153.Pp
154.Fn EVP_MD_CTX_create
155allocates, initializes, and returns a digest context.
156.Pp
157.Fn EVP_DigestInit_ex
158sets up digest context
159.Fa ctx
160to use a digest
161.Fa type
162from
163.Vt ENGINE
164.Fa impl .
165.Fa ctx
166must be initialized before calling this function.
167.Fa type
168will typically be supplied by a function such as
169.Fn EVP_sha1 .
170If
171.Fa impl
172is
173.Dv NULL ,
174then the default implementation of digest
175.Fa type
176is used.
177.Pp
178.Fn EVP_DigestUpdate
179hashes
180.Fa cnt
181bytes of data at
182.Fa d
183into the digest context
184.Fa ctx .
185This function can be called several times on the same
186.Fa ctx
187to hash additional data.
188.Pp
189.Fn EVP_DigestFinal_ex
190retrieves the digest value from
191.Fa ctx
192and places it in
193.Fa md .
194If the
195.Fa s
196parameter is not
197.Dv NULL ,
198then the number of bytes of data written (i.e. the length of the
199digest) will be written to the integer at
200.Fa s ,
201at most
202.Dv EVP_MAX_MD_SIZE
203bytes will be written.
204After calling
205.Fn EVP_DigestFinal_ex ,
206no additional calls to
207.Fn EVP_DigestUpdate
208can be made, but
209.Fn EVP_DigestInit_ex
210can be called to initialize a new digest operation.
211.Pp
212.Fn EVP_MD_CTX_cleanup
213cleans up the digest context
214.Fa ctx .
215It should be called after a digest context is no longer needed.
216.Pp
217.Fn EVP_MD_CTX_destroy
218cleans up the digest context
219.Fa ctx
220and frees up the space allocated to it.
221It should be called only on a context created using
222.Fn EVP_MD_CTX_create .
223.Pp
224.Fn EVP_MD_CTX_copy_ex
225can be used to copy the message digest state from
226.Fa in
227to
228.Fa out .
229This is useful if large amounts of data are to be hashed which only
230differ in the last few bytes.
231.Fa out
232must be initialized before calling this function.
233.Pp
234.Fn EVP_DigestInit
235behaves in the same way as
236.Fn EVP_DigestInit_ex
237except the passed context
238.Fa ctx
239does not have to be initialized, and it always uses the default digest
240implementation.
241.Pp
242.Fn EVP_DigestFinal
243is similar to
244.Fn EVP_DigestFinal_ex
245except the digest context
246.Fa ctx
247is automatically cleaned up.
248.Pp
249.Fn EVP_MD_CTX_copy
250is similar to
251.Fn EVP_MD_CTX_copy_ex
252except the destination
253.Fa out
254does not have to be initialized.
255.Pp
256.Fn EVP_MD_size
257and
258.Fn EVP_MD_CTX_size
259return the size of the message digest when passed an
260.Vt EVP_MD
261or an
262.Vt EVP_MD_CTX
263structure, i.e. the size of the hash.
264.Pp
265.Fn EVP_MD_block_size
266and
267.Fn EVP_MD_CTX_block_size
268return the block size of the message digest when passed an
269.Vt EVP_MD
270or an
271.Vt EVP_MD_CTX
272structure.
273.Pp
274.Fn EVP_MD_type
275and
276.Fn EVP_MD_CTX_type
277return the NID of the OBJECT IDENTIFIER representing the given message
278digest when passed an
279.Vt EVP_MD
280structure.
281For example
282.Fn EVP_MD_type EVP_sha1()
283returns
284.Dv NID_sha1 .
285This function is normally used when setting ASN1 OIDs.
286.Pp
287.Fn EVP_MD_CTX_md
288returns the
289.Vt EVP_MD
290structure corresponding to the passed
291.Vt EVP_MD_CTX .
292.Pp
293.Fn EVP_MD_pkey_type
294returns the NID of the public key signing algorithm associated with this
295digest.
296For example
297.Fn EVP_sha1
298is associated with RSA so this will return
299.Dv NID_sha1WithRSAEncryption .
300Since digests and signature algorithms are no longer linked this
301function 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 ,
310and
311.Fn EVP_ripemd160
312return
313.Vt EVP_MD
314structures for the MD2, MD5, SHA1, SHA224, SHA256, SHA384, SHA512 and
315RIPEMD160 digest algorithms respectively.
316.Pp
317.Fn EVP_dss
318and
319.Fn EVP_dss1
320return
321.Vt EVP_MD
322structures for SHA1 digest algorithms but using DSS (DSA) for the
323signature algorithm.
324Note: there is no need to use these pseudo-digests in OpenSSL 1.0.0 and
325later, they are however retained for compatibility.
326.Pp
327.Fn EVP_md_null
328is a "null" message digest that does nothing:
329i.e. the hash it returns is of zero length.
330.Pp
331.Fn EVP_get_digestbyname ,
332.Fn EVP_get_digestbynid ,
333and
334.Fn EVP_get_digestbyobj
335return an
336.Vt EVP_MD
337structure when passed a digest name, a digest NID, or an ASN1_OBJECT
338structure respectively.
339The digest table must be initialized using, for example,
340.Xr OpenSSL_add_all_digests 3
341for these functions to work.
342.Pp
343The EVP interface to message digests should almost always be used
344in preference to the low level interfaces.
345This is because the code then becomes transparent to the digest used and
346much more flexible.
347.Pp
348New applications should use the SHA2 digest algorithms such as SHA256.
349The other digest algorithms are still in common use.
350.Pp
351For most applications the
352.Fa impl
353parameter to
354.Fn EVP_DigestInit_ex
355will be set to NULL to use the default digest implementation.
356.Pp
357The functions
358.Fn EVP_DigestInit ,
359.Fn EVP_DigestFinal ,
360and
361.Fn EVP_MD_CTX_copy
362are obsolete but are retained to maintain compatibility with existing
363code.
364New applications should use
365.Fn EVP_DigestInit_ex ,
366.Fn EVP_DigestFinal_ex ,
367and
368.Fn EVP_MD_CTX_copy_ex
369because they can efficiently reuse a digest context instead of
370initializing and cleaning it up on each call and allow non default
371implementations of digests to be specified.
372.Pp
373In OpenSSL 0.9.7 and later if digest contexts are not cleaned up after
374use memory leaks will occur.
375.Pp
376Stack allocation of
377.Vt EVP_MD_CTX
378structures is common, for example:
379.Bd -literal -offset indent
380EVP_MD_CTX mctx;
381EVP_MD_CTX_init(&mctx);
382.Ed
383.Pp
384This will cause binary compatibility issues if the size of
385.Vt EVP_MD_CTX
386structure changes (this will only happen with a major release of OpenSSL).
387Applications wishing to avoid this should use
388.Fn EVP_MD_CTX_create
389instead:
390.Bd -literal -offset indent
391EVP_MD_CTX *mctx;
392mctx = EVP_MD_CTX_create();
393.Ed
394.Sh RETURN VALUES
395.Fn EVP_DigestInit_ex ,
396.Fn EVP_DigestUpdate ,
397.Fn EVP_DigestFinal_ex ,
398and
399.Fn EVP_MD_CTX_copy_ex
400return 1 for success or 0 for failure.
401.Pp
402.Fn EVP_MD_type ,
403.Fn EVP_MD_pkey_type ,
404and
405.Fn EVP_MD_type
406return the NID of the corresponding OBJECT IDENTIFIER or
407.Dv NID_undef
408if none exists.
409.Pp
410.Fn EVP_MD_size ,
411.Fn EVP_MD_block_size ,
412.Fn EVP_MD_CTX_size ,
413and
414.Fn EVP_MD_CTX_block_size
415return 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 ,
423and
424.Fn EVP_ripemd160
425return pointers to the corresponding
426.Vt EVP_MD
427structures.
428.Pp
429.Fn EVP_get_digestbyname ,
430.Fn EVP_get_digestbynid ,
431and
432.Fn EVP_get_digestbyobj
433return either an
434.Vt EVP_MD
435structure or
436.Dv NULL
437if an error occurs.
438.Sh EXAMPLES
439This example digests the data "Test Message\en" and "Hello World\en",
440using the digest name passed on the command line.
441.Bd -literal
442#include <stdio.h>
443#include <openssl/evp.h>
444
445int
446main(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 ,
486and
487.Fn EVP_DigestFinal
488are 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 ,
496and
497.Fn EVP_DigestFinal_ex
498were 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 ,
506and
507.Fn EVP_ripemd160
508were changed to return truely const
509.Vt EVP_MD
510pointers in OpenSSL 0.9.7.
511.Pp
512The link between digests and signing algorithms was fixed in OpenSSL 1.0
513and later, so now
514.Fn EVP_sha1
515can be used with RSA and DSA, there is no need to use
516.Fn EVP_dss1
517any more.
518.Pp
519OpenSSL 1.0 and later does not include the MD2 digest algorithm in the
520default configuration due to its security weaknesses.