]>
Commit | Line | Data |
---|---|---|
3cbe1980 DSH |
1 | =pod |
2 | ||
3 | =head1 NAME | |
4 | ||
37842dfa | 5 | EVP_MD_CTX_new, EVP_MD_CTX_reset, EVP_MD_CTX_free, EVP_MD_CTX_copy, |
d5e5e2ff SL |
6 | EVP_MD_CTX_copy_ex, EVP_MD_CTX_ctrl, EVP_MD_CTX_set_params, EVP_MD_CTX_get_params, |
7 | EVP_MD_CTX_set_flags, EVP_MD_CTX_clear_flags, EVP_MD_CTX_test_flags, | |
37842dfa | 8 | EVP_Digest, EVP_DigestInit_ex, EVP_DigestInit, EVP_DigestUpdate, |
cd8d1456 | 9 | EVP_DigestFinal_ex, EVP_DigestFinalXOF, EVP_DigestFinal, |
37842dfa AS |
10 | EVP_MD_type, EVP_MD_pkey_type, EVP_MD_size, EVP_MD_block_size, EVP_MD_flags, |
11 | EVP_MD_CTX_md, EVP_MD_CTX_type, EVP_MD_CTX_size, EVP_MD_CTX_block_size, | |
12 | EVP_MD_CTX_md_data, EVP_MD_CTX_update_fn, EVP_MD_CTX_set_update_fn, | |
a9cf71a3 | 13 | EVP_md_null, |
37842dfa AS |
14 | EVP_get_digestbyname, EVP_get_digestbynid, EVP_get_digestbyobj, |
15 | EVP_MD_CTX_pkey_ctx, EVP_MD_CTX_set_pkey_ctx - EVP digest routines | |
3cbe1980 DSH |
16 | |
17 | =head1 SYNOPSIS | |
18 | ||
19 | #include <openssl/evp.h> | |
20 | ||
25191fff RL |
21 | EVP_MD_CTX *EVP_MD_CTX_new(void); |
22 | int EVP_MD_CTX_reset(EVP_MD_CTX *ctx); | |
23 | void EVP_MD_CTX_free(EVP_MD_CTX *ctx); | |
52ad5b60 | 24 | void EVP_MD_CTX_ctrl(EVP_MD_CTX *ctx, int cmd, int p1, void* p2); |
d5e5e2ff SL |
25 | int EVP_MD_CTX_get_params(EVP_MD_CTX *ctx, const OSSL_PARAM params[]); |
26 | int EVP_MD_CTX_set_params(EVP_MD_CTX *ctx, const OSSL_PARAM params[]); | |
a9cf71a3 RL |
27 | void EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags); |
28 | void EVP_MD_CTX_clear_flags(EVP_MD_CTX *ctx, int flags); | |
29 | int EVP_MD_CTX_test_flags(const EVP_MD_CTX *ctx, int flags); | |
e72d734d | 30 | |
37842dfa AS |
31 | int EVP_Digest(const void *data, size_t count, unsigned char *md, |
32 | unsigned int *size, const EVP_MD *type, ENGINE *impl); | |
e72d734d | 33 | int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl); |
109d3123 | 34 | int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *d, size_t cnt); |
e9b77246 | 35 | int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *s); |
cd8d1456 | 36 | int EVP_DigestFinalXOF(EVP_MD_CTX *ctx, unsigned char *md, size_t len); |
e72d734d | 37 | |
aebb9aac | 38 | int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in); |
e72d734d DSH |
39 | |
40 | int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type); | |
e9b77246 | 41 | int EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *s); |
3cbe1980 | 42 | |
aebb9aac | 43 | int EVP_MD_CTX_copy(EVP_MD_CTX *out, EVP_MD_CTX *in); |
e72d734d | 44 | |
5a34fcd7 | 45 | int EVP_MD_type(const EVP_MD *md); |
05ea606a | 46 | int EVP_MD_pkey_type(const EVP_MD *md); |
5a34fcd7 DSH |
47 | int EVP_MD_size(const EVP_MD *md); |
48 | int EVP_MD_block_size(const EVP_MD *md); | |
37842dfa | 49 | unsigned long EVP_MD_flags(const EVP_MD *md); |
3cbe1980 | 50 | |
5a34fcd7 | 51 | const EVP_MD *EVP_MD_CTX_md(const EVP_MD_CTX *ctx); |
25191fff RL |
52 | int EVP_MD_CTX_size(const EVP_MD *ctx); |
53 | int EVP_MD_CTX_block_size(const EVP_MD *ctx); | |
54 | int EVP_MD_CTX_type(const EVP_MD *ctx); | |
a9cf71a3 | 55 | void *EVP_MD_CTX_md_data(const EVP_MD_CTX *ctx); |
37842dfa AS |
56 | int (*EVP_MD_CTX_update_fn(EVP_MD_CTX *ctx))(EVP_MD_CTX *ctx, |
57 | const void *data, size_t count); | |
58 | void EVP_MD_CTX_set_update_fn(EVP_MD_CTX *ctx, | |
59 | int (*update)(EVP_MD_CTX *ctx, | |
60 | const void *data, size_t count)); | |
3cbe1980 | 61 | |
13588350 | 62 | const EVP_MD *EVP_md_null(void); |
e4adad92 | 63 | |
3cbe1980 | 64 | const EVP_MD *EVP_get_digestbyname(const char *name); |
25191fff RL |
65 | const EVP_MD *EVP_get_digestbynid(int type); |
66 | const EVP_MD *EVP_get_digestbyobj(const ASN1_OBJECT *o); | |
3cbe1980 | 67 | |
37842dfa | 68 | EVP_PKEY_CTX *EVP_MD_CTX_pkey_ctx(const EVP_MD_CTX *ctx); |
675f4cee PY |
69 | void EVP_MD_CTX_set_pkey_ctx(EVP_MD_CTX *ctx, EVP_PKEY_CTX *pctx); |
70 | ||
3cbe1980 DSH |
71 | =head1 DESCRIPTION |
72 | ||
c7497f34 RS |
73 | The EVP digest routines are a high level interface to message digests, |
74 | and should be used instead of the cipher-specific functions. | |
3cbe1980 | 75 | |
bbda8ce9 | 76 | =over 4 |
25191fff | 77 | |
bbda8ce9 | 78 | =item EVP_MD_CTX_new() |
e72d734d | 79 | |
b45497c3 | 80 | Allocates and returns a digest context. |
e72d734d | 81 | |
bbda8ce9 | 82 | =item EVP_MD_CTX_reset() |
52ad5b60 | 83 | |
bbda8ce9 RT |
84 | Resets the digest context B<ctx>. This can be used to reuse an already |
85 | existing context. | |
3cbe1980 | 86 | |
bbda8ce9 | 87 | =item EVP_MD_CTX_free() |
3cbe1980 | 88 | |
bbda8ce9 | 89 | Cleans up digest context B<ctx> and frees up the space allocated to it. |
3cbe1980 | 90 | |
bbda8ce9 RT |
91 | =item EVP_MD_CTX_ctrl() |
92 | ||
d5e5e2ff SL |
93 | This is a deprecated function. EVP_MD_CTX_set_params() and EVP_MD_CTX_get_params() |
94 | is the mechanism that should be used to set and get parameters that are used by | |
95 | providers. | |
37842dfa AS |
96 | Performs digest-specific control actions on context B<ctx>. The control command |
97 | is indicated in B<cmd> and any additional arguments in B<p1> and B<p2>. | |
98 | EVP_MD_CTX_ctrl() must be called after EVP_DigestInit_ex(). Other restrictions | |
99 | may apply depending on the control type and digest implementation. | |
100 | See L</CONTROLS> below for more information. | |
bbda8ce9 | 101 | |
d5e5e2ff SL |
102 | =item EVP_MD_CTX_get_params |
103 | ||
104 | Retrieves the requested list of B<params> from a MD context B<ctx>. | |
105 | See L</PARAMS> below for more information. | |
106 | ||
107 | =item EVP_MD_CTX_set_params | |
108 | ||
109 | Sets the list of <params> into a MD context B<ctx>. | |
110 | See L</PARAMS> below for more information. | |
111 | ||
a9cf71a3 RL |
112 | =item EVP_MD_CTX_set_flags(), EVP_MD_CTX_clear_flags(), EVP_MD_CTX_test_flags() |
113 | ||
114 | Sets, clears and tests B<ctx> flags. See L</FLAGS> below for more information. | |
115 | ||
37842dfa AS |
116 | =item EVP_Digest() |
117 | ||
118 | A wrapper around the Digest Init_ex, Update and Final_ex functions. | |
119 | Hashes B<count> bytes of data at B<data> using a digest B<type> from ENGINE | |
120 | B<impl>. The digest value is placed in B<md> and its length is written at B<size> | |
121 | if the pointer is not NULL. At most B<EVP_MAX_MD_SIZE> bytes will be written. | |
122 | If B<impl> is NULL the default implementation of digest B<type> is used. | |
123 | ||
bbda8ce9 RT |
124 | =item EVP_DigestInit_ex() |
125 | ||
126 | Sets up digest context B<ctx> to use a digest B<type> from ENGINE B<impl>. | |
b45497c3 P |
127 | B<type> will typically be supplied by a function such as EVP_sha1(). If |
128 | B<impl> is NULL then the default implementation of digest B<type> is used. | |
bbda8ce9 RT |
129 | |
130 | =item EVP_DigestUpdate() | |
131 | ||
132 | Hashes B<cnt> bytes of data at B<d> into the digest context B<ctx>. This | |
133 | function can be called several times on the same B<ctx> to hash additional | |
134 | data. | |
135 | ||
136 | =item EVP_DigestFinal_ex() | |
137 | ||
138 | Retrieves the digest value from B<ctx> and places it in B<md>. If the B<s> | |
139 | parameter is not NULL then the number of bytes of data written (i.e. the | |
140 | length of the digest) will be written to the integer at B<s>, at most | |
141 | B<EVP_MAX_MD_SIZE> bytes will be written. After calling EVP_DigestFinal_ex() | |
cd8d1456 | 142 | no additional calls to EVP_DigestUpdate() can be made, but |
bbda8ce9 RT |
143 | EVP_DigestInit_ex() can be called to initialize a new digest operation. |
144 | ||
145 | =item EVP_DigestFinalXOF() | |
146 | ||
147 | Interfaces to extendable-output functions, XOFs, such as SHAKE128 and SHAKE256. | |
148 | It retrieves the digest value from B<ctx> and places it in B<len>-sized <B>md. | |
149 | After calling this function no additional calls to EVP_DigestUpdate() can be | |
150 | made, but EVP_DigestInit_ex() can be called to initialize a new operation. | |
151 | ||
152 | =item EVP_MD_CTX_copy_ex() | |
153 | ||
154 | Can be used to copy the message digest state from B<in> to B<out>. This is | |
155 | useful if large amounts of data are to be hashed which only differ in the last | |
b45497c3 | 156 | few bytes. |
bbda8ce9 RT |
157 | |
158 | =item EVP_DigestInit() | |
159 | ||
b45497c3 P |
160 | Behaves in the same way as EVP_DigestInit_ex() except it always uses the |
161 | default digest implementation. | |
bbda8ce9 RT |
162 | |
163 | =item EVP_DigestFinal() | |
164 | ||
165 | Similar to EVP_DigestFinal_ex() except the digest context B<ctx> is | |
166 | automatically cleaned up. | |
167 | ||
168 | =item EVP_MD_CTX_copy() | |
cd8d1456 | 169 | |
bbda8ce9 RT |
170 | Similar to EVP_MD_CTX_copy_ex() except the destination B<out> does not have to |
171 | be initialized. | |
e72d734d | 172 | |
bbda8ce9 RT |
173 | =item EVP_MD_size(), |
174 | EVP_MD_CTX_size() | |
e72d734d | 175 | |
bbda8ce9 RT |
176 | Return the size of the message digest when passed an B<EVP_MD> or an |
177 | B<EVP_MD_CTX> structure, i.e. the size of the hash. | |
e72d734d | 178 | |
bbda8ce9 RT |
179 | =item EVP_MD_block_size(), |
180 | EVP_MD_CTX_block_size() | |
3cbe1980 | 181 | |
bbda8ce9 RT |
182 | Return the block size of the message digest when passed an B<EVP_MD> or an |
183 | B<EVP_MD_CTX> structure. | |
3cbe1980 | 184 | |
bbda8ce9 RT |
185 | =item EVP_MD_type(), |
186 | EVP_MD_CTX_type() | |
3cbe1980 | 187 | |
bbda8ce9 RT |
188 | Return the NID of the OBJECT IDENTIFIER representing the given message digest |
189 | when passed an B<EVP_MD> structure. For example, C<EVP_MD_type(EVP_sha1())> | |
190 | returns B<NID_sha1>. This function is normally used when setting ASN1 OIDs. | |
3cbe1980 | 191 | |
a9cf71a3 RL |
192 | =item EVP_MD_CTX_md_data() |
193 | ||
194 | Return the digest method private data for the passed B<EVP_MD_CTX>. | |
195 | The space is allocated by OpenSSL and has the size originally set with | |
196 | EVP_MD_meth_set_app_datasize(). | |
197 | ||
bbda8ce9 | 198 | =item EVP_MD_CTX_md() |
3cbe1980 | 199 | |
b7c913c8 MC |
200 | Returns the B<EVP_MD> structure corresponding to the passed B<EVP_MD_CTX>. This |
201 | will be the same B<EVP_MD> object originally passed to EVP_DigestInit_ex() (or | |
202 | other similar function) when the EVP_MD_CTX was first initialised. Note that | |
203 | where explicit fetch is in use (see L<EVP_MD_fetch(3)>) the value returned from | |
204 | this function will not have its reference count incremented and therefore it | |
205 | should not be used after the EVP_MD_CTX is freed. | |
3cbe1980 | 206 | |
37842dfa AS |
207 | =item EVP_MD_CTX_set_update_fn() |
208 | ||
209 | Sets the update function for B<ctx> to B<update>. | |
210 | This is the function that is called by EVP_DigestUpdate. If not set, the | |
211 | update function from the B<EVP_MD> type specified at initialization is used. | |
212 | ||
213 | =item EVP_MD_CTX_update_fn() | |
214 | ||
215 | Returns the update function for B<ctx>. | |
216 | ||
217 | =item EVP_MD_flags() | |
218 | ||
219 | Returns the B<md> flags. Note that these are different from the B<EVP_MD_CTX> | |
220 | ones. See L<EVP_MD_meth_set_flags(3)> for more information. | |
221 | ||
bbda8ce9 | 222 | =item EVP_MD_pkey_type() |
3cbe1980 | 223 | |
bbda8ce9 RT |
224 | Returns the NID of the public key signing algorithm associated with this |
225 | digest. For example EVP_sha1() is associated with RSA so this will return | |
226 | B<NID_sha1WithRSAEncryption>. Since digests and signature algorithms are no | |
227 | longer linked this function is only retained for compatibility reasons. | |
3cbe1980 | 228 | |
bbda8ce9 RT |
229 | =item EVP_md_null() |
230 | ||
231 | A "null" message digest that does nothing: i.e. the hash it returns is of zero | |
232 | length. | |
233 | ||
234 | =item EVP_get_digestbyname(), | |
235 | EVP_get_digestbynid(), | |
236 | EVP_get_digestbyobj() | |
237 | ||
238 | Returns an B<EVP_MD> structure when passed a digest name, a digest B<NID> or an | |
239 | B<ASN1_OBJECT> structure respectively. | |
240 | ||
37842dfa AS |
241 | =item EVP_MD_CTX_pkey_ctx() |
242 | ||
243 | Returns the B<EVP_PKEY_CTX> assigned to B<ctx>. The returned pointer should not | |
244 | be freed by the caller. | |
245 | ||
675f4cee PY |
246 | =item EVP_MD_CTX_set_pkey_ctx() |
247 | ||
248 | Assigns an B<EVP_PKEY_CTX> to B<EVP_MD_CTX>. This is usually used to provide | |
37842dfa | 249 | a customized B<EVP_PKEY_CTX> to L<EVP_DigestSignInit(3)> or |
81c79453 | 250 | L<EVP_DigestVerifyInit(3)>. The B<pctx> passed to this function should be freed |
f922dac8 | 251 | by the caller. A NULL B<pctx> pointer is also allowed to clear the B<EVP_PKEY_CTX> |
81c79453 PY |
252 | assigned to B<ctx>. In such case, freeing the cleared B<EVP_PKEY_CTX> or not |
253 | depends on how the B<EVP_PKEY_CTX> is created. | |
675f4cee | 254 | |
bbda8ce9 | 255 | =back |
3cbe1980 | 256 | |
d5e5e2ff SL |
257 | =head1 PARAMS |
258 | ||
259 | See L<OSSL_PARAM(3)> for information about passing parameters. | |
260 | ||
261 | EVP_MD_CTX_set_params() can be used with the following OSSL_PARAM keys: | |
262 | ||
263 | =over 4 | |
264 | ||
265 | =item OSSL_PARAM_DIGEST_KEY_XOFLEN <size_t> | |
266 | ||
267 | Sets the digest length for extendable output functions. | |
268 | It is used by the SHAKE algorithm. | |
269 | ||
270 | =item OSSL_PARAM_DIGEST_KEY_PAD_TYPE <int> | |
271 | ||
272 | Sets the pad type. | |
273 | It is used by the MDC2 algorithm. | |
274 | ||
275 | =back | |
276 | ||
277 | EVP_MD_CTX_get_params() can be used with the following OSSL_PARAM keys: | |
278 | ||
279 | =over 4 | |
280 | ||
281 | =item OSSL_PARAM_DIGEST_KEY_MICALG <utf8string>. | |
282 | ||
283 | Gets the digest Message Integrity Check algorithm string. This is used when | |
284 | creating S/MIME multipart/signed messages, as specified in RFC 3851. | |
285 | It may be used by external engines or providers. | |
286 | ||
287 | =back | |
288 | ||
37842dfa AS |
289 | =head1 CONTROLS |
290 | ||
291 | EVP_MD_CTX_ctrl() can be used to send the following standard controls: | |
292 | ||
293 | =over 4 | |
294 | ||
295 | =item EVP_MD_CTRL_MICALG | |
296 | ||
297 | Gets the digest Message Integrity Check algorithm string. This is used when | |
298 | creating S/MIME multipart/signed messages, as specified in RFC 3851. | |
299 | The string value is written to B<p2>. | |
300 | ||
301 | =item EVP_MD_CTRL_XOF_LEN | |
302 | ||
303 | This control sets the digest length for extendable output functions to B<p1>. | |
304 | Sending this control directly should not be necessary, the use of | |
305 | C<EVP_DigestFinalXOF()> is preferred. | |
306 | Currently used by SHAKE. | |
307 | ||
308 | =back | |
309 | ||
a9cf71a3 RL |
310 | =head1 FLAGS |
311 | ||
312 | EVP_MD_CTX_set_flags(), EVP_MD_CTX_clear_flags() and EVP_MD_CTX_test_flags() | |
313 | can be used the manipulate and test these B<EVP_MD_CTX> flags: | |
314 | ||
315 | =over 4 | |
316 | ||
317 | =item EVP_MD_CTX_FLAG_ONESHOT | |
318 | ||
319 | This flag instructs the digest to optimize for one update only, if possible. | |
320 | ||
321 | =for comment EVP_MD_CTX_FLAG_CLEANED is internal, don't mention it | |
322 | ||
323 | =for comment EVP_MD_CTX_FLAG_REUSE is internal, don't mention it | |
324 | ||
325 | =for comment We currently avoid documenting flags that are only bit holder: | |
326 | EVP_MD_CTX_FLAG_NON_FIPS_ALLOW, EVP_MD_CTX_FLAGS_PAD_* | |
327 | ||
328 | =item EVP_MD_CTX_FLAG_NO_INIT | |
329 | ||
330 | This flag instructs EVP_DigestInit() and similar not to initialise the | |
331 | implementation specific data. | |
332 | ||
333 | =item EVP_MD_CTX_FLAG_FINALISE | |
334 | ||
335 | Some functions such as EVP_DigestSign only finalise copies of internal | |
336 | contexts so additional data can be included after the finalisation call. | |
337 | This is inefficient if this functionality is not required, and can be | |
338 | disabled with this flag. | |
339 | ||
340 | =back | |
341 | ||
3cbe1980 DSH |
342 | =head1 RETURN VALUES |
343 | ||
bbda8ce9 RT |
344 | =over 4 |
345 | ||
346 | =item EVP_DigestInit_ex(), | |
347 | EVP_DigestUpdate(), | |
348 | EVP_DigestFinal_ex() | |
349 | ||
350 | Returns 1 for | |
13588350 | 351 | success and 0 for failure. |
3cbe1980 | 352 | |
bbda8ce9 RT |
353 | =item EVP_MD_CTX_ctrl() |
354 | ||
355 | Returns 1 if successful or 0 for failure. | |
356 | ||
d5e5e2ff SL |
357 | =item EVP_MD_CTX_set_params(), |
358 | EVP_MD_CTX_get_params() | |
359 | ||
360 | Returns 1 if successful or 0 for failure. | |
361 | ||
bbda8ce9 | 362 | =item EVP_MD_CTX_copy_ex() |
52ad5b60 | 363 | |
bbda8ce9 | 364 | Returns 1 if successful or 0 for failure. |
3cbe1980 | 365 | |
bbda8ce9 | 366 | =item EVP_MD_type(), |
37842dfa | 367 | EVP_MD_pkey_type() |
3cbe1980 | 368 | |
bbda8ce9 RT |
369 | Returns the NID of the corresponding OBJECT IDENTIFIER or NID_undef if none |
370 | exists. | |
3cbe1980 | 371 | |
bbda8ce9 RT |
372 | =item EVP_MD_size(), |
373 | EVP_MD_block_size(), | |
374 | EVP_MD_CTX_size(), | |
375 | EVP_MD_CTX_block_size() | |
3cbe1980 | 376 | |
bbda8ce9 RT |
377 | Returns the digest or block size in bytes. |
378 | ||
379 | =item EVP_md_null() | |
380 | ||
381 | Returns a pointer to the B<EVP_MD> structure of the "null" message digest. | |
382 | ||
383 | =item EVP_get_digestbyname(), | |
384 | EVP_get_digestbynid(), | |
385 | EVP_get_digestbyobj() | |
386 | ||
387 | Returns either an B<EVP_MD> structure or NULL if an error occurs. | |
388 | ||
675f4cee PY |
389 | =item EVP_MD_CTX_set_pkey_ctx() |
390 | ||
391 | This function has no return value. | |
392 | ||
bbda8ce9 | 393 | =back |
3cbe1980 DSH |
394 | |
395 | =head1 NOTES | |
396 | ||
397 | The B<EVP> interface to message digests should almost always be used in | |
398 | preference to the low level interfaces. This is because the code then becomes | |
399 | transparent to the digest used and much more flexible. | |
400 | ||
bbda8ce9 | 401 | New applications should use the SHA-2 (such as L<EVP_sha256(3)>) or the SHA-3 |
89f66fe2 | 402 | digest algorithms (such as L<EVP_sha3_512(3)>). The other digest algorithms |
403 | are still in common use. | |
3cbe1980 | 404 | |
e72d734d DSH |
405 | For most applications the B<impl> parameter to EVP_DigestInit_ex() will be |
406 | set to NULL to use the default digest implementation. | |
407 | ||
7b3e11c5 | 408 | The functions EVP_DigestInit(), EVP_DigestFinal() and EVP_MD_CTX_copy() are |
e72d734d | 409 | obsolete but are retained to maintain compatibility with existing code. New |
7b3e11c5 | 410 | applications should use EVP_DigestInit_ex(), EVP_DigestFinal_ex() and |
e72d734d DSH |
411 | EVP_MD_CTX_copy_ex() because they can efficiently reuse a digest context |
412 | instead of initializing and cleaning it up on each call and allow non default | |
413 | implementations of digests to be specified. | |
414 | ||
fa332bba | 415 | If digest contexts are not cleaned up after use, |
7b3e11c5 | 416 | memory leaks will occur. |
13588350 | 417 | |
25191fff RL |
418 | EVP_MD_CTX_size(), EVP_MD_CTX_block_size(), EVP_MD_CTX_type(), |
419 | EVP_get_digestbynid() and EVP_get_digestbyobj() are defined as | |
420 | macros. | |
5a34fcd7 | 421 | |
52ad5b60 TS |
422 | EVP_MD_CTX_ctrl() sends commands to message digests for additional configuration |
423 | or control. | |
5a34fcd7 | 424 | |
3cbe1980 DSH |
425 | =head1 EXAMPLE |
426 | ||
427 | This example digests the data "Test Message\n" and "Hello World\n", using the | |
428 | digest name passed on the command line. | |
429 | ||
430 | #include <stdio.h> | |
19ac1bf2 | 431 | #include <string.h> |
3cbe1980 DSH |
432 | #include <openssl/evp.h> |
433 | ||
19ac1bf2 | 434 | int main(int argc, char *argv[]) |
3cbe1980 | 435 | { |
2947af32 BB |
436 | EVP_MD_CTX *mdctx; |
437 | const EVP_MD *md; | |
438 | char mess1[] = "Test Message\n"; | |
439 | char mess2[] = "Hello World\n"; | |
440 | unsigned char md_value[EVP_MAX_MD_SIZE]; | |
19ac1bf2 | 441 | unsigned int md_len, i; |
2947af32 BB |
442 | |
443 | if (argv[1] == NULL) { | |
444 | printf("Usage: mdtest digestname\n"); | |
445 | exit(1); | |
446 | } | |
447 | ||
448 | md = EVP_get_digestbyname(argv[1]); | |
449 | if (md == NULL) { | |
450 | printf("Unknown message digest %s\n", argv[1]); | |
451 | exit(1); | |
452 | } | |
453 | ||
454 | mdctx = EVP_MD_CTX_new(); | |
455 | EVP_DigestInit_ex(mdctx, md, NULL); | |
456 | EVP_DigestUpdate(mdctx, mess1, strlen(mess1)); | |
457 | EVP_DigestUpdate(mdctx, mess2, strlen(mess2)); | |
458 | EVP_DigestFinal_ex(mdctx, md_value, &md_len); | |
459 | EVP_MD_CTX_free(mdctx); | |
460 | ||
461 | printf("Digest is: "); | |
462 | for (i = 0; i < md_len; i++) | |
463 | printf("%02x", md_value[i]); | |
464 | printf("\n"); | |
465 | ||
466 | exit(0); | |
3cbe1980 DSH |
467 | } |
468 | ||
3cbe1980 DSH |
469 | =head1 SEE ALSO |
470 | ||
37842dfa | 471 | L<EVP_MD_meth_new(3)>, |
9b86974e | 472 | L<dgst(1)>, |
d5e5e2ff SL |
473 | L<evp(7)>, |
474 | L<OSSL_PROVIDER(3)>, | |
475 | L<OSSL_PARAM(3)> | |
4facdbb5 | 476 | |
bbda8ce9 RT |
477 | The full list of digest algorithms are provided below. |
478 | ||
479 | L<EVP_blake2b512(3)>, | |
480 | L<EVP_md2(3)>, | |
481 | L<EVP_md4(3)>, | |
482 | L<EVP_md5(3)>, | |
483 | L<EVP_mdc2(3)>, | |
484 | L<EVP_ripemd160(3)>, | |
485 | L<EVP_sha1(3)>, | |
486 | L<EVP_sha224(3)>, | |
487 | L<EVP_sha3_224(3)>, | |
67e247fa | 488 | L<EVP_sm3(3)>, |
bbda8ce9 RT |
489 | L<EVP_whirlpool(3)> |
490 | ||
3cbe1980 DSH |
491 | =head1 HISTORY |
492 | ||
fc5ecadd DMSP |
493 | The EVP_MD_CTX_create() and EVP_MD_CTX_destroy() functions were renamed to |
494 | EVP_MD_CTX_new() and EVP_MD_CTX_free() in OpenSSL 1.1.0, respectively. | |
25191fff | 495 | |
3fa39ed7 | 496 | The link between digests and signing algorithms was fixed in OpenSSL 1.0 and |
a95d7574 RS |
497 | later, so now EVP_sha1() can be used with RSA and DSA. |
498 | ||
fc5ecadd | 499 | The EVP_dss1() function was removed in OpenSSL 1.1.0. |
3fa39ed7 | 500 | |
fc5ecadd | 501 | The EVP_MD_CTX_set_pkey_ctx() function was added in 1.1.1. |
675f4cee | 502 | |
d5e5e2ff SL |
503 | The EVP_MD_CTX_set_params() and EVP_MD_CTX_get_params() functions were |
504 | added in 3.0. | |
505 | ||
e2f92610 RS |
506 | =head1 COPYRIGHT |
507 | ||
d5e5e2ff | 508 | Copyright 2000-2019 The OpenSSL Project Authors. All Rights Reserved. |
e2f92610 | 509 | |
4746f25a | 510 | Licensed under the Apache License 2.0 (the "License"). You may not use |
e2f92610 RS |
511 | this file except in compliance with the License. You can obtain a copy |
512 | in the file LICENSE in the source distribution or at | |
513 | L<https://www.openssl.org/source/license.html>. | |
514 | ||
515 | =cut |