VirtualBox

source: vbox/trunk/src/libs/openssl-3.1.3/doc/man3/EVP_DigestInit.pod@ 102459

最後變更 在這個檔案從102459是 101211,由 vboxsync 提交於 17 月 前

openssl-3.1.3: Applied and adjusted our OpenSSL changes to 3.1.2. bugref:10527

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette