Replace provider digest flags with separate param fields
[openssl.git] / doc / man3 / EVP_DigestInit.pod
1 =pod
2
3 =head1 NAME
4
5 EVP_MD_fetch, EVP_MD_up_ref, EVP_MD_free,
6 EVP_MD_get_params, EVP_MD_gettable_params,
7 EVP_MD_CTX_new, EVP_MD_CTX_reset, EVP_MD_CTX_free, EVP_MD_CTX_copy,
8 EVP_MD_CTX_copy_ex, EVP_MD_CTX_ctrl,
9 EVP_MD_CTX_set_params, EVP_MD_CTX_get_params,
10 EVP_MD_settable_ctx_params, EVP_MD_gettable_ctx_params,
11 EVP_MD_CTX_settable_params, EVP_MD_CTX_gettable_params,
12 EVP_MD_CTX_set_flags, EVP_MD_CTX_clear_flags, EVP_MD_CTX_test_flags,
13 EVP_Digest, EVP_DigestInit_ex, EVP_DigestInit, EVP_DigestUpdate,
14 EVP_DigestFinal_ex, EVP_DigestFinalXOF, EVP_DigestFinal,
15 EVP_MD_is_a, EVP_MD_name, EVP_MD_number, EVP_MD_names_do_all, EVP_MD_provider,
16 EVP_MD_type, EVP_MD_pkey_type, EVP_MD_size, EVP_MD_block_size, EVP_MD_flags,
17 EVP_MD_CTX_name,
18 EVP_MD_CTX_md, EVP_MD_CTX_type, EVP_MD_CTX_size, EVP_MD_CTX_block_size,
19 EVP_MD_CTX_md_data, EVP_MD_CTX_update_fn, EVP_MD_CTX_set_update_fn,
20 EVP_md_null,
21 EVP_get_digestbyname, EVP_get_digestbynid, EVP_get_digestbyobj,
22 EVP_MD_CTX_pkey_ctx, EVP_MD_CTX_set_pkey_ctx,
23 EVP_MD_do_all_provided
24 - EVP digest routines
25
26 =head1 SYNOPSIS
27
28  #include <openssl/evp.h>
29
30  EVP_MD *EVP_MD_fetch(OSSL_LIB_CTX *ctx, const char *algorithm,
31                       const char *properties);
32  int EVP_MD_up_ref(EVP_MD *md);
33  void EVP_MD_free(EVP_MD *md);
34  int EVP_MD_get_params(const EVP_MD *digest, OSSL_PARAM params[]);
35  const OSSL_PARAM *EVP_MD_gettable_params(const EVP_MD *digest);
36  EVP_MD_CTX *EVP_MD_CTX_new(void);
37  int EVP_MD_CTX_reset(EVP_MD_CTX *ctx);
38  void EVP_MD_CTX_free(EVP_MD_CTX *ctx);
39  void EVP_MD_CTX_ctrl(EVP_MD_CTX *ctx, int cmd, int p1, void* p2);
40  int EVP_MD_CTX_get_params(EVP_MD_CTX *ctx, OSSL_PARAM params[]);
41  int EVP_MD_CTX_set_params(EVP_MD_CTX *ctx, const OSSL_PARAM params[]);
42  const OSSL_PARAM *EVP_MD_settable_ctx_params(const EVP_MD *md);
43  const OSSL_PARAM *EVP_MD_gettable_ctx_params(const EVP_MD *md);
44  const OSSL_PARAM *EVP_MD_CTX_settable_params(EVP_MD_CTX *ctx);
45  const OSSL_PARAM *EVP_MD_CTX_gettable_params(EVP_MD_CTX *ctx);
46  void EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags);
47  void EVP_MD_CTX_clear_flags(EVP_MD_CTX *ctx, int flags);
48  int EVP_MD_CTX_test_flags(const EVP_MD_CTX *ctx, int flags);
49
50  int EVP_Digest(const void *data, size_t count, unsigned char *md,
51                 unsigned int *size, const EVP_MD *type, ENGINE *impl);
52  int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl);
53  int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *d, size_t cnt);
54  int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *s);
55  int EVP_DigestFinalXOF(EVP_MD_CTX *ctx, unsigned char *md, size_t len);
56
57  int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in);
58
59  int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type);
60  int EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *s);
61
62  int EVP_MD_CTX_copy(EVP_MD_CTX *out, EVP_MD_CTX *in);
63
64  const char *EVP_MD_name(const EVP_MD *md);
65  int EVP_MD_number(const EVP_MD *md);
66  int EVP_MD_is_a(const EVP_MD *md, const char *name);
67  void EVP_MD_names_do_all(const EVP_MD *md,
68                           void (*fn)(const char *name, void *data),
69                           void *data);
70  const OSSL_PROVIDER *EVP_MD_provider(const EVP_MD *md);
71  int EVP_MD_type(const EVP_MD *md);
72  int EVP_MD_pkey_type(const EVP_MD *md);
73  int EVP_MD_size(const EVP_MD *md);
74  int EVP_MD_block_size(const EVP_MD *md);
75  unsigned long EVP_MD_flags(const EVP_MD *md);
76
77  const EVP_MD *EVP_MD_CTX_md(const EVP_MD_CTX *ctx);
78  const char *EVP_MD_CTX_name(const EVP_MD_CTX *ctx);
79  int EVP_MD_CTX_size(const EVP_MD_CTX *ctx);
80  int EVP_MD_CTX_block_size(const EVP_MD_CTX *ctx);
81  int EVP_MD_CTX_type(const EVP_MD_CTX *ctx);
82  void *EVP_MD_CTX_md_data(const EVP_MD_CTX *ctx);
83
84  const EVP_MD *EVP_md_null(void);
85
86  const EVP_MD *EVP_get_digestbyname(const char *name);
87  const EVP_MD *EVP_get_digestbynid(int type);
88  const EVP_MD *EVP_get_digestbyobj(const ASN1_OBJECT *o);
89
90  EVP_PKEY_CTX *EVP_MD_CTX_pkey_ctx(const EVP_MD_CTX *ctx);
91  void EVP_MD_CTX_set_pkey_ctx(EVP_MD_CTX *ctx, EVP_PKEY_CTX *pctx);
92
93  void EVP_MD_do_all_provided(OSSL_LIB_CTX *libctx,
94                              void (*fn)(EVP_MD *mac, void *arg),
95                              void *arg);
96
97 Deprecated since OpenSSL 3.0, can be hidden entirely by defining
98 B<OPENSSL_API_COMPAT> with a suitable version value, see
99 L<openssl_user_macros(7)>:
100
101  int (*EVP_MD_CTX_update_fn(EVP_MD_CTX *ctx))(EVP_MD_CTX *ctx,
102                                               const void *data, size_t count);
103
104  void EVP_MD_CTX_set_update_fn(EVP_MD_CTX *ctx,
105                                int (*update)(EVP_MD_CTX *ctx,
106                                              const void *data, size_t count));
107
108 =head1 DESCRIPTION
109
110 The EVP digest routines are a high-level interface to message digests,
111 and should be used instead of the digest-specific functions.
112
113 The B<EVP_MD> type is a structure for digest method implementation.
114
115 =over 4
116
117 =item EVP_MD_fetch()
118
119 Fetches the digest implementation for the given I<algorithm> from any
120 provider offering it, within the criteria given by the I<properties>.
121 See L<provider(7)/Fetching algorithms> for further information.
122
123 The returned value must eventually be freed with EVP_MD_free().
124
125 Fetched B<EVP_MD> structures are reference counted.
126
127 =item EVP_MD_up_ref()
128
129 Increments the reference count for an B<EVP_MD> structure.
130
131 =item EVP_MD_free()
132
133 Decrements the reference count for the fetched B<EVP_MD> structure.
134 If the reference count drops to 0 then the structure is freed.
135
136 =item EVP_MD_CTX_new()
137
138 Allocates and returns a digest context.
139
140 =item EVP_MD_CTX_reset()
141
142 Resets the digest context I<ctx>.  This can be used to reuse an already
143 existing context.
144
145 =item EVP_MD_CTX_free()
146
147 Cleans up digest context I<ctx> and frees up the space allocated to it.
148
149 =item EVP_MD_CTX_ctrl()
150
151 I<This is a legacy method. EVP_MD_CTX_set_params() and EVP_MD_CTX_get_params()
152 is the mechanism that should be used to set and get parameters that are used by
153 providers.>
154
155 Performs digest-specific control actions on context I<ctx>. The control command
156 is indicated in I<cmd> and any additional arguments in I<p1> and I<p2>.
157 EVP_MD_CTX_ctrl() must be called after EVP_DigestInit_ex(). Other restrictions
158 may apply depending on the control type and digest implementation.
159
160 If this function happens to be used with a fetched B<EVP_MD>, it will
161 translate the controls that are known to OpenSSL into L<OSSL_PARAM(3)>
162 parameters with keys defined by OpenSSL and call EVP_MD_CTX_get_params() or
163 EVP_MD_CTX_set_params() as is appropriate for each control command.
164
165 See L</CONTROLS> below for more information, including what translations are
166 being done.
167
168 =item EVP_MD_get_params()
169
170 Retrieves the requested list of I<params> from a MD I<md>.
171 See L</PARAMETERS> below for more information.
172
173 =item EVP_MD_CTX_get_params()
174
175 Retrieves the requested list of I<params> from a MD context I<ctx>.
176 See L</PARAMETERS> below for more information.
177
178 =item EVP_MD_CTX_set_params()
179
180 Sets the list of I<params> into a MD context I<ctx>.
181 See L</PARAMETERS> below for more information.
182
183 =item EVP_MD_gettable_params(), EVP_MD_gettable_ctx_params(),
184 EVP_MD_settable_ctx_params(), EVP_MD_CTX_gettable_params(),
185 EVP_MD_CTX_settable_params()
186
187 Get a B<OSSL_PARAM> array that describes the retrievable and settable
188 parameters. EVP_MD_gettable_params() returns parameters that can be used with
189 EVP_MD_get_params(). EVP_MD_gettable_ctx_params() and
190 EVP_MD_CTX_gettable_params() return parameters that can be used with
191 EVP_MD_CTX_get_params(). EVP_MD_settable_ctx_params() and
192 EVP_MD_CTX_settable_params() return parameters that can be used with
193 EVP_MD_CTX_set_params().
194 See L<OSSL_PARAM(3)> for the use of B<OSSL_PARAM> as parameter descriptor.
195
196 =item EVP_MD_CTX_set_flags(), EVP_MD_CTX_clear_flags(), EVP_MD_CTX_test_flags()
197
198 Sets, clears and tests I<ctx> flags.  See L</FLAGS> below for more information.
199
200 =item EVP_Digest()
201
202 A wrapper around the Digest Init_ex, Update and Final_ex functions.
203 Hashes I<count> bytes of data at I<data> using a digest I<type> from ENGINE
204 I<impl>. The digest value is placed in I<md> and its length is written at I<size>
205 if the pointer is not NULL. At most B<EVP_MAX_MD_SIZE> bytes will be written.
206 If I<impl> is NULL the default implementation of digest I<type> is used.
207
208 =item EVP_DigestInit_ex()
209
210 Sets up digest context I<ctx> to use a digest I<type>.
211 I<type> is typically supplied by a function such as EVP_sha1(), or a
212 value explicitly fetched with EVP_MD_fetch().
213
214 If I<impl> is non-NULL, its implementation of the digest I<type> is used if
215 there is one, and if not, the default implementation is used.
216
217 The I<type> parameter can be NULL if I<ctx> has been already initialized
218 with another EVP_DigestInit_ex() call and has not been reset with
219 EVP_MD_CTX_reset().
220
221 =item EVP_DigestUpdate()
222
223 Hashes I<cnt> bytes of data at I<d> into the digest context I<ctx>. This
224 function can be called several times on the same I<ctx> to hash additional
225 data.
226
227 =item EVP_DigestFinal_ex()
228
229 Retrieves the digest value from I<ctx> and places it in I<md>. If the I<s>
230 parameter is not NULL then the number of bytes of data written (i.e. the
231 length of the digest) will be written to the integer at I<s>, at most
232 B<EVP_MAX_MD_SIZE> bytes will be written.  After calling EVP_DigestFinal_ex()
233 no additional calls to EVP_DigestUpdate() can be made, but
234 EVP_DigestInit_ex() can be called to initialize a new digest operation.
235
236 =item EVP_DigestFinalXOF()
237
238 Interfaces to extendable-output functions, XOFs, such as SHAKE128 and SHAKE256.
239 It retrieves the digest value from I<ctx> and places it in I<len>-sized I<md>.
240 After calling this function no additional calls to EVP_DigestUpdate() can be
241 made, but EVP_DigestInit_ex() can be called to initialize a new operation.
242
243 =item EVP_MD_CTX_copy_ex()
244
245 Can be used to copy the message digest state from I<in> to I<out>. This is
246 useful if large amounts of data are to be hashed which only differ in the last
247 few bytes.
248
249 =item EVP_DigestInit()
250
251 Behaves in the same way as EVP_DigestInit_ex() except it always uses the
252 default digest implementation and calls EVP_MD_CTX_reset() so it cannot
253 be used with an I<type> of NULL.
254
255 =item EVP_DigestFinal()
256
257 Similar to EVP_DigestFinal_ex() except after computing the digest
258 the digest context I<ctx> is automatically cleaned up with EVP_MD_CTX_reset().
259
260 =item EVP_MD_CTX_copy()
261
262 Similar to EVP_MD_CTX_copy_ex() except the destination I<out> does not have to
263 be initialized.
264
265 =item EVP_MD_is_a()
266
267 Returns 1 if I<md> is an implementation of an algorithm that's
268 identifiable with I<name>, otherwise 0.
269
270 If I<md> is a legacy digest (it's the return value from the likes of
271 EVP_sha256() rather than the result of an EVP_MD_fetch()), only cipher
272 names registered with the default library context (see
273 L<OSSL_LIB_CTX(3)>) will be considered.
274
275 =item EVP_MD_number()
276
277 Returns the internal dynamic number assigned to the I<md>.  This is
278 only useful with fetched B<EVP_MD>s.
279
280 =item EVP_MD_name(),
281 EVP_MD_CTX_name()
282
283 Return the name of the given message digest.  For fetched message
284 digests with multiple names, only one of them is returned; it's
285 recommended to use EVP_MD_names_do_all() instead.
286
287 =item EVP_MD_names_do_all()
288
289 Traverses all names for the I<md>, and calls I<fn> with each name and
290 I<data>.  This is only useful with fetched B<EVP_MD>s.
291
292 =item EVP_MD_provider()
293
294 Returns an B<OSSL_PROVIDER> pointer to the provider that implements the given
295 B<EVP_MD>.
296
297 =item EVP_MD_size(),
298 EVP_MD_CTX_size()
299
300 Return the size of the message digest when passed an B<EVP_MD> or an
301 B<EVP_MD_CTX> structure, i.e. the size of the hash.
302
303 =item EVP_MD_block_size(),
304 EVP_MD_CTX_block_size()
305
306 Return the block size of the message digest when passed an B<EVP_MD> or an
307 B<EVP_MD_CTX> structure.
308
309 =item EVP_MD_type(),
310 EVP_MD_CTX_type()
311
312 Return the NID of the OBJECT IDENTIFIER representing the given message digest
313 when passed an B<EVP_MD> structure.  For example, C<EVP_MD_type(EVP_sha1())>
314 returns B<NID_sha1>. This function is normally used when setting ASN1 OIDs.
315
316 =item EVP_MD_CTX_md_data()
317
318 Return the digest method private data for the passed B<EVP_MD_CTX>.
319 The space is allocated by OpenSSL and has the size originally set with
320 EVP_MD_meth_set_app_datasize().
321
322 =item EVP_MD_CTX_md()
323
324 Returns the B<EVP_MD> structure corresponding to the passed B<EVP_MD_CTX>. This
325 will be the same B<EVP_MD> object originally passed to EVP_DigestInit_ex() (or
326 other similar function) when the EVP_MD_CTX was first initialised. Note that
327 where explicit fetch is in use (see L<EVP_MD_fetch(3)>) the value returned from
328 this function will not have its reference count incremented and therefore it
329 should not be used after the EVP_MD_CTX is freed.
330
331 =item EVP_MD_CTX_set_update_fn()
332
333 Sets the update function for I<ctx> to I<update>.
334 This is the function that is called by EVP_DigestUpdate(). If not set, the
335 update function from the B<EVP_MD> type specified at initialization is used.
336
337 =item EVP_MD_CTX_update_fn()
338
339 Returns the update function for I<ctx>.
340
341 =item EVP_MD_flags()
342
343 Returns the I<md> flags. Note that these are different from the B<EVP_MD_CTX>
344 ones. See L<EVP_MD_meth_set_flags(3)> for more information.
345
346 =item EVP_MD_pkey_type()
347
348 Returns the NID of the public key signing algorithm associated with this
349 digest. For example EVP_sha1() is associated with RSA so this will return
350 B<NID_sha1WithRSAEncryption>. Since digests and signature algorithms are no
351 longer linked this function is only retained for compatibility reasons.
352
353 =item EVP_md_null()
354
355 A "null" message digest that does nothing: i.e. the hash it returns is of zero
356 length.
357
358 =item EVP_get_digestbyname(),
359 EVP_get_digestbynid(),
360 EVP_get_digestbyobj()
361
362 Returns an B<EVP_MD> structure when passed a digest name, a digest B<NID> or an
363 B<ASN1_OBJECT> structure respectively.
364
365 =item EVP_MD_CTX_pkey_ctx()
366
367 Returns the B<EVP_PKEY_CTX> assigned to I<ctx>. The returned pointer should not
368 be freed by the caller.
369
370 =item EVP_MD_CTX_set_pkey_ctx()
371
372 Assigns an B<EVP_PKEY_CTX> to B<EVP_MD_CTX>. This is usually used to provide
373 a customized B<EVP_PKEY_CTX> to L<EVP_DigestSignInit(3)> or
374 L<EVP_DigestVerifyInit(3)>. The I<pctx> passed to this function should be freed
375 by the caller. A NULL I<pctx> pointer is also allowed to clear the B<EVP_PKEY_CTX>
376 assigned to I<ctx>. In such case, freeing the cleared B<EVP_PKEY_CTX> or not
377 depends on how the B<EVP_PKEY_CTX> is created.
378
379 =item EVP_MD_do_all_provided()
380
381 Traverses all messages digests implemented by all activated providers
382 in the given library context I<libctx>, and for each of the implementations,
383 calls the given function I<fn> with the implementation method and the given
384 I<arg> as argument.
385
386 =back
387
388 =head1 PARAMETERS
389
390 See L<OSSL_PARAM(3)> for information about passing parameters.
391
392 EVP_MD_CTX_set_params() can be used with the following OSSL_PARAM keys:
393
394 =over 4
395
396 =item "xoflen" (B<OSSL_DIGEST_PARAM_XOFLEN>) <unsigned integer>
397
398 Sets the digest length for extendable output functions.
399 It is used by the SHAKE algorithm and should not exceed what can be given
400 using a B<size_t>.
401
402 =item "pad-type" (B<OSSL_DIGEST_PARAM_PAD_TYPE>) <unsigned integer>
403
404 Sets the padding type.
405 It is used by the MDC2 algorithm.
406
407 =back
408
409 EVP_MD_CTX_get_params() can be used with the following OSSL_PARAM keys:
410
411 =over 4
412
413 =item "micalg" (B<OSSL_PARAM_DIGEST_KEY_MICALG>) <UTF8 string>.
414
415 Gets the digest Message Integrity Check algorithm string. This is used when
416 creating S/MIME multipart/signed messages, as specified in RFC 3851.
417 It may be used by external engines or providers.
418
419 =back
420
421 =head1 CONTROLS
422
423 EVP_MD_CTX_ctrl() can be used to send the following standard controls:
424
425 =over 4
426
427 =item EVP_MD_CTRL_MICALG
428
429 Gets the digest Message Integrity Check algorithm string. This is used when
430 creating S/MIME multipart/signed messages, as specified in RFC 3851.
431 The string value is written to I<p2>.
432
433 When used with a fetched B<EVP_MD>, EVP_MD_CTX_get_params() gets called with
434 an L<OSSL_PARAM(3)> item with the key "micalg" (B<OSSL_DIGEST_PARAM_MICALG>).
435
436 =item EVP_MD_CTRL_XOF_LEN
437
438 This control sets the digest length for extendable output functions to I<p1>.
439 Sending this control directly should not be necessary, the use of
440 EVP_DigestFinalXOF() is preferred.
441 Currently used by SHAKE.
442
443 When used with a fetched B<EVP_MD>, EVP_MD_CTX_get_params() gets called with
444 an L<OSSL_PARAM(3)> item with the key "xoflen" (B<OSSL_DIGEST_PARAM_XOFLEN>).
445
446 =back
447
448 =head1 FLAGS
449
450 EVP_MD_CTX_set_flags(), EVP_MD_CTX_clear_flags() and EVP_MD_CTX_test_flags()
451 can be used the manipulate and test these B<EVP_MD_CTX> flags:
452
453 =over 4
454
455 =item EVP_MD_CTX_FLAG_ONESHOT
456
457 This flag instructs the digest to optimize for one update only, if possible.
458
459 =for comment EVP_MD_CTX_FLAG_CLEANED is internal, don't mention it
460
461 =for comment EVP_MD_CTX_FLAG_REUSE is internal, don't mention it
462
463 =for comment We currently avoid documenting flags that are only bit holder:
464 EVP_MD_CTX_FLAG_NON_FIPS_ALLOW, EVP_MD_CTX_FLAGS_PAD_*
465
466 =item EVP_MD_CTX_FLAG_NO_INIT
467
468 This flag instructs EVP_DigestInit() and similar not to initialise the
469 implementation specific data.
470
471 =item EVP_MD_CTX_FLAG_FINALISE
472
473 Some functions such as EVP_DigestSign only finalise copies of internal
474 contexts so additional data can be included after the finalisation call.
475 This is inefficient if this functionality is not required, and can be
476 disabled with this flag.
477
478 =back
479
480 =head1 RETURN VALUES
481
482 =over 4
483
484 =item EVP_MD_fetch()
485
486 Returns a pointer to a B<EVP_MD> for success or NULL for failure.
487
488 =item EVP_MD_up_ref()
489
490 Returns 1 for success or 0 for failure.
491
492 =item EVP_DigestInit_ex(),
493 EVP_DigestUpdate(),
494 EVP_DigestFinal_ex()
495
496 Returns 1 for
497 success and 0 for failure.
498
499 =item EVP_MD_CTX_ctrl()
500
501 Returns 1 if successful or 0 for failure.
502
503 =item EVP_MD_CTX_set_params(),
504 EVP_MD_CTX_get_params()
505
506 Returns 1 if successful or 0 for failure.
507
508 =item EVP_MD_CTX_settable_params(),
509 EVP_MD_CTX_gettable_params()
510
511 Return an array of constant B<OSSL_PARAM>s, or NULL if there is none
512 to get.
513
514 =item EVP_MD_CTX_copy_ex()
515
516 Returns 1 if successful or 0 for failure.
517
518 =item EVP_MD_type(),
519 EVP_MD_pkey_type()
520
521 Returns the NID of the corresponding OBJECT IDENTIFIER or NID_undef if none
522 exists.
523
524 =item EVP_MD_size(),
525 EVP_MD_block_size(),
526 EVP_MD_CTX_size(),
527 EVP_MD_CTX_block_size()
528
529 Returns the digest or block size in bytes.
530
531 =item EVP_md_null()
532
533 Returns a pointer to the B<EVP_MD> structure of the "null" message digest.
534
535 =item EVP_get_digestbyname(),
536 EVP_get_digestbynid(),
537 EVP_get_digestbyobj()
538
539 Returns either an B<EVP_MD> structure or NULL if an error occurs.
540
541 =item EVP_MD_CTX_set_pkey_ctx()
542
543 This function has no return value.
544
545 =back
546
547 =head1 NOTES
548
549 The B<EVP> interface to message digests should almost always be used in
550 preference to the low-level interfaces. This is because the code then becomes
551 transparent to the digest used and much more flexible.
552
553 New applications should use the SHA-2 (such as L<EVP_sha256(3)>) or the SHA-3
554 digest algorithms (such as L<EVP_sha3_512(3)>). The other digest algorithms
555 are still in common use.
556
557 For most applications the I<impl> parameter to EVP_DigestInit_ex() will be
558 set to NULL to use the default digest implementation.
559
560 The functions EVP_DigestInit(), EVP_DigestFinal() and EVP_MD_CTX_copy() are
561 obsolete but are retained to maintain compatibility with existing code. New
562 applications should use EVP_DigestInit_ex(), EVP_DigestFinal_ex() and
563 EVP_MD_CTX_copy_ex() because they can efficiently reuse a digest context
564 instead of initializing and cleaning it up on each call and allow non default
565 implementations of digests to be specified.
566
567 If digest contexts are not cleaned up after use,
568 memory leaks will occur.
569
570 EVP_MD_CTX_name(), EVP_MD_CTX_size(), EVP_MD_CTX_block_size(),
571 EVP_MD_CTX_type(), EVP_get_digestbynid() and EVP_get_digestbyobj() are defined
572 as macros.
573
574 EVP_MD_CTX_ctrl() sends commands to message digests for additional configuration
575 or control.
576
577 =head1 EXAMPLES
578
579 This example digests the data "Test Message\n" and "Hello World\n", using the
580 digest name passed on the command line.
581
582  #include <stdio.h>
583  #include <string.h>
584  #include <openssl/evp.h>
585
586  int main(int argc, char *argv[])
587  {
588      EVP_MD_CTX *mdctx;
589      const EVP_MD *md;
590      char mess1[] = "Test Message\n";
591      char mess2[] = "Hello World\n";
592      unsigned char md_value[EVP_MAX_MD_SIZE];
593      unsigned int md_len, i;
594
595      if (argv[1] == NULL) {
596          printf("Usage: mdtest digestname\n");
597          exit(1);
598      }
599
600      md = EVP_get_digestbyname(argv[1]);
601      if (md == NULL) {
602          printf("Unknown message digest %s\n", argv[1]);
603          exit(1);
604      }
605
606      mdctx = EVP_MD_CTX_new();
607      EVP_DigestInit_ex(mdctx, md, NULL);
608      EVP_DigestUpdate(mdctx, mess1, strlen(mess1));
609      EVP_DigestUpdate(mdctx, mess2, strlen(mess2));
610      EVP_DigestFinal_ex(mdctx, md_value, &md_len);
611      EVP_MD_CTX_free(mdctx);
612
613      printf("Digest is: ");
614      for (i = 0; i < md_len; i++)
615          printf("%02x", md_value[i]);
616      printf("\n");
617
618      exit(0);
619  }
620
621 =head1 SEE ALSO
622
623 L<EVP_MD_meth_new(3)>,
624 L<openssl-dgst(1)>,
625 L<evp(7)>,
626 L<OSSL_PROVIDER(3)>,
627 L<OSSL_PARAM(3)>
628
629 The full list of digest algorithms are provided below.
630
631 L<EVP_blake2b512(3)>,
632 L<EVP_md2(3)>,
633 L<EVP_md4(3)>,
634 L<EVP_md5(3)>,
635 L<EVP_mdc2(3)>,
636 L<EVP_ripemd160(3)>,
637 L<EVP_sha1(3)>,
638 L<EVP_sha224(3)>,
639 L<EVP_sha3_224(3)>,
640 L<EVP_sm3(3)>,
641 L<EVP_whirlpool(3)>
642 L<provider(7)/Fetching algorithms>
643
644 =head1 HISTORY
645
646 The EVP_MD_CTX_create() and EVP_MD_CTX_destroy() functions were renamed to
647 EVP_MD_CTX_new() and EVP_MD_CTX_free() in OpenSSL 1.1.0, respectively.
648
649 The link between digests and signing algorithms was fixed in OpenSSL 1.0 and
650 later, so now EVP_sha1() can be used with RSA and DSA.
651
652 The EVP_dss1() function was removed in OpenSSL 1.1.0.
653
654 The EVP_MD_CTX_set_pkey_ctx() function was added in OpenSSL 1.1.1.
655
656 The EVP_MD_fetch(), EVP_MD_free(), EVP_MD_up_ref(), EVP_MD_CTX_set_params()
657 and EVP_MD_CTX_get_params() functions were added in OpenSSL 3.0.
658 The EVP_MD_CTX_update_fn() and EVP_MD_CTX_set_update_fn() were deprecated
659 in OpenSSL 3.0.
660
661 =head1 COPYRIGHT
662
663 Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved.
664
665 Licensed under the Apache License 2.0 (the "License").  You may not use
666 this file except in compliance with the License.  You can obtain a copy
667 in the file LICENSE in the source distribution or at
668 L<https://www.openssl.org/source/license.html>.
669
670 =cut