xref: /netbsd-src/crypto/external/bsd/openssl.old/dist/doc/man3/EVP_DigestInit.pod (revision 4724848cf0da353df257f730694b7882798e5daf)
1*4724848cSchristos=pod
2*4724848cSchristos
3*4724848cSchristos=head1 NAME
4*4724848cSchristos
5*4724848cSchristosEVP_MD_CTX_new, EVP_MD_CTX_reset, EVP_MD_CTX_free, EVP_MD_CTX_copy,
6*4724848cSchristosEVP_MD_CTX_copy_ex, EVP_MD_CTX_ctrl, EVP_MD_CTX_set_flags,
7*4724848cSchristosEVP_MD_CTX_clear_flags, EVP_MD_CTX_test_flags,
8*4724848cSchristosEVP_Digest, EVP_DigestInit_ex, EVP_DigestInit, EVP_DigestUpdate,
9*4724848cSchristosEVP_DigestFinal_ex, EVP_DigestFinalXOF, EVP_DigestFinal,
10*4724848cSchristosEVP_MD_type, EVP_MD_pkey_type, EVP_MD_size, EVP_MD_block_size, EVP_MD_flags,
11*4724848cSchristosEVP_MD_CTX_md, EVP_MD_CTX_type, EVP_MD_CTX_size, EVP_MD_CTX_block_size,
12*4724848cSchristosEVP_MD_CTX_md_data, EVP_MD_CTX_update_fn, EVP_MD_CTX_set_update_fn,
13*4724848cSchristosEVP_md_null,
14*4724848cSchristosEVP_get_digestbyname, EVP_get_digestbynid, EVP_get_digestbyobj,
15*4724848cSchristosEVP_MD_CTX_pkey_ctx, EVP_MD_CTX_set_pkey_ctx - EVP digest routines
16*4724848cSchristos
17*4724848cSchristos=head1 SYNOPSIS
18*4724848cSchristos
19*4724848cSchristos #include <openssl/evp.h>
20*4724848cSchristos
21*4724848cSchristos EVP_MD_CTX *EVP_MD_CTX_new(void);
22*4724848cSchristos int EVP_MD_CTX_reset(EVP_MD_CTX *ctx);
23*4724848cSchristos void EVP_MD_CTX_free(EVP_MD_CTX *ctx);
24*4724848cSchristos void EVP_MD_CTX_ctrl(EVP_MD_CTX *ctx, int cmd, int p1, void* p2);
25*4724848cSchristos void EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags);
26*4724848cSchristos void EVP_MD_CTX_clear_flags(EVP_MD_CTX *ctx, int flags);
27*4724848cSchristos int EVP_MD_CTX_test_flags(const EVP_MD_CTX *ctx, int flags);
28*4724848cSchristos
29*4724848cSchristos int EVP_Digest(const void *data, size_t count, unsigned char *md,
30*4724848cSchristos                unsigned int *size, const EVP_MD *type, ENGINE *impl);
31*4724848cSchristos int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl);
32*4724848cSchristos int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *d, size_t cnt);
33*4724848cSchristos int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *s);
34*4724848cSchristos int EVP_DigestFinalXOF(EVP_MD_CTX *ctx, unsigned char *md, size_t len);
35*4724848cSchristos
36*4724848cSchristos int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in);
37*4724848cSchristos
38*4724848cSchristos int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type);
39*4724848cSchristos int EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *s);
40*4724848cSchristos
41*4724848cSchristos int EVP_MD_CTX_copy(EVP_MD_CTX *out, EVP_MD_CTX *in);
42*4724848cSchristos
43*4724848cSchristos int EVP_MD_type(const EVP_MD *md);
44*4724848cSchristos int EVP_MD_pkey_type(const EVP_MD *md);
45*4724848cSchristos int EVP_MD_size(const EVP_MD *md);
46*4724848cSchristos int EVP_MD_block_size(const EVP_MD *md);
47*4724848cSchristos unsigned long EVP_MD_flags(const EVP_MD *md);
48*4724848cSchristos
49*4724848cSchristos const EVP_MD *EVP_MD_CTX_md(const EVP_MD_CTX *ctx);
50*4724848cSchristos int EVP_MD_CTX_size(const EVP_MD_CTX *ctx);
51*4724848cSchristos int EVP_MD_CTX_block_size(const EVP_MD_CTX *ctx);
52*4724848cSchristos int EVP_MD_CTX_type(const EVP_MD_CTX *ctx);
53*4724848cSchristos void *EVP_MD_CTX_md_data(const EVP_MD_CTX *ctx);
54*4724848cSchristos int (*EVP_MD_CTX_update_fn(EVP_MD_CTX *ctx))(EVP_MD_CTX *ctx,
55*4724848cSchristos                                              const void *data, size_t count);
56*4724848cSchristos void EVP_MD_CTX_set_update_fn(EVP_MD_CTX *ctx,
57*4724848cSchristos                               int (*update)(EVP_MD_CTX *ctx,
58*4724848cSchristos                                             const void *data, size_t count));
59*4724848cSchristos
60*4724848cSchristos const EVP_MD *EVP_md_null(void);
61*4724848cSchristos
62*4724848cSchristos const EVP_MD *EVP_get_digestbyname(const char *name);
63*4724848cSchristos const EVP_MD *EVP_get_digestbynid(int type);
64*4724848cSchristos const EVP_MD *EVP_get_digestbyobj(const ASN1_OBJECT *o);
65*4724848cSchristos
66*4724848cSchristos EVP_PKEY_CTX *EVP_MD_CTX_pkey_ctx(const EVP_MD_CTX *ctx);
67*4724848cSchristos void EVP_MD_CTX_set_pkey_ctx(EVP_MD_CTX *ctx, EVP_PKEY_CTX *pctx);
68*4724848cSchristos
69*4724848cSchristos=head1 DESCRIPTION
70*4724848cSchristos
71*4724848cSchristosThe EVP digest routines are a high-level interface to message digests,
72*4724848cSchristosand should be used instead of the cipher-specific functions.
73*4724848cSchristos
74*4724848cSchristos=over 4
75*4724848cSchristos
76*4724848cSchristos=item EVP_MD_CTX_new()
77*4724848cSchristos
78*4724848cSchristosAllocates and returns a digest context.
79*4724848cSchristos
80*4724848cSchristos=item EVP_MD_CTX_reset()
81*4724848cSchristos
82*4724848cSchristosResets the digest context B<ctx>.  This can be used to reuse an already
83*4724848cSchristosexisting context.
84*4724848cSchristos
85*4724848cSchristos=item EVP_MD_CTX_free()
86*4724848cSchristos
87*4724848cSchristosCleans up digest context B<ctx> and frees up the space allocated to it.
88*4724848cSchristos
89*4724848cSchristos=item EVP_MD_CTX_ctrl()
90*4724848cSchristos
91*4724848cSchristosPerforms digest-specific control actions on context B<ctx>. The control command
92*4724848cSchristosis indicated in B<cmd> and any additional arguments in B<p1> and B<p2>.
93*4724848cSchristosEVP_MD_CTX_ctrl() must be called after EVP_DigestInit_ex(). Other restrictions
94*4724848cSchristosmay apply depending on the control type and digest implementation.
95*4724848cSchristosSee L</CONTROLS> below for more information.
96*4724848cSchristos
97*4724848cSchristos=item EVP_MD_CTX_set_flags(), EVP_MD_CTX_clear_flags(), EVP_MD_CTX_test_flags()
98*4724848cSchristos
99*4724848cSchristosSets, clears and tests B<ctx> flags.  See L</FLAGS> below for more information.
100*4724848cSchristos
101*4724848cSchristos=item EVP_Digest()
102*4724848cSchristos
103*4724848cSchristosA wrapper around the Digest Init_ex, Update and Final_ex functions.
104*4724848cSchristosHashes B<count> bytes of data at B<data> using a digest B<type> from ENGINE
105*4724848cSchristosB<impl>. The digest value is placed in B<md> and its length is written at B<size>
106*4724848cSchristosif the pointer is not NULL. At most B<EVP_MAX_MD_SIZE> bytes will be written.
107*4724848cSchristosIf B<impl> is NULL the default implementation of digest B<type> is used.
108*4724848cSchristos
109*4724848cSchristos=item EVP_DigestInit_ex()
110*4724848cSchristos
111*4724848cSchristosSets up digest context B<ctx> to use a digest B<type> from ENGINE B<impl>.
112*4724848cSchristosB<type> will typically be supplied by a function such as EVP_sha1().  If
113*4724848cSchristosB<impl> is NULL then the default implementation of digest B<type> is used.
114*4724848cSchristos
115*4724848cSchristos=item EVP_DigestUpdate()
116*4724848cSchristos
117*4724848cSchristosHashes B<cnt> bytes of data at B<d> into the digest context B<ctx>. This
118*4724848cSchristosfunction can be called several times on the same B<ctx> to hash additional
119*4724848cSchristosdata.
120*4724848cSchristos
121*4724848cSchristos=item EVP_DigestFinal_ex()
122*4724848cSchristos
123*4724848cSchristosRetrieves the digest value from B<ctx> and places it in B<md>. If the B<s>
124*4724848cSchristosparameter is not NULL then the number of bytes of data written (i.e. the
125*4724848cSchristoslength of the digest) will be written to the integer at B<s>, at most
126*4724848cSchristosB<EVP_MAX_MD_SIZE> bytes will be written.  After calling EVP_DigestFinal_ex()
127*4724848cSchristosno additional calls to EVP_DigestUpdate() can be made, but
128*4724848cSchristosEVP_DigestInit_ex() can be called to initialize a new digest operation.
129*4724848cSchristos
130*4724848cSchristos=item EVP_DigestFinalXOF()
131*4724848cSchristos
132*4724848cSchristosInterfaces to extendable-output functions, XOFs, such as SHAKE128 and SHAKE256.
133*4724848cSchristosIt retrieves the digest value from B<ctx> and places it in B<len>-sized <B>md.
134*4724848cSchristosAfter calling this function no additional calls to EVP_DigestUpdate() can be
135*4724848cSchristosmade, but EVP_DigestInit_ex() can be called to initialize a new operation.
136*4724848cSchristos
137*4724848cSchristos=item EVP_MD_CTX_copy_ex()
138*4724848cSchristos
139*4724848cSchristosCan be used to copy the message digest state from B<in> to B<out>. This is
140*4724848cSchristosuseful if large amounts of data are to be hashed which only differ in the last
141*4724848cSchristosfew bytes.
142*4724848cSchristos
143*4724848cSchristos=item EVP_DigestInit()
144*4724848cSchristos
145*4724848cSchristosBehaves in the same way as EVP_DigestInit_ex() except it always uses the
146*4724848cSchristosdefault digest implementation and calls EVP_MD_CTX_reset().
147*4724848cSchristos
148*4724848cSchristos=item EVP_DigestFinal()
149*4724848cSchristos
150*4724848cSchristosSimilar to EVP_DigestFinal_ex() except the digest context B<ctx> is
151*4724848cSchristosautomatically cleaned up.
152*4724848cSchristos
153*4724848cSchristos=item EVP_MD_CTX_copy()
154*4724848cSchristos
155*4724848cSchristosSimilar to EVP_MD_CTX_copy_ex() except the destination B<out> does not have to
156*4724848cSchristosbe initialized.
157*4724848cSchristos
158*4724848cSchristos=item EVP_MD_size(),
159*4724848cSchristosEVP_MD_CTX_size()
160*4724848cSchristos
161*4724848cSchristosReturn the size of the message digest when passed an B<EVP_MD> or an
162*4724848cSchristosB<EVP_MD_CTX> structure, i.e. the size of the hash.
163*4724848cSchristos
164*4724848cSchristos=item EVP_MD_block_size(),
165*4724848cSchristosEVP_MD_CTX_block_size()
166*4724848cSchristos
167*4724848cSchristosReturn the block size of the message digest when passed an B<EVP_MD> or an
168*4724848cSchristosB<EVP_MD_CTX> structure.
169*4724848cSchristos
170*4724848cSchristos=item EVP_MD_type(),
171*4724848cSchristosEVP_MD_CTX_type()
172*4724848cSchristos
173*4724848cSchristosReturn the NID of the OBJECT IDENTIFIER representing the given message digest
174*4724848cSchristoswhen passed an B<EVP_MD> structure.  For example, C<EVP_MD_type(EVP_sha1())>
175*4724848cSchristosreturns B<NID_sha1>. This function is normally used when setting ASN1 OIDs.
176*4724848cSchristos
177*4724848cSchristos=item EVP_MD_CTX_md_data()
178*4724848cSchristos
179*4724848cSchristosReturn the digest method private data for the passed B<EVP_MD_CTX>.
180*4724848cSchristosThe space is allocated by OpenSSL and has the size originally set with
181*4724848cSchristosEVP_MD_meth_set_app_datasize().
182*4724848cSchristos
183*4724848cSchristos=item EVP_MD_CTX_md()
184*4724848cSchristos
185*4724848cSchristosReturns the B<EVP_MD> structure corresponding to the passed B<EVP_MD_CTX>.
186*4724848cSchristos
187*4724848cSchristos=item EVP_MD_CTX_set_update_fn()
188*4724848cSchristos
189*4724848cSchristosSets the update function for B<ctx> to B<update>.
190*4724848cSchristosThis is the function that is called by EVP_DigestUpdate. If not set, the
191*4724848cSchristosupdate function from the B<EVP_MD> type specified at initialization is used.
192*4724848cSchristos
193*4724848cSchristos=item EVP_MD_CTX_update_fn()
194*4724848cSchristos
195*4724848cSchristosReturns the update function for B<ctx>.
196*4724848cSchristos
197*4724848cSchristos=item EVP_MD_flags()
198*4724848cSchristos
199*4724848cSchristosReturns the B<md> flags. Note that these are different from the B<EVP_MD_CTX>
200*4724848cSchristosones. See L<EVP_MD_meth_set_flags(3)> for more information.
201*4724848cSchristos
202*4724848cSchristos=item EVP_MD_pkey_type()
203*4724848cSchristos
204*4724848cSchristosReturns the NID of the public key signing algorithm associated with this
205*4724848cSchristosdigest. For example EVP_sha1() is associated with RSA so this will return
206*4724848cSchristosB<NID_sha1WithRSAEncryption>. Since digests and signature algorithms are no
207*4724848cSchristoslonger linked this function is only retained for compatibility reasons.
208*4724848cSchristos
209*4724848cSchristos=item EVP_md_null()
210*4724848cSchristos
211*4724848cSchristosA "null" message digest that does nothing: i.e. the hash it returns is of zero
212*4724848cSchristoslength.
213*4724848cSchristos
214*4724848cSchristos=item EVP_get_digestbyname(),
215*4724848cSchristosEVP_get_digestbynid(),
216*4724848cSchristosEVP_get_digestbyobj()
217*4724848cSchristos
218*4724848cSchristosReturns an B<EVP_MD> structure when passed a digest name, a digest B<NID> or an
219*4724848cSchristosB<ASN1_OBJECT> structure respectively.
220*4724848cSchristos
221*4724848cSchristos=item EVP_MD_CTX_pkey_ctx()
222*4724848cSchristos
223*4724848cSchristosReturns the B<EVP_PKEY_CTX> assigned to B<ctx>. The returned pointer should not
224*4724848cSchristosbe freed by the caller.
225*4724848cSchristos
226*4724848cSchristos=item EVP_MD_CTX_set_pkey_ctx()
227*4724848cSchristos
228*4724848cSchristosAssigns an B<EVP_PKEY_CTX> to B<EVP_MD_CTX>. This is usually used to provide
229*4724848cSchristosa customized B<EVP_PKEY_CTX> to L<EVP_DigestSignInit(3)> or
230*4724848cSchristosL<EVP_DigestVerifyInit(3)>. The B<pctx> passed to this function should be freed
231*4724848cSchristosby the caller. A NULL B<pctx> pointer is also allowed to clear the B<EVP_PKEY_CTX>
232*4724848cSchristosassigned to B<ctx>. In such case, freeing the cleared B<EVP_PKEY_CTX> or not
233*4724848cSchristosdepends on how the B<EVP_PKEY_CTX> is created.
234*4724848cSchristos
235*4724848cSchristos=back
236*4724848cSchristos
237*4724848cSchristos=head1 CONTROLS
238*4724848cSchristos
239*4724848cSchristosEVP_MD_CTX_ctrl() can be used to send the following standard controls:
240*4724848cSchristos
241*4724848cSchristos=over 4
242*4724848cSchristos
243*4724848cSchristos=item EVP_MD_CTRL_MICALG
244*4724848cSchristos
245*4724848cSchristosGets the digest Message Integrity Check algorithm string. This is used when
246*4724848cSchristoscreating S/MIME multipart/signed messages, as specified in RFC 3851.
247*4724848cSchristosThe string value is written to B<p2>.
248*4724848cSchristos
249*4724848cSchristos=item EVP_MD_CTRL_XOF_LEN
250*4724848cSchristos
251*4724848cSchristosThis control sets the digest length for extendable output functions to B<p1>.
252*4724848cSchristosSending this control directly should not be necessary, the use of
253*4724848cSchristosC<EVP_DigestFinalXOF()> is preferred.
254*4724848cSchristosCurrently used by SHAKE.
255*4724848cSchristos
256*4724848cSchristos=back
257*4724848cSchristos
258*4724848cSchristos=head1 FLAGS
259*4724848cSchristos
260*4724848cSchristosEVP_MD_CTX_set_flags(), EVP_MD_CTX_clear_flags() and EVP_MD_CTX_test_flags()
261*4724848cSchristoscan be used the manipulate and test these B<EVP_MD_CTX> flags:
262*4724848cSchristos
263*4724848cSchristos=over 4
264*4724848cSchristos
265*4724848cSchristos=item EVP_MD_CTX_FLAG_ONESHOT
266*4724848cSchristos
267*4724848cSchristosThis flag instructs the digest to optimize for one update only, if possible.
268*4724848cSchristos
269*4724848cSchristos=for comment EVP_MD_CTX_FLAG_CLEANED is internal, don't mention it
270*4724848cSchristos
271*4724848cSchristos=for comment EVP_MD_CTX_FLAG_REUSE is internal, don't mention it
272*4724848cSchristos
273*4724848cSchristos=for comment We currently avoid documenting flags that are only bit holder:
274*4724848cSchristosEVP_MD_CTX_FLAG_NON_FIPS_ALLOW, EVP_MD_CTX_FLAGS_PAD_*
275*4724848cSchristos
276*4724848cSchristos=item EVP_MD_CTX_FLAG_NO_INIT
277*4724848cSchristos
278*4724848cSchristosThis flag instructs EVP_DigestInit() and similar not to initialise the
279*4724848cSchristosimplementation specific data.
280*4724848cSchristos
281*4724848cSchristos=item EVP_MD_CTX_FLAG_FINALISE
282*4724848cSchristos
283*4724848cSchristosSome functions such as EVP_DigestSign only finalise copies of internal
284*4724848cSchristoscontexts so additional data can be included after the finalisation call.
285*4724848cSchristosThis is inefficient if this functionality is not required, and can be
286*4724848cSchristosdisabled with this flag.
287*4724848cSchristos
288*4724848cSchristos=back
289*4724848cSchristos
290*4724848cSchristos=head1 RETURN VALUES
291*4724848cSchristos
292*4724848cSchristos=over 4
293*4724848cSchristos
294*4724848cSchristos=item EVP_DigestInit_ex(),
295*4724848cSchristosEVP_DigestUpdate(),
296*4724848cSchristosEVP_DigestFinal_ex()
297*4724848cSchristos
298*4724848cSchristosReturns 1 for
299*4724848cSchristossuccess and 0 for failure.
300*4724848cSchristos
301*4724848cSchristos=item EVP_MD_CTX_ctrl()
302*4724848cSchristos
303*4724848cSchristosReturns 1 if successful or 0 for failure.
304*4724848cSchristos
305*4724848cSchristos=item EVP_MD_CTX_copy_ex()
306*4724848cSchristos
307*4724848cSchristosReturns 1 if successful or 0 for failure.
308*4724848cSchristos
309*4724848cSchristos=item EVP_MD_type(),
310*4724848cSchristosEVP_MD_pkey_type()
311*4724848cSchristos
312*4724848cSchristosReturns the NID of the corresponding OBJECT IDENTIFIER or NID_undef if none
313*4724848cSchristosexists.
314*4724848cSchristos
315*4724848cSchristos=item EVP_MD_size(),
316*4724848cSchristosEVP_MD_block_size(),
317*4724848cSchristosEVP_MD_CTX_size(),
318*4724848cSchristosEVP_MD_CTX_block_size()
319*4724848cSchristos
320*4724848cSchristosReturns the digest or block size in bytes.
321*4724848cSchristos
322*4724848cSchristos=item EVP_md_null()
323*4724848cSchristos
324*4724848cSchristosReturns a pointer to the B<EVP_MD> structure of the "null" message digest.
325*4724848cSchristos
326*4724848cSchristos=item EVP_get_digestbyname(),
327*4724848cSchristosEVP_get_digestbynid(),
328*4724848cSchristosEVP_get_digestbyobj()
329*4724848cSchristos
330*4724848cSchristosReturns either an B<EVP_MD> structure or NULL if an error occurs.
331*4724848cSchristos
332*4724848cSchristos=item EVP_MD_CTX_set_pkey_ctx()
333*4724848cSchristos
334*4724848cSchristosThis function has no return value.
335*4724848cSchristos
336*4724848cSchristos=back
337*4724848cSchristos
338*4724848cSchristos=head1 NOTES
339*4724848cSchristos
340*4724848cSchristosThe B<EVP> interface to message digests should almost always be used in
341*4724848cSchristospreference to the low-level interfaces. This is because the code then becomes
342*4724848cSchristostransparent to the digest used and much more flexible.
343*4724848cSchristos
344*4724848cSchristosNew applications should use the SHA-2 (such as L<EVP_sha256(3)>) or the SHA-3
345*4724848cSchristosdigest algorithms (such as L<EVP_sha3_512(3)>). The other digest algorithms
346*4724848cSchristosare still in common use.
347*4724848cSchristos
348*4724848cSchristosFor most applications the B<impl> parameter to EVP_DigestInit_ex() will be
349*4724848cSchristosset to NULL to use the default digest implementation.
350*4724848cSchristos
351*4724848cSchristosThe functions EVP_DigestInit(), EVP_DigestFinal() and EVP_MD_CTX_copy() are
352*4724848cSchristosobsolete but are retained to maintain compatibility with existing code. New
353*4724848cSchristosapplications should use EVP_DigestInit_ex(), EVP_DigestFinal_ex() and
354*4724848cSchristosEVP_MD_CTX_copy_ex() because they can efficiently reuse a digest context
355*4724848cSchristosinstead of initializing and cleaning it up on each call and allow non default
356*4724848cSchristosimplementations of digests to be specified.
357*4724848cSchristos
358*4724848cSchristosIf digest contexts are not cleaned up after use,
359*4724848cSchristosmemory leaks will occur.
360*4724848cSchristos
361*4724848cSchristosEVP_MD_CTX_size(), EVP_MD_CTX_block_size(), EVP_MD_CTX_type(),
362*4724848cSchristosEVP_get_digestbynid() and EVP_get_digestbyobj() are defined as
363*4724848cSchristosmacros.
364*4724848cSchristos
365*4724848cSchristosEVP_MD_CTX_ctrl() sends commands to message digests for additional configuration
366*4724848cSchristosor control.
367*4724848cSchristos
368*4724848cSchristos=head1 EXAMPLES
369*4724848cSchristos
370*4724848cSchristosThis example digests the data "Test Message\n" and "Hello World\n", using the
371*4724848cSchristosdigest name passed on the command line.
372*4724848cSchristos
373*4724848cSchristos #include <stdio.h>
374*4724848cSchristos #include <string.h>
375*4724848cSchristos #include <openssl/evp.h>
376*4724848cSchristos
377*4724848cSchristos int main(int argc, char *argv[])
378*4724848cSchristos {
379*4724848cSchristos     EVP_MD_CTX *mdctx;
380*4724848cSchristos     const EVP_MD *md;
381*4724848cSchristos     char mess1[] = "Test Message\n";
382*4724848cSchristos     char mess2[] = "Hello World\n";
383*4724848cSchristos     unsigned char md_value[EVP_MAX_MD_SIZE];
384*4724848cSchristos     unsigned int md_len, i;
385*4724848cSchristos
386*4724848cSchristos     if (argv[1] == NULL) {
387*4724848cSchristos         printf("Usage: mdtest digestname\n");
388*4724848cSchristos         exit(1);
389*4724848cSchristos     }
390*4724848cSchristos
391*4724848cSchristos     md = EVP_get_digestbyname(argv[1]);
392*4724848cSchristos     if (md == NULL) {
393*4724848cSchristos         printf("Unknown message digest %s\n", argv[1]);
394*4724848cSchristos         exit(1);
395*4724848cSchristos     }
396*4724848cSchristos
397*4724848cSchristos     mdctx = EVP_MD_CTX_new();
398*4724848cSchristos     EVP_DigestInit_ex(mdctx, md, NULL);
399*4724848cSchristos     EVP_DigestUpdate(mdctx, mess1, strlen(mess1));
400*4724848cSchristos     EVP_DigestUpdate(mdctx, mess2, strlen(mess2));
401*4724848cSchristos     EVP_DigestFinal_ex(mdctx, md_value, &md_len);
402*4724848cSchristos     EVP_MD_CTX_free(mdctx);
403*4724848cSchristos
404*4724848cSchristos     printf("Digest is: ");
405*4724848cSchristos     for (i = 0; i < md_len; i++)
406*4724848cSchristos         printf("%02x", md_value[i]);
407*4724848cSchristos     printf("\n");
408*4724848cSchristos
409*4724848cSchristos     exit(0);
410*4724848cSchristos }
411*4724848cSchristos
412*4724848cSchristos=head1 SEE ALSO
413*4724848cSchristos
414*4724848cSchristosL<EVP_MD_meth_new(3)>,
415*4724848cSchristosL<dgst(1)>,
416*4724848cSchristosL<evp(7)>
417*4724848cSchristos
418*4724848cSchristosThe full list of digest algorithms are provided below.
419*4724848cSchristos
420*4724848cSchristosL<EVP_blake2b512(3)>,
421*4724848cSchristosL<EVP_md2(3)>,
422*4724848cSchristosL<EVP_md4(3)>,
423*4724848cSchristosL<EVP_md5(3)>,
424*4724848cSchristosL<EVP_mdc2(3)>,
425*4724848cSchristosL<EVP_ripemd160(3)>,
426*4724848cSchristosL<EVP_sha1(3)>,
427*4724848cSchristosL<EVP_sha224(3)>,
428*4724848cSchristosL<EVP_sha3_224(3)>,
429*4724848cSchristosL<EVP_sm3(3)>,
430*4724848cSchristosL<EVP_whirlpool(3)>
431*4724848cSchristos
432*4724848cSchristos=head1 HISTORY
433*4724848cSchristos
434*4724848cSchristosThe EVP_MD_CTX_create() and EVP_MD_CTX_destroy() functions were renamed to
435*4724848cSchristosEVP_MD_CTX_new() and EVP_MD_CTX_free() in OpenSSL 1.1.0, respectively.
436*4724848cSchristos
437*4724848cSchristosThe link between digests and signing algorithms was fixed in OpenSSL 1.0 and
438*4724848cSchristoslater, so now EVP_sha1() can be used with RSA and DSA.
439*4724848cSchristos
440*4724848cSchristosThe EVP_dss1() function was removed in OpenSSL 1.1.0.
441*4724848cSchristos
442*4724848cSchristosThe EVP_MD_CTX_set_pkey_ctx() function was added in 1.1.1.
443*4724848cSchristos
444*4724848cSchristos=head1 COPYRIGHT
445*4724848cSchristos
446*4724848cSchristosCopyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved.
447*4724848cSchristos
448*4724848cSchristosLicensed under the OpenSSL license (the "License").  You may not use
449*4724848cSchristosthis file except in compliance with the License.  You can obtain a copy
450*4724848cSchristosin the file LICENSE in the source distribution or at
451*4724848cSchristosL<https://www.openssl.org/source/license.html>.
452*4724848cSchristos
453*4724848cSchristos=cut
454