xref: /freebsd/crypto/openssl/doc/man3/EVP_DigestInit.pod (revision da327cd22e88f26f6cab9d4c45805b512139aa11)
1e71b7053SJung-uk Kim=pod
2e71b7053SJung-uk Kim
3e71b7053SJung-uk Kim=head1 NAME
4e71b7053SJung-uk Kim
5e71b7053SJung-uk KimEVP_MD_CTX_new, EVP_MD_CTX_reset, EVP_MD_CTX_free, EVP_MD_CTX_copy_ex,
6e71b7053SJung-uk KimEVP_MD_CTX_ctrl, EVP_MD_CTX_set_flags, EVP_MD_CTX_clear_flags,
7e71b7053SJung-uk KimEVP_MD_CTX_test_flags, EVP_DigestInit_ex, EVP_DigestInit, EVP_DigestUpdate,
8e71b7053SJung-uk KimEVP_DigestFinal_ex, EVP_DigestFinalXOF, EVP_DigestFinal,
9e71b7053SJung-uk KimEVP_MD_CTX_copy, EVP_MD_type, EVP_MD_pkey_type, EVP_MD_size,
10e71b7053SJung-uk KimEVP_MD_block_size, EVP_MD_CTX_md, EVP_MD_CTX_size,
11e71b7053SJung-uk KimEVP_MD_CTX_block_size, EVP_MD_CTX_type, EVP_MD_CTX_md_data,
12e71b7053SJung-uk KimEVP_md_null,
13e71b7053SJung-uk KimEVP_get_digestbyname, EVP_get_digestbynid,
14e71b7053SJung-uk KimEVP_get_digestbyobj,
15e71b7053SJung-uk KimEVP_MD_CTX_set_pkey_ctx - EVP digest routines
16e71b7053SJung-uk Kim
17e71b7053SJung-uk Kim=head1 SYNOPSIS
18e71b7053SJung-uk Kim
19e71b7053SJung-uk Kim #include <openssl/evp.h>
20e71b7053SJung-uk Kim
21e71b7053SJung-uk Kim EVP_MD_CTX *EVP_MD_CTX_new(void);
22e71b7053SJung-uk Kim int EVP_MD_CTX_reset(EVP_MD_CTX *ctx);
23e71b7053SJung-uk Kim void EVP_MD_CTX_free(EVP_MD_CTX *ctx);
24e71b7053SJung-uk Kim void EVP_MD_CTX_ctrl(EVP_MD_CTX *ctx, int cmd, int p1, void* p2);
25e71b7053SJung-uk Kim void EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags);
26e71b7053SJung-uk Kim void EVP_MD_CTX_clear_flags(EVP_MD_CTX *ctx, int flags);
27e71b7053SJung-uk Kim int EVP_MD_CTX_test_flags(const EVP_MD_CTX *ctx, int flags);
28e71b7053SJung-uk Kim
29e71b7053SJung-uk Kim int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl);
30e71b7053SJung-uk Kim int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *d, size_t cnt);
31e71b7053SJung-uk Kim int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *s);
32e71b7053SJung-uk Kim int EVP_DigestFinalXOF(EVP_MD_CTX *ctx, unsigned char *md, size_t len);
33e71b7053SJung-uk Kim
34e71b7053SJung-uk Kim int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in);
35e71b7053SJung-uk Kim
36e71b7053SJung-uk Kim int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type);
37e71b7053SJung-uk Kim int EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *s);
38e71b7053SJung-uk Kim
39e71b7053SJung-uk Kim int EVP_MD_CTX_copy(EVP_MD_CTX *out, EVP_MD_CTX *in);
40e71b7053SJung-uk Kim
41e71b7053SJung-uk Kim int EVP_MD_type(const EVP_MD *md);
42e71b7053SJung-uk Kim int EVP_MD_pkey_type(const EVP_MD *md);
43e71b7053SJung-uk Kim int EVP_MD_size(const EVP_MD *md);
44e71b7053SJung-uk Kim int EVP_MD_block_size(const EVP_MD *md);
45e71b7053SJung-uk Kim
46e71b7053SJung-uk Kim const EVP_MD *EVP_MD_CTX_md(const EVP_MD_CTX *ctx);
47e71b7053SJung-uk Kim int EVP_MD_CTX_size(const EVP_MD *ctx);
48e71b7053SJung-uk Kim int EVP_MD_CTX_block_size(const EVP_MD *ctx);
49e71b7053SJung-uk Kim int EVP_MD_CTX_type(const EVP_MD *ctx);
50e71b7053SJung-uk Kim void *EVP_MD_CTX_md_data(const EVP_MD_CTX *ctx);
51e71b7053SJung-uk Kim
52e71b7053SJung-uk Kim const EVP_MD *EVP_md_null(void);
53e71b7053SJung-uk Kim
54e71b7053SJung-uk Kim const EVP_MD *EVP_get_digestbyname(const char *name);
55e71b7053SJung-uk Kim const EVP_MD *EVP_get_digestbynid(int type);
56e71b7053SJung-uk Kim const EVP_MD *EVP_get_digestbyobj(const ASN1_OBJECT *o);
57e71b7053SJung-uk Kim
58e71b7053SJung-uk Kim void EVP_MD_CTX_set_pkey_ctx(EVP_MD_CTX *ctx, EVP_PKEY_CTX *pctx);
59e71b7053SJung-uk Kim
60e71b7053SJung-uk Kim=head1 DESCRIPTION
61e71b7053SJung-uk Kim
62e71b7053SJung-uk KimThe EVP digest routines are a high level interface to message digests,
63e71b7053SJung-uk Kimand should be used instead of the cipher-specific functions.
64e71b7053SJung-uk Kim
65e71b7053SJung-uk Kim=over 4
66e71b7053SJung-uk Kim
67e71b7053SJung-uk Kim=item EVP_MD_CTX_new()
68e71b7053SJung-uk Kim
69e71b7053SJung-uk KimAllocates and returns a digest context.
70e71b7053SJung-uk Kim
71e71b7053SJung-uk Kim=item EVP_MD_CTX_reset()
72e71b7053SJung-uk Kim
73e71b7053SJung-uk KimResets the digest context B<ctx>.  This can be used to reuse an already
74e71b7053SJung-uk Kimexisting context.
75e71b7053SJung-uk Kim
76e71b7053SJung-uk Kim=item EVP_MD_CTX_free()
77e71b7053SJung-uk Kim
78e71b7053SJung-uk KimCleans up digest context B<ctx> and frees up the space allocated to it.
79e71b7053SJung-uk Kim
80e71b7053SJung-uk Kim=item EVP_MD_CTX_ctrl()
81e71b7053SJung-uk Kim
82e71b7053SJung-uk KimPerforms digest-specific control actions on context B<ctx>.
83e71b7053SJung-uk Kim
84e71b7053SJung-uk Kim=item EVP_MD_CTX_set_flags(), EVP_MD_CTX_clear_flags(), EVP_MD_CTX_test_flags()
85e71b7053SJung-uk Kim
86e71b7053SJung-uk KimSets, clears and tests B<ctx> flags.  See L</FLAGS> below for more information.
87e71b7053SJung-uk Kim
88e71b7053SJung-uk Kim=item EVP_DigestInit_ex()
89e71b7053SJung-uk Kim
90e71b7053SJung-uk KimSets up digest context B<ctx> to use a digest B<type> from ENGINE B<impl>.
91e71b7053SJung-uk KimB<type> will typically be supplied by a function such as EVP_sha1().  If
92e71b7053SJung-uk KimB<impl> is NULL then the default implementation of digest B<type> is used.
93e71b7053SJung-uk Kim
94e71b7053SJung-uk Kim=item EVP_DigestUpdate()
95e71b7053SJung-uk Kim
96e71b7053SJung-uk KimHashes B<cnt> bytes of data at B<d> into the digest context B<ctx>. This
97e71b7053SJung-uk Kimfunction can be called several times on the same B<ctx> to hash additional
98e71b7053SJung-uk Kimdata.
99e71b7053SJung-uk Kim
100e71b7053SJung-uk Kim=item EVP_DigestFinal_ex()
101e71b7053SJung-uk Kim
102e71b7053SJung-uk KimRetrieves the digest value from B<ctx> and places it in B<md>. If the B<s>
103e71b7053SJung-uk Kimparameter is not NULL then the number of bytes of data written (i.e. the
104e71b7053SJung-uk Kimlength of the digest) will be written to the integer at B<s>, at most
105e71b7053SJung-uk KimB<EVP_MAX_MD_SIZE> bytes will be written.  After calling EVP_DigestFinal_ex()
106e71b7053SJung-uk Kimno additional calls to EVP_DigestUpdate() can be made, but
107e71b7053SJung-uk KimEVP_DigestInit_ex() can be called to initialize a new digest operation.
108e71b7053SJung-uk Kim
109e71b7053SJung-uk Kim=item EVP_DigestFinalXOF()
110e71b7053SJung-uk Kim
111e71b7053SJung-uk KimInterfaces to extendable-output functions, XOFs, such as SHAKE128 and SHAKE256.
112e71b7053SJung-uk KimIt retrieves the digest value from B<ctx> and places it in B<len>-sized <B>md.
113e71b7053SJung-uk KimAfter calling this function no additional calls to EVP_DigestUpdate() can be
114e71b7053SJung-uk Kimmade, but EVP_DigestInit_ex() can be called to initialize a new operation.
115e71b7053SJung-uk Kim
116e71b7053SJung-uk Kim=item EVP_MD_CTX_copy_ex()
117e71b7053SJung-uk Kim
118e71b7053SJung-uk KimCan be used to copy the message digest state from B<in> to B<out>. This is
119e71b7053SJung-uk Kimuseful if large amounts of data are to be hashed which only differ in the last
120e71b7053SJung-uk Kimfew bytes.
121e71b7053SJung-uk Kim
122e71b7053SJung-uk Kim=item EVP_DigestInit()
123e71b7053SJung-uk Kim
124e71b7053SJung-uk KimBehaves in the same way as EVP_DigestInit_ex() except it always uses the
125e71b7053SJung-uk Kimdefault digest implementation.
126e71b7053SJung-uk Kim
127e71b7053SJung-uk Kim=item EVP_DigestFinal()
128e71b7053SJung-uk Kim
129e71b7053SJung-uk KimSimilar to EVP_DigestFinal_ex() except the digest context B<ctx> is
130e71b7053SJung-uk Kimautomatically cleaned up.
131e71b7053SJung-uk Kim
132e71b7053SJung-uk Kim=item EVP_MD_CTX_copy()
133e71b7053SJung-uk Kim
134e71b7053SJung-uk KimSimilar to EVP_MD_CTX_copy_ex() except the destination B<out> does not have to
135e71b7053SJung-uk Kimbe initialized.
136e71b7053SJung-uk Kim
137e71b7053SJung-uk Kim=item EVP_MD_size(),
138e71b7053SJung-uk KimEVP_MD_CTX_size()
139e71b7053SJung-uk Kim
140e71b7053SJung-uk KimReturn the size of the message digest when passed an B<EVP_MD> or an
141e71b7053SJung-uk KimB<EVP_MD_CTX> structure, i.e. the size of the hash.
142e71b7053SJung-uk Kim
143e71b7053SJung-uk Kim=item EVP_MD_block_size(),
144e71b7053SJung-uk KimEVP_MD_CTX_block_size()
145e71b7053SJung-uk Kim
146e71b7053SJung-uk KimReturn the block size of the message digest when passed an B<EVP_MD> or an
147e71b7053SJung-uk KimB<EVP_MD_CTX> structure.
148e71b7053SJung-uk Kim
149e71b7053SJung-uk Kim=item EVP_MD_type(),
150e71b7053SJung-uk KimEVP_MD_CTX_type()
151e71b7053SJung-uk Kim
152e71b7053SJung-uk KimReturn the NID of the OBJECT IDENTIFIER representing the given message digest
153e71b7053SJung-uk Kimwhen passed an B<EVP_MD> structure.  For example, C<EVP_MD_type(EVP_sha1())>
154e71b7053SJung-uk Kimreturns B<NID_sha1>. This function is normally used when setting ASN1 OIDs.
155e71b7053SJung-uk Kim
156e71b7053SJung-uk Kim=item EVP_MD_CTX_md_data()
157e71b7053SJung-uk Kim
158e71b7053SJung-uk KimReturn the digest method private data for the passed B<EVP_MD_CTX>.
159e71b7053SJung-uk KimThe space is allocated by OpenSSL and has the size originally set with
160e71b7053SJung-uk KimEVP_MD_meth_set_app_datasize().
161e71b7053SJung-uk Kim
162e71b7053SJung-uk Kim=item EVP_MD_CTX_md()
163e71b7053SJung-uk Kim
164e71b7053SJung-uk KimReturns the B<EVP_MD> structure corresponding to the passed B<EVP_MD_CTX>.
165e71b7053SJung-uk Kim
166e71b7053SJung-uk Kim=item EVP_MD_pkey_type()
167e71b7053SJung-uk Kim
168e71b7053SJung-uk KimReturns the NID of the public key signing algorithm associated with this
169e71b7053SJung-uk Kimdigest. For example EVP_sha1() is associated with RSA so this will return
170e71b7053SJung-uk KimB<NID_sha1WithRSAEncryption>. Since digests and signature algorithms are no
171e71b7053SJung-uk Kimlonger linked this function is only retained for compatibility reasons.
172e71b7053SJung-uk Kim
173e71b7053SJung-uk Kim=item EVP_md_null()
174e71b7053SJung-uk Kim
175e71b7053SJung-uk KimA "null" message digest that does nothing: i.e. the hash it returns is of zero
176e71b7053SJung-uk Kimlength.
177e71b7053SJung-uk Kim
178e71b7053SJung-uk Kim=item EVP_get_digestbyname(),
179e71b7053SJung-uk KimEVP_get_digestbynid(),
180e71b7053SJung-uk KimEVP_get_digestbyobj()
181e71b7053SJung-uk Kim
182e71b7053SJung-uk KimReturns an B<EVP_MD> structure when passed a digest name, a digest B<NID> or an
183e71b7053SJung-uk KimB<ASN1_OBJECT> structure respectively.
184e71b7053SJung-uk Kim
185e71b7053SJung-uk Kim=item EVP_MD_CTX_set_pkey_ctx()
186e71b7053SJung-uk Kim
187e71b7053SJung-uk KimAssigns an B<EVP_PKEY_CTX> to B<EVP_MD_CTX>. This is usually used to provide
188e71b7053SJung-uk Kima customzied B<EVP_PKEY_CTX> to L<EVP_DigestSignInit(3)> or
189e71b7053SJung-uk KimL<EVP_DigestVerifyInit(3)>. The B<pctx> passed to this function should be freed
190e71b7053SJung-uk Kimby the caller. A NULL B<pctx> pointer is also allowed to clear the B<EVP_PKEY_CTX>
191e71b7053SJung-uk Kimassigned to B<ctx>. In such case, freeing the cleared B<EVP_PKEY_CTX> or not
192e71b7053SJung-uk Kimdepends on how the B<EVP_PKEY_CTX> is created.
193e71b7053SJung-uk Kim
194e71b7053SJung-uk Kim=back
195e71b7053SJung-uk Kim
196e71b7053SJung-uk Kim=head1 FLAGS
197e71b7053SJung-uk Kim
198e71b7053SJung-uk KimEVP_MD_CTX_set_flags(), EVP_MD_CTX_clear_flags() and EVP_MD_CTX_test_flags()
199e71b7053SJung-uk Kimcan be used the manipulate and test these B<EVP_MD_CTX> flags:
200e71b7053SJung-uk Kim
201e71b7053SJung-uk Kim=over 4
202e71b7053SJung-uk Kim
203e71b7053SJung-uk Kim=item EVP_MD_CTX_FLAG_ONESHOT
204e71b7053SJung-uk Kim
205e71b7053SJung-uk KimThis flag instructs the digest to optimize for one update only, if possible.
206e71b7053SJung-uk Kim
207e71b7053SJung-uk Kim=for comment EVP_MD_CTX_FLAG_CLEANED is internal, don't mention it
208e71b7053SJung-uk Kim
209e71b7053SJung-uk Kim=for comment EVP_MD_CTX_FLAG_REUSE is internal, don't mention it
210e71b7053SJung-uk Kim
211e71b7053SJung-uk Kim=for comment We currently avoid documenting flags that are only bit holder:
212e71b7053SJung-uk KimEVP_MD_CTX_FLAG_NON_FIPS_ALLOW, EVP_MD_CTX_FLAGS_PAD_*
213e71b7053SJung-uk Kim
214e71b7053SJung-uk Kim=item EVP_MD_CTX_FLAG_NO_INIT
215e71b7053SJung-uk Kim
216e71b7053SJung-uk KimThis flag instructs EVP_DigestInit() and similar not to initialise the
217e71b7053SJung-uk Kimimplementation specific data.
218e71b7053SJung-uk Kim
219e71b7053SJung-uk Kim=item EVP_MD_CTX_FLAG_FINALISE
220e71b7053SJung-uk Kim
221e71b7053SJung-uk KimSome functions such as EVP_DigestSign only finalise copies of internal
222e71b7053SJung-uk Kimcontexts so additional data can be included after the finalisation call.
223e71b7053SJung-uk KimThis is inefficient if this functionality is not required, and can be
224e71b7053SJung-uk Kimdisabled with this flag.
225e71b7053SJung-uk Kim
226e71b7053SJung-uk Kim=back
227e71b7053SJung-uk Kim
228e71b7053SJung-uk Kim=head1 RETURN VALUES
229e71b7053SJung-uk Kim
230e71b7053SJung-uk Kim=over 4
231e71b7053SJung-uk Kim
232e71b7053SJung-uk Kim=item EVP_DigestInit_ex(),
233e71b7053SJung-uk KimEVP_DigestUpdate(),
234e71b7053SJung-uk KimEVP_DigestFinal_ex()
235e71b7053SJung-uk Kim
236e71b7053SJung-uk KimReturns 1 for
237e71b7053SJung-uk Kimsuccess and 0 for failure.
238e71b7053SJung-uk Kim
239e71b7053SJung-uk Kim=item EVP_MD_CTX_ctrl()
240e71b7053SJung-uk Kim
241e71b7053SJung-uk KimReturns 1 if successful or 0 for failure.
242e71b7053SJung-uk Kim
243e71b7053SJung-uk Kim=item EVP_MD_CTX_copy_ex()
244e71b7053SJung-uk Kim
245e71b7053SJung-uk KimReturns 1 if successful or 0 for failure.
246e71b7053SJung-uk Kim
247e71b7053SJung-uk Kim=item EVP_MD_type(),
248e71b7053SJung-uk KimEVP_MD_pkey_type(),
249e71b7053SJung-uk KimEVP_MD_type()
250e71b7053SJung-uk Kim
251e71b7053SJung-uk KimReturns the NID of the corresponding OBJECT IDENTIFIER or NID_undef if none
252e71b7053SJung-uk Kimexists.
253e71b7053SJung-uk Kim
254e71b7053SJung-uk Kim=item EVP_MD_size(),
255e71b7053SJung-uk KimEVP_MD_block_size(),
256e71b7053SJung-uk KimEVP_MD_CTX_size(),
257e71b7053SJung-uk KimEVP_MD_CTX_block_size()
258e71b7053SJung-uk Kim
259e71b7053SJung-uk KimReturns the digest or block size in bytes.
260e71b7053SJung-uk Kim
261e71b7053SJung-uk Kim=item EVP_md_null()
262e71b7053SJung-uk Kim
263e71b7053SJung-uk KimReturns a pointer to the B<EVP_MD> structure of the "null" message digest.
264e71b7053SJung-uk Kim
265e71b7053SJung-uk Kim=item EVP_get_digestbyname(),
266e71b7053SJung-uk KimEVP_get_digestbynid(),
267e71b7053SJung-uk KimEVP_get_digestbyobj()
268e71b7053SJung-uk Kim
269e71b7053SJung-uk KimReturns either an B<EVP_MD> structure or NULL if an error occurs.
270e71b7053SJung-uk Kim
271e71b7053SJung-uk Kim=item EVP_MD_CTX_set_pkey_ctx()
272e71b7053SJung-uk Kim
273e71b7053SJung-uk KimThis function has no return value.
274e71b7053SJung-uk Kim
275e71b7053SJung-uk Kim=back
276e71b7053SJung-uk Kim
277e71b7053SJung-uk Kim=head1 NOTES
278e71b7053SJung-uk Kim
279e71b7053SJung-uk KimThe B<EVP> interface to message digests should almost always be used in
280e71b7053SJung-uk Kimpreference to the low level interfaces. This is because the code then becomes
281e71b7053SJung-uk Kimtransparent to the digest used and much more flexible.
282e71b7053SJung-uk Kim
283e71b7053SJung-uk KimNew applications should use the SHA-2 (such as L<EVP_sha256(3)>) or the SHA-3
284e71b7053SJung-uk Kimdigest algorithms (such as L<EVP_sha3_512(3)>). The other digest algorithms
285e71b7053SJung-uk Kimare still in common use.
286e71b7053SJung-uk Kim
287e71b7053SJung-uk KimFor most applications the B<impl> parameter to EVP_DigestInit_ex() will be
288e71b7053SJung-uk Kimset to NULL to use the default digest implementation.
289e71b7053SJung-uk Kim
290e71b7053SJung-uk KimThe functions EVP_DigestInit(), EVP_DigestFinal() and EVP_MD_CTX_copy() are
291e71b7053SJung-uk Kimobsolete but are retained to maintain compatibility with existing code. New
292e71b7053SJung-uk Kimapplications should use EVP_DigestInit_ex(), EVP_DigestFinal_ex() and
293e71b7053SJung-uk KimEVP_MD_CTX_copy_ex() because they can efficiently reuse a digest context
294e71b7053SJung-uk Kiminstead of initializing and cleaning it up on each call and allow non default
295e71b7053SJung-uk Kimimplementations of digests to be specified.
296e71b7053SJung-uk Kim
297e71b7053SJung-uk KimIf digest contexts are not cleaned up after use,
298e71b7053SJung-uk Kimmemory leaks will occur.
299e71b7053SJung-uk Kim
300e71b7053SJung-uk KimEVP_MD_CTX_size(), EVP_MD_CTX_block_size(), EVP_MD_CTX_type(),
301e71b7053SJung-uk KimEVP_get_digestbynid() and EVP_get_digestbyobj() are defined as
302e71b7053SJung-uk Kimmacros.
303e71b7053SJung-uk Kim
304e71b7053SJung-uk KimEVP_MD_CTX_ctrl() sends commands to message digests for additional configuration
305e71b7053SJung-uk Kimor control.
306e71b7053SJung-uk Kim
307*da327cd2SJung-uk Kim=head1 EXAMPLES
308e71b7053SJung-uk Kim
309e71b7053SJung-uk KimThis example digests the data "Test Message\n" and "Hello World\n", using the
310e71b7053SJung-uk Kimdigest name passed on the command line.
311e71b7053SJung-uk Kim
312e71b7053SJung-uk Kim #include <stdio.h>
313c9cf7b5cSJung-uk Kim #include <string.h>
314e71b7053SJung-uk Kim #include <openssl/evp.h>
315e71b7053SJung-uk Kim
316c9cf7b5cSJung-uk Kim int main(int argc, char *argv[])
317e71b7053SJung-uk Kim {
318e71b7053SJung-uk Kim     EVP_MD_CTX *mdctx;
319e71b7053SJung-uk Kim     const EVP_MD *md;
320e71b7053SJung-uk Kim     char mess1[] = "Test Message\n";
321e71b7053SJung-uk Kim     char mess2[] = "Hello World\n";
322e71b7053SJung-uk Kim     unsigned char md_value[EVP_MAX_MD_SIZE];
323c9cf7b5cSJung-uk Kim     unsigned int md_len, i;
324e71b7053SJung-uk Kim
325e71b7053SJung-uk Kim     if (argv[1] == NULL) {
326e71b7053SJung-uk Kim         printf("Usage: mdtest digestname\n");
327e71b7053SJung-uk Kim         exit(1);
328e71b7053SJung-uk Kim     }
329e71b7053SJung-uk Kim
330e71b7053SJung-uk Kim     md = EVP_get_digestbyname(argv[1]);
331e71b7053SJung-uk Kim     if (md == NULL) {
332e71b7053SJung-uk Kim         printf("Unknown message digest %s\n", argv[1]);
333e71b7053SJung-uk Kim         exit(1);
334e71b7053SJung-uk Kim     }
335e71b7053SJung-uk Kim
336e71b7053SJung-uk Kim     mdctx = EVP_MD_CTX_new();
337e71b7053SJung-uk Kim     EVP_DigestInit_ex(mdctx, md, NULL);
338e71b7053SJung-uk Kim     EVP_DigestUpdate(mdctx, mess1, strlen(mess1));
339e71b7053SJung-uk Kim     EVP_DigestUpdate(mdctx, mess2, strlen(mess2));
340e71b7053SJung-uk Kim     EVP_DigestFinal_ex(mdctx, md_value, &md_len);
341e71b7053SJung-uk Kim     EVP_MD_CTX_free(mdctx);
342e71b7053SJung-uk Kim
343e71b7053SJung-uk Kim     printf("Digest is: ");
344e71b7053SJung-uk Kim     for (i = 0; i < md_len; i++)
345e71b7053SJung-uk Kim         printf("%02x", md_value[i]);
346e71b7053SJung-uk Kim     printf("\n");
347e71b7053SJung-uk Kim
348e71b7053SJung-uk Kim     exit(0);
349e71b7053SJung-uk Kim }
350e71b7053SJung-uk Kim
351e71b7053SJung-uk Kim=head1 SEE ALSO
352e71b7053SJung-uk Kim
353e71b7053SJung-uk KimL<dgst(1)>,
354e71b7053SJung-uk KimL<evp(7)>
355e71b7053SJung-uk Kim
356e71b7053SJung-uk KimThe full list of digest algorithms are provided below.
357e71b7053SJung-uk Kim
358e71b7053SJung-uk KimL<EVP_blake2b512(3)>,
359e71b7053SJung-uk KimL<EVP_md2(3)>,
360e71b7053SJung-uk KimL<EVP_md4(3)>,
361e71b7053SJung-uk KimL<EVP_md5(3)>,
362e71b7053SJung-uk KimL<EVP_mdc2(3)>,
363e71b7053SJung-uk KimL<EVP_ripemd160(3)>,
364e71b7053SJung-uk KimL<EVP_sha1(3)>,
365e71b7053SJung-uk KimL<EVP_sha224(3)>,
366e71b7053SJung-uk KimL<EVP_sha3_224(3)>,
367e71b7053SJung-uk KimL<EVP_sm3(3)>,
368e71b7053SJung-uk KimL<EVP_whirlpool(3)>
369e71b7053SJung-uk Kim
370e71b7053SJung-uk Kim=head1 HISTORY
371e71b7053SJung-uk Kim
3726935a639SJung-uk KimThe EVP_MD_CTX_create() and EVP_MD_CTX_destroy() functions were renamed to
3736935a639SJung-uk KimEVP_MD_CTX_new() and EVP_MD_CTX_free() in OpenSSL 1.1.0, respectively.
374e71b7053SJung-uk Kim
375e71b7053SJung-uk KimThe link between digests and signing algorithms was fixed in OpenSSL 1.0 and
376e71b7053SJung-uk Kimlater, so now EVP_sha1() can be used with RSA and DSA.
377e71b7053SJung-uk Kim
3786935a639SJung-uk KimThe EVP_dss1() function was removed in OpenSSL 1.1.0.
379e71b7053SJung-uk Kim
3806935a639SJung-uk KimThe EVP_MD_CTX_set_pkey_ctx() function was added in 1.1.1.
381e71b7053SJung-uk Kim
382e71b7053SJung-uk Kim=head1 COPYRIGHT
383e71b7053SJung-uk Kim
384*da327cd2SJung-uk KimCopyright 2000-2019 The OpenSSL Project Authors. All Rights Reserved.
385e71b7053SJung-uk Kim
386e71b7053SJung-uk KimLicensed under the OpenSSL license (the "License").  You may not use
387e71b7053SJung-uk Kimthis file except in compliance with the License.  You can obtain a copy
388e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at
389e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>.
390e71b7053SJung-uk Kim
391e71b7053SJung-uk Kim=cut
392