]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - secure/lib/libcrypto/man/man3/EVP_DigestInit.3
OpenSSL: Regen manual pages for OpenSSL 1.1.1j.
[FreeBSD/FreeBSD.git] / secure / lib / libcrypto / man / man3 / EVP_DigestInit.3
1 .\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42)
2 .\"
3 .\" Standard preamble:
4 .\" ========================================================================
5 .de Sp \" Vertical space (when we can't use .PP)
6 .if t .sp .5v
7 .if n .sp
8 ..
9 .de Vb \" Begin verbatim text
10 .ft CW
11 .nf
12 .ne \\$1
13 ..
14 .de Ve \" End verbatim text
15 .ft R
16 .fi
17 ..
18 .\" Set up some character translations and predefined strings.  \*(-- will
19 .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
20 .\" double quote, and \*(R" will give a right double quote.  \*(C+ will
21 .\" give a nicer C++.  Capital omega is used to do unbreakable dashes and
22 .\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,
23 .\" nothing in troff, for use with C<>.
24 .tr \(*W-
25 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
26 .ie n \{\
27 .    ds -- \(*W-
28 .    ds PI pi
29 .    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
30 .    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
31 .    ds L" ""
32 .    ds R" ""
33 .    ds C` ""
34 .    ds C' ""
35 'br\}
36 .el\{\
37 .    ds -- \|\(em\|
38 .    ds PI \(*p
39 .    ds L" ``
40 .    ds R" ''
41 .    ds C`
42 .    ds C'
43 'br\}
44 .\"
45 .\" Escape single quotes in literal strings from groff's Unicode transform.
46 .ie \n(.g .ds Aq \(aq
47 .el       .ds Aq '
48 .\"
49 .\" If the F register is >0, we'll generate index entries on stderr for
50 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
51 .\" entries marked with X<> in POD.  Of course, you'll have to process the
52 .\" output yourself in some meaningful fashion.
53 .\"
54 .\" Avoid warning from groff about undefined register 'F'.
55 .de IX
56 ..
57 .nr rF 0
58 .if \n(.g .if rF .nr rF 1
59 .if (\n(rF:(\n(.g==0)) \{\
60 .    if \nF \{\
61 .        de IX
62 .        tm Index:\\$1\t\\n%\t"\\$2"
63 ..
64 .        if !\nF==2 \{\
65 .            nr % 0
66 .            nr F 2
67 .        \}
68 .    \}
69 .\}
70 .rr rF
71 .\"
72 .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
73 .\" Fear.  Run.  Save yourself.  No user-serviceable parts.
74 .    \" fudge factors for nroff and troff
75 .if n \{\
76 .    ds #H 0
77 .    ds #V .8m
78 .    ds #F .3m
79 .    ds #[ \f1
80 .    ds #] \fP
81 .\}
82 .if t \{\
83 .    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
84 .    ds #V .6m
85 .    ds #F 0
86 .    ds #[ \&
87 .    ds #] \&
88 .\}
89 .    \" simple accents for nroff and troff
90 .if n \{\
91 .    ds ' \&
92 .    ds ` \&
93 .    ds ^ \&
94 .    ds , \&
95 .    ds ~ ~
96 .    ds /
97 .\}
98 .if t \{\
99 .    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
100 .    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
101 .    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
102 .    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
103 .    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
104 .    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
105 .\}
106 .    \" troff and (daisy-wheel) nroff accents
107 .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
108 .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
109 .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
110 .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
111 .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
112 .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
113 .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
114 .ds ae a\h'-(\w'a'u*4/10)'e
115 .ds Ae A\h'-(\w'A'u*4/10)'E
116 .    \" corrections for vroff
117 .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
118 .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
119 .    \" for low resolution devices (crt and lpr)
120 .if \n(.H>23 .if \n(.V>19 \
121 \{\
122 .    ds : e
123 .    ds 8 ss
124 .    ds o a
125 .    ds d- d\h'-1'\(ga
126 .    ds D- D\h'-1'\(hy
127 .    ds th \o'bp'
128 .    ds Th \o'LP'
129 .    ds ae ae
130 .    ds Ae AE
131 .\}
132 .rm #[ #] #H #V #F C
133 .\" ========================================================================
134 .\"
135 .IX Title "EVP_DIGESTINIT 3"
136 .TH EVP_DIGESTINIT 3 "2021-02-16" "1.1.1j" "OpenSSL"
137 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
138 .\" way too many mistakes in technical documents.
139 .if n .ad l
140 .nh
141 .SH "NAME"
142 EVP_MD_CTX_new, EVP_MD_CTX_reset, EVP_MD_CTX_free, EVP_MD_CTX_copy, EVP_MD_CTX_copy_ex, EVP_MD_CTX_ctrl, EVP_MD_CTX_set_flags, EVP_MD_CTX_clear_flags, EVP_MD_CTX_test_flags, EVP_Digest, EVP_DigestInit_ex, EVP_DigestInit, EVP_DigestUpdate, EVP_DigestFinal_ex, EVP_DigestFinalXOF, EVP_DigestFinal, EVP_MD_type, EVP_MD_pkey_type, EVP_MD_size, EVP_MD_block_size, EVP_MD_flags, EVP_MD_CTX_md, EVP_MD_CTX_type, EVP_MD_CTX_size, EVP_MD_CTX_block_size, EVP_MD_CTX_md_data, EVP_MD_CTX_update_fn, EVP_MD_CTX_set_update_fn, EVP_md_null, EVP_get_digestbyname, EVP_get_digestbynid, EVP_get_digestbyobj, EVP_MD_CTX_pkey_ctx, EVP_MD_CTX_set_pkey_ctx \- EVP digest routines
143 .SH "SYNOPSIS"
144 .IX Header "SYNOPSIS"
145 .Vb 1
146 \& #include <openssl/evp.h>
147 \&
148 \& EVP_MD_CTX *EVP_MD_CTX_new(void);
149 \& int EVP_MD_CTX_reset(EVP_MD_CTX *ctx);
150 \& void EVP_MD_CTX_free(EVP_MD_CTX *ctx);
151 \& void EVP_MD_CTX_ctrl(EVP_MD_CTX *ctx, int cmd, int p1, void* p2);
152 \& void EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags);
153 \& void EVP_MD_CTX_clear_flags(EVP_MD_CTX *ctx, int flags);
154 \& int EVP_MD_CTX_test_flags(const EVP_MD_CTX *ctx, int flags);
155 \&
156 \& int EVP_Digest(const void *data, size_t count, unsigned char *md,
157 \&                unsigned int *size, const EVP_MD *type, ENGINE *impl);
158 \& int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl);
159 \& int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *d, size_t cnt);
160 \& int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *s);
161 \& int EVP_DigestFinalXOF(EVP_MD_CTX *ctx, unsigned char *md, size_t len);
162 \&
163 \& int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in);
164 \&
165 \& int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type);
166 \& int EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *s);
167 \&
168 \& int EVP_MD_CTX_copy(EVP_MD_CTX *out, EVP_MD_CTX *in);
169 \&
170 \& int EVP_MD_type(const EVP_MD *md);
171 \& int EVP_MD_pkey_type(const EVP_MD *md);
172 \& int EVP_MD_size(const EVP_MD *md);
173 \& int EVP_MD_block_size(const EVP_MD *md);
174 \& unsigned long EVP_MD_flags(const EVP_MD *md);
175 \&
176 \& const EVP_MD *EVP_MD_CTX_md(const EVP_MD_CTX *ctx);
177 \& int EVP_MD_CTX_size(const EVP_MD_CTX *ctx);
178 \& int EVP_MD_CTX_block_size(const EVP_MD_CTX *ctx);
179 \& int EVP_MD_CTX_type(const EVP_MD_CTX *ctx);
180 \& void *EVP_MD_CTX_md_data(const EVP_MD_CTX *ctx);
181 \& int (*EVP_MD_CTX_update_fn(EVP_MD_CTX *ctx))(EVP_MD_CTX *ctx,
182 \&                                              const void *data, size_t count);
183 \& void EVP_MD_CTX_set_update_fn(EVP_MD_CTX *ctx,
184 \&                               int (*update)(EVP_MD_CTX *ctx,
185 \&                                             const void *data, size_t count));
186 \&
187 \& const EVP_MD *EVP_md_null(void);
188 \&
189 \& const EVP_MD *EVP_get_digestbyname(const char *name);
190 \& const EVP_MD *EVP_get_digestbynid(int type);
191 \& const EVP_MD *EVP_get_digestbyobj(const ASN1_OBJECT *o);
192 \&
193 \& EVP_PKEY_CTX *EVP_MD_CTX_pkey_ctx(const EVP_MD_CTX *ctx);
194 \& void EVP_MD_CTX_set_pkey_ctx(EVP_MD_CTX *ctx, EVP_PKEY_CTX *pctx);
195 .Ve
196 .SH "DESCRIPTION"
197 .IX Header "DESCRIPTION"
198 The \s-1EVP\s0 digest routines are a high-level interface to message digests,
199 and should be used instead of the cipher-specific functions.
200 .IP "\fBEVP_MD_CTX_new()\fR" 4
201 .IX Item "EVP_MD_CTX_new()"
202 Allocates and returns a digest context.
203 .IP "\fBEVP_MD_CTX_reset()\fR" 4
204 .IX Item "EVP_MD_CTX_reset()"
205 Resets the digest context \fBctx\fR.  This can be used to reuse an already
206 existing context.
207 .IP "\fBEVP_MD_CTX_free()\fR" 4
208 .IX Item "EVP_MD_CTX_free()"
209 Cleans up digest context \fBctx\fR and frees up the space allocated to it.
210 .IP "\fBEVP_MD_CTX_ctrl()\fR" 4
211 .IX Item "EVP_MD_CTX_ctrl()"
212 Performs digest-specific control actions on context \fBctx\fR. The control command
213 is indicated in \fBcmd\fR and any additional arguments in \fBp1\fR and \fBp2\fR.
214 \&\fBEVP_MD_CTX_ctrl()\fR must be called after \fBEVP_DigestInit_ex()\fR. Other restrictions
215 may apply depending on the control type and digest implementation.
216 See \*(L"\s-1CONTROLS\*(R"\s0 below for more information.
217 .IP "\fBEVP_MD_CTX_set_flags()\fR, \fBEVP_MD_CTX_clear_flags()\fR, \fBEVP_MD_CTX_test_flags()\fR" 4
218 .IX Item "EVP_MD_CTX_set_flags(), EVP_MD_CTX_clear_flags(), EVP_MD_CTX_test_flags()"
219 Sets, clears and tests \fBctx\fR flags.  See \*(L"\s-1FLAGS\*(R"\s0 below for more information.
220 .IP "\fBEVP_Digest()\fR" 4
221 .IX Item "EVP_Digest()"
222 A wrapper around the Digest Init_ex, Update and Final_ex functions.
223 Hashes \fBcount\fR bytes of data at \fBdata\fR using a digest \fBtype\fR from \s-1ENGINE\s0
224 \&\fBimpl\fR. The digest value is placed in \fBmd\fR and its length is written at \fBsize\fR
225 if the pointer is not \s-1NULL.\s0 At most \fB\s-1EVP_MAX_MD_SIZE\s0\fR bytes will be written.
226 If \fBimpl\fR is \s-1NULL\s0 the default implementation of digest \fBtype\fR is used.
227 .IP "\fBEVP_DigestInit_ex()\fR" 4
228 .IX Item "EVP_DigestInit_ex()"
229 Sets up digest context \fBctx\fR to use a digest \fBtype\fR from \s-1ENGINE\s0 \fBimpl\fR.
230 \&\fBtype\fR will typically be supplied by a function such as \fBEVP_sha1()\fR.  If
231 \&\fBimpl\fR is \s-1NULL\s0 then the default implementation of digest \fBtype\fR is used.
232 .IP "\fBEVP_DigestUpdate()\fR" 4
233 .IX Item "EVP_DigestUpdate()"
234 Hashes \fBcnt\fR bytes of data at \fBd\fR into the digest context \fBctx\fR. This
235 function can be called several times on the same \fBctx\fR to hash additional
236 data.
237 .IP "\fBEVP_DigestFinal_ex()\fR" 4
238 .IX Item "EVP_DigestFinal_ex()"
239 Retrieves the digest value from \fBctx\fR and places it in \fBmd\fR. If the \fBs\fR
240 parameter is not \s-1NULL\s0 then the number of bytes of data written (i.e. the
241 length of the digest) will be written to the integer at \fBs\fR, at most
242 \&\fB\s-1EVP_MAX_MD_SIZE\s0\fR bytes will be written.  After calling \fBEVP_DigestFinal_ex()\fR
243 no additional calls to \fBEVP_DigestUpdate()\fR can be made, but
244 \&\fBEVP_DigestInit_ex()\fR can be called to initialize a new digest operation.
245 .IP "\fBEVP_DigestFinalXOF()\fR" 4
246 .IX Item "EVP_DigestFinalXOF()"
247 Interfaces to extendable-output functions, XOFs, such as \s-1SHAKE128\s0 and \s-1SHAKE256.\s0
248 It retrieves the digest value from \fBctx\fR and places it in \fBlen\fR\-sized <B>md.
249 After calling this function no additional calls to \fBEVP_DigestUpdate()\fR can be
250 made, but \fBEVP_DigestInit_ex()\fR can be called to initialize a new operation.
251 .IP "\fBEVP_MD_CTX_copy_ex()\fR" 4
252 .IX Item "EVP_MD_CTX_copy_ex()"
253 Can be used to copy the message digest state from \fBin\fR to \fBout\fR. This is
254 useful if large amounts of data are to be hashed which only differ in the last
255 few bytes.
256 .IP "\fBEVP_DigestInit()\fR" 4
257 .IX Item "EVP_DigestInit()"
258 Behaves in the same way as \fBEVP_DigestInit_ex()\fR except it always uses the
259 default digest implementation and calls \fBEVP_MD_CTX_reset()\fR.
260 .IP "\fBEVP_DigestFinal()\fR" 4
261 .IX Item "EVP_DigestFinal()"
262 Similar to \fBEVP_DigestFinal_ex()\fR except the digest context \fBctx\fR is
263 automatically cleaned up.
264 .IP "\fBEVP_MD_CTX_copy()\fR" 4
265 .IX Item "EVP_MD_CTX_copy()"
266 Similar to \fBEVP_MD_CTX_copy_ex()\fR except the destination \fBout\fR does not have to
267 be initialized.
268 .IP "\fBEVP_MD_size()\fR, \fBEVP_MD_CTX_size()\fR" 4
269 .IX Item "EVP_MD_size(), EVP_MD_CTX_size()"
270 Return the size of the message digest when passed an \fB\s-1EVP_MD\s0\fR or an
271 \&\fB\s-1EVP_MD_CTX\s0\fR structure, i.e. the size of the hash.
272 .IP "\fBEVP_MD_block_size()\fR, \fBEVP_MD_CTX_block_size()\fR" 4
273 .IX Item "EVP_MD_block_size(), EVP_MD_CTX_block_size()"
274 Return the block size of the message digest when passed an \fB\s-1EVP_MD\s0\fR or an
275 \&\fB\s-1EVP_MD_CTX\s0\fR structure.
276 .IP "\fBEVP_MD_type()\fR, \fBEVP_MD_CTX_type()\fR" 4
277 .IX Item "EVP_MD_type(), EVP_MD_CTX_type()"
278 Return the \s-1NID\s0 of the \s-1OBJECT IDENTIFIER\s0 representing the given message digest
279 when passed an \fB\s-1EVP_MD\s0\fR structure.  For example, \f(CW\*(C`EVP_MD_type(EVP_sha1())\*(C'\fR
280 returns \fBNID_sha1\fR. This function is normally used when setting \s-1ASN1\s0 OIDs.
281 .IP "\fBEVP_MD_CTX_md_data()\fR" 4
282 .IX Item "EVP_MD_CTX_md_data()"
283 Return the digest method private data for the passed \fB\s-1EVP_MD_CTX\s0\fR.
284 The space is allocated by OpenSSL and has the size originally set with
285 \&\fBEVP_MD_meth_set_app_datasize()\fR.
286 .IP "\fBEVP_MD_CTX_md()\fR" 4
287 .IX Item "EVP_MD_CTX_md()"
288 Returns the \fB\s-1EVP_MD\s0\fR structure corresponding to the passed \fB\s-1EVP_MD_CTX\s0\fR.
289 .IP "\fBEVP_MD_CTX_set_update_fn()\fR" 4
290 .IX Item "EVP_MD_CTX_set_update_fn()"
291 Sets the update function for \fBctx\fR to \fBupdate\fR.
292 This is the function that is called by EVP_DigestUpdate. If not set, the
293 update function from the \fB\s-1EVP_MD\s0\fR type specified at initialization is used.
294 .IP "\fBEVP_MD_CTX_update_fn()\fR" 4
295 .IX Item "EVP_MD_CTX_update_fn()"
296 Returns the update function for \fBctx\fR.
297 .IP "\fBEVP_MD_flags()\fR" 4
298 .IX Item "EVP_MD_flags()"
299 Returns the \fBmd\fR flags. Note that these are different from the \fB\s-1EVP_MD_CTX\s0\fR
300 ones. See \fBEVP_MD_meth_set_flags\fR\|(3) for more information.
301 .IP "\fBEVP_MD_pkey_type()\fR" 4
302 .IX Item "EVP_MD_pkey_type()"
303 Returns the \s-1NID\s0 of the public key signing algorithm associated with this
304 digest. For example \fBEVP_sha1()\fR is associated with \s-1RSA\s0 so this will return
305 \&\fBNID_sha1WithRSAEncryption\fR. Since digests and signature algorithms are no
306 longer linked this function is only retained for compatibility reasons.
307 .IP "\fBEVP_md_null()\fR" 4
308 .IX Item "EVP_md_null()"
309 A \*(L"null\*(R" message digest that does nothing: i.e. the hash it returns is of zero
310 length.
311 .IP "\fBEVP_get_digestbyname()\fR, \fBEVP_get_digestbynid()\fR, \fBEVP_get_digestbyobj()\fR" 4
312 .IX Item "EVP_get_digestbyname(), EVP_get_digestbynid(), EVP_get_digestbyobj()"
313 Returns an \fB\s-1EVP_MD\s0\fR structure when passed a digest name, a digest \fB\s-1NID\s0\fR or an
314 \&\fB\s-1ASN1_OBJECT\s0\fR structure respectively.
315 .IP "\fBEVP_MD_CTX_pkey_ctx()\fR" 4
316 .IX Item "EVP_MD_CTX_pkey_ctx()"
317 Returns the \fB\s-1EVP_PKEY_CTX\s0\fR assigned to \fBctx\fR. The returned pointer should not
318 be freed by the caller.
319 .IP "\fBEVP_MD_CTX_set_pkey_ctx()\fR" 4
320 .IX Item "EVP_MD_CTX_set_pkey_ctx()"
321 Assigns an \fB\s-1EVP_PKEY_CTX\s0\fR to \fB\s-1EVP_MD_CTX\s0\fR. This is usually used to provide
322 a customized \fB\s-1EVP_PKEY_CTX\s0\fR to \fBEVP_DigestSignInit\fR\|(3) or
323 \&\fBEVP_DigestVerifyInit\fR\|(3). The \fBpctx\fR passed to this function should be freed
324 by the caller. A \s-1NULL\s0 \fBpctx\fR pointer is also allowed to clear the \fB\s-1EVP_PKEY_CTX\s0\fR
325 assigned to \fBctx\fR. In such case, freeing the cleared \fB\s-1EVP_PKEY_CTX\s0\fR or not
326 depends on how the \fB\s-1EVP_PKEY_CTX\s0\fR is created.
327 .SH "CONTROLS"
328 .IX Header "CONTROLS"
329 \&\fBEVP_MD_CTX_ctrl()\fR can be used to send the following standard controls:
330 .IP "\s-1EVP_MD_CTRL_MICALG\s0" 4
331 .IX Item "EVP_MD_CTRL_MICALG"
332 Gets the digest Message Integrity Check algorithm string. This is used when
333 creating S/MIME multipart/signed messages, as specified in \s-1RFC 3851.\s0
334 The string value is written to \fBp2\fR.
335 .IP "\s-1EVP_MD_CTRL_XOF_LEN\s0" 4
336 .IX Item "EVP_MD_CTRL_XOF_LEN"
337 This control sets the digest length for extendable output functions to \fBp1\fR.
338 Sending this control directly should not be necessary, the use of
339 \&\f(CW\*(C`EVP_DigestFinalXOF()\*(C'\fR is preferred.
340 Currently used by \s-1SHAKE.\s0
341 .SH "FLAGS"
342 .IX Header "FLAGS"
343 \&\fBEVP_MD_CTX_set_flags()\fR, \fBEVP_MD_CTX_clear_flags()\fR and \fBEVP_MD_CTX_test_flags()\fR
344 can be used the manipulate and test these \fB\s-1EVP_MD_CTX\s0\fR flags:
345 .IP "\s-1EVP_MD_CTX_FLAG_ONESHOT\s0" 4
346 .IX Item "EVP_MD_CTX_FLAG_ONESHOT"
347 This flag instructs the digest to optimize for one update only, if possible.
348 .IP "\s-1EVP_MD_CTX_FLAG_NO_INIT\s0" 4
349 .IX Item "EVP_MD_CTX_FLAG_NO_INIT"
350 This flag instructs \fBEVP_DigestInit()\fR and similar not to initialise the
351 implementation specific data.
352 .IP "\s-1EVP_MD_CTX_FLAG_FINALISE\s0" 4
353 .IX Item "EVP_MD_CTX_FLAG_FINALISE"
354 Some functions such as EVP_DigestSign only finalise copies of internal
355 contexts so additional data can be included after the finalisation call.
356 This is inefficient if this functionality is not required, and can be
357 disabled with this flag.
358 .SH "RETURN VALUES"
359 .IX Header "RETURN VALUES"
360 .IP "\fBEVP_DigestInit_ex()\fR, \fBEVP_DigestUpdate()\fR, \fBEVP_DigestFinal_ex()\fR" 4
361 .IX Item "EVP_DigestInit_ex(), EVP_DigestUpdate(), EVP_DigestFinal_ex()"
362 Returns 1 for
363 success and 0 for failure.
364 .IP "\fBEVP_MD_CTX_ctrl()\fR" 4
365 .IX Item "EVP_MD_CTX_ctrl()"
366 Returns 1 if successful or 0 for failure.
367 .IP "\fBEVP_MD_CTX_copy_ex()\fR" 4
368 .IX Item "EVP_MD_CTX_copy_ex()"
369 Returns 1 if successful or 0 for failure.
370 .IP "\fBEVP_MD_type()\fR, \fBEVP_MD_pkey_type()\fR" 4
371 .IX Item "EVP_MD_type(), EVP_MD_pkey_type()"
372 Returns the \s-1NID\s0 of the corresponding \s-1OBJECT IDENTIFIER\s0 or NID_undef if none
373 exists.
374 .IP "\fBEVP_MD_size()\fR, \fBEVP_MD_block_size()\fR, \fBEVP_MD_CTX_size()\fR, \fBEVP_MD_CTX_block_size()\fR" 4
375 .IX Item "EVP_MD_size(), EVP_MD_block_size(), EVP_MD_CTX_size(), EVP_MD_CTX_block_size()"
376 Returns the digest or block size in bytes.
377 .IP "\fBEVP_md_null()\fR" 4
378 .IX Item "EVP_md_null()"
379 Returns a pointer to the \fB\s-1EVP_MD\s0\fR structure of the \*(L"null\*(R" message digest.
380 .IP "\fBEVP_get_digestbyname()\fR, \fBEVP_get_digestbynid()\fR, \fBEVP_get_digestbyobj()\fR" 4
381 .IX Item "EVP_get_digestbyname(), EVP_get_digestbynid(), EVP_get_digestbyobj()"
382 Returns either an \fB\s-1EVP_MD\s0\fR structure or \s-1NULL\s0 if an error occurs.
383 .IP "\fBEVP_MD_CTX_set_pkey_ctx()\fR" 4
384 .IX Item "EVP_MD_CTX_set_pkey_ctx()"
385 This function has no return value.
386 .SH "NOTES"
387 .IX Header "NOTES"
388 The \fB\s-1EVP\s0\fR interface to message digests should almost always be used in
389 preference to the low-level interfaces. This is because the code then becomes
390 transparent to the digest used and much more flexible.
391 .PP
392 New applications should use the \s-1SHA\-2\s0 (such as \fBEVP_sha256\fR\|(3)) or the \s-1SHA\-3\s0
393 digest algorithms (such as \fBEVP_sha3_512\fR\|(3)). The other digest algorithms
394 are still in common use.
395 .PP
396 For most applications the \fBimpl\fR parameter to \fBEVP_DigestInit_ex()\fR will be
397 set to \s-1NULL\s0 to use the default digest implementation.
398 .PP
399 The functions \fBEVP_DigestInit()\fR, \fBEVP_DigestFinal()\fR and \fBEVP_MD_CTX_copy()\fR are
400 obsolete but are retained to maintain compatibility with existing code. New
401 applications should use \fBEVP_DigestInit_ex()\fR, \fBEVP_DigestFinal_ex()\fR and
402 \&\fBEVP_MD_CTX_copy_ex()\fR because they can efficiently reuse a digest context
403 instead of initializing and cleaning it up on each call and allow non default
404 implementations of digests to be specified.
405 .PP
406 If digest contexts are not cleaned up after use,
407 memory leaks will occur.
408 .PP
409 \&\fBEVP_MD_CTX_size()\fR, \fBEVP_MD_CTX_block_size()\fR, \fBEVP_MD_CTX_type()\fR,
410 \&\fBEVP_get_digestbynid()\fR and \fBEVP_get_digestbyobj()\fR are defined as
411 macros.
412 .PP
413 \&\fBEVP_MD_CTX_ctrl()\fR sends commands to message digests for additional configuration
414 or control.
415 .SH "EXAMPLES"
416 .IX Header "EXAMPLES"
417 This example digests the data \*(L"Test Message\en\*(R" and \*(L"Hello World\en\*(R", using the
418 digest name passed on the command line.
419 .PP
420 .Vb 3
421 \& #include <stdio.h>
422 \& #include <string.h>
423 \& #include <openssl/evp.h>
424 \&
425 \& int main(int argc, char *argv[])
426 \& {
427 \&     EVP_MD_CTX *mdctx;
428 \&     const EVP_MD *md;
429 \&     char mess1[] = "Test Message\en";
430 \&     char mess2[] = "Hello World\en";
431 \&     unsigned char md_value[EVP_MAX_MD_SIZE];
432 \&     unsigned int md_len, i;
433 \&
434 \&     if (argv[1] == NULL) {
435 \&         printf("Usage: mdtest digestname\en");
436 \&         exit(1);
437 \&     }
438 \&
439 \&     md = EVP_get_digestbyname(argv[1]);
440 \&     if (md == NULL) {
441 \&         printf("Unknown message digest %s\en", argv[1]);
442 \&         exit(1);
443 \&     }
444 \&
445 \&     mdctx = EVP_MD_CTX_new();
446 \&     EVP_DigestInit_ex(mdctx, md, NULL);
447 \&     EVP_DigestUpdate(mdctx, mess1, strlen(mess1));
448 \&     EVP_DigestUpdate(mdctx, mess2, strlen(mess2));
449 \&     EVP_DigestFinal_ex(mdctx, md_value, &md_len);
450 \&     EVP_MD_CTX_free(mdctx);
451 \&
452 \&     printf("Digest is: ");
453 \&     for (i = 0; i < md_len; i++)
454 \&         printf("%02x", md_value[i]);
455 \&     printf("\en");
456 \&
457 \&     exit(0);
458 \& }
459 .Ve
460 .SH "SEE ALSO"
461 .IX Header "SEE ALSO"
462 \&\fBEVP_MD_meth_new\fR\|(3),
463 \&\fBdgst\fR\|(1),
464 \&\fBevp\fR\|(7)
465 .PP
466 The full list of digest algorithms are provided below.
467 .PP
468 \&\fBEVP_blake2b512\fR\|(3),
469 \&\fBEVP_md2\fR\|(3),
470 \&\fBEVP_md4\fR\|(3),
471 \&\fBEVP_md5\fR\|(3),
472 \&\fBEVP_mdc2\fR\|(3),
473 \&\fBEVP_ripemd160\fR\|(3),
474 \&\fBEVP_sha1\fR\|(3),
475 \&\fBEVP_sha224\fR\|(3),
476 \&\fBEVP_sha3_224\fR\|(3),
477 \&\fBEVP_sm3\fR\|(3),
478 \&\fBEVP_whirlpool\fR\|(3)
479 .SH "HISTORY"
480 .IX Header "HISTORY"
481 The \fBEVP_MD_CTX_create()\fR and \fBEVP_MD_CTX_destroy()\fR functions were renamed to
482 \&\fBEVP_MD_CTX_new()\fR and \fBEVP_MD_CTX_free()\fR in OpenSSL 1.1.0, respectively.
483 .PP
484 The link between digests and signing algorithms was fixed in OpenSSL 1.0 and
485 later, so now \fBEVP_sha1()\fR can be used with \s-1RSA\s0 and \s-1DSA.\s0
486 .PP
487 The \fBEVP_dss1()\fR function was removed in OpenSSL 1.1.0.
488 .PP
489 The \fBEVP_MD_CTX_set_pkey_ctx()\fR function was added in 1.1.1.
490 .SH "COPYRIGHT"
491 .IX Header "COPYRIGHT"
492 Copyright 2000\-2020 The OpenSSL Project Authors. All Rights Reserved.
493 .PP
494 Licensed under the OpenSSL license (the \*(L"License\*(R").  You may not use
495 this file except in compliance with the License.  You can obtain a copy
496 in the file \s-1LICENSE\s0 in the source distribution or at
497 <https://www.openssl.org/source/license.html>.