summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/man/EVP_MD_meth_new.3
blob: 8a80cca06eed15f33f9481a7c7d6622a27493c86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
.\" $OpenBSD: EVP_MD_meth_new.3,v 1.5 2023/09/12 16:26:30 schwarze Exp $
.\" selective merge up to:
.\" OpenSSL man3/EVP_MD_meth_new 0388d212 Dec 14 12:47:07 2018 -0800
.\"
.\" This file is a derived work.
.\" The changes are covered by the following Copyright and license:
.\"
.\" Copyright (c) 2023 Ingo Schwarze <schwarze@openbsd.org>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.\" The original file was written by Richard Levitte <levitte@openssl.org>
.\" Copyright (c) 2015 The OpenSSL Project.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\"
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\"
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in
.\"    the documentation and/or other materials provided with the
.\"    distribution.
.\"
.\" 3. All advertising materials mentioning features or use of this
.\"    software must display the following acknowledgment:
.\"    "This product includes software developed by the OpenSSL Project
.\"    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
.\"
.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
.\"    endorse or promote products derived from this software without
.\"    prior written permission. For written permission, please contact
.\"    openssl-core@openssl.org.
.\"
.\" 5. Products derived from this software may not be called "OpenSSL"
.\"    nor may "OpenSSL" appear in their names without prior written
.\"    permission of the OpenSSL Project.
.\"
.\" 6. Redistributions of any form whatsoever must retain the following
.\"    acknowledgment:
.\"    "This product includes software developed by the OpenSSL Project
.\"    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
.\" OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd $Mdocdate: September 12 2023 $
.Dt EVP_MD_METH_NEW 3
.Os
.Sh NAME
.Nm EVP_MD_meth_dup ,
.Nm EVP_MD_meth_new ,
.Nm EVP_MD_meth_free ,
.Nm EVP_MD_meth_set_input_blocksize ,
.Nm EVP_MD_meth_set_result_size ,
.Nm EVP_MD_meth_set_app_datasize ,
.Nm EVP_MD_meth_set_flags ,
.Nm EVP_MD_meth_set_init ,
.Nm EVP_MD_meth_set_update ,
.Nm EVP_MD_meth_set_final ,
.Nm EVP_MD_meth_set_copy ,
.Nm EVP_MD_meth_set_cleanup ,
.Nm EVP_MD_meth_set_ctrl
.Nd Routines to build up EVP_MD methods
.Sh SYNOPSIS
.In openssl/evp.h
.Ft EVP_MD *
.Fo EVP_MD_meth_new
.Fa "int md_type"
.Fa "int pkey_type"
.Fc
.Ft void
.Fo EVP_MD_meth_free
.Fa "EVP_MD *md"
.Fc
.Ft EVP_MD *
.Fo EVP_MD_meth_dup
.Fa "const EVP_MD *md"
.Fc
.Ft int
.Fo EVP_MD_meth_set_input_blocksize
.Fa "EVP_MD *md"
.Fa "int blocksize"
.Fc
.Ft int
.Fo EVP_MD_meth_set_result_size
.Fa "EVP_MD *md"
.Fa "int resultsize"
.Fc
.Ft int
.Fo EVP_MD_meth_set_app_datasize
.Fa "EVP_MD *md"
.Fa "int datasize"
.Fc
.Ft int
.Fo EVP_MD_meth_set_flags
.Fa "EVP_MD *md"
.Fa "unsigned long flags"
.Fc
.Ft int
.Fo EVP_MD_meth_set_init
.Fa "EVP_MD *md"
.Fa "int (*init)(EVP_MD_CTX *ctx)"
.Fc
.Ft int
.Fo EVP_MD_meth_set_update
.Fa "EVP_MD *md"
.Fa "int (*update)(EVP_MD_CTX *ctx, const void *data, size_t count)"
.Fc
.Ft int
.Fo EVP_MD_meth_set_final
.Fa "EVP_MD *md"
.Fa "int (*final)(EVP_MD_CTX *ctx, unsigned char *md)"
.Fc
.Ft int
.Fo EVP_MD_meth_set_copy
.Fa "EVP_MD *md"
.Fa "int (*copy)(EVP_MD_CTX *to, const EVP_MD_CTX *from)"
.Fc
.Ft int
.Fo EVP_MD_meth_set_cleanup
.Fa "EVP_MD *md"
.Fa "int (*cleanup)(EVP_MD_CTX *ctx)"
.Fc
.Ft int
.Fo EVP_MD_meth_set_ctrl
.Fa "EVP_MD *md"
.Fa "int (*control)(EVP_MD_CTX *ctx, int command, int p1, void *p2)"
.Fc
.Sh DESCRIPTION
The
.Vt EVP_MD
type is a structure for digest method implementation.
It can also have associated public/private key signing and verifying
routines.
.Pp
.Fn EVP_MD_meth_new
creates a new
.Vt EVP_MD
structure.
.Pp
.Fn EVP_MD_meth_dup
creates a copy of
.Fa md .
.Pp
.Fn EVP_MD_meth_free
destroys a
.Vt EVP_MD
structure.
.Pp
.Fn EVP_MD_meth_set_input_blocksize
sets the internal input block size for the method
.Fa md
to
.Fa blocksize
bytes.
.Pp
.Fn EVP_MD_meth_set_result_size
sets the size of the result that the digest method in
.Fa md
is expected to produce to
.Fa resultsize
bytes.
.Pp
The digest method may have its own private data, which OpenSSL will
allocate for it.
.Fn EVP_MD_meth_set_app_datasize
should be used to set the size for it to
.Fa datasize .
.Pp
.Fn EVP_MD_meth_set_flags
sets the flags to describe optional behaviours in the particular
.Fa md .
Several flags can be or'd together.
The available flags are:
.Bl -tag -width Ds
.It Dv EVP_MD_FLAG_DIGALGID_NULL
When setting up a
.Vt DigestAlgorithmIdentifier
with
.Xr X509_ALGOR_set_md 3 ,
set the parameter type to
.Dv V_ASN1_NULL
and the parameter value to
.Dv NULL .
This is the default, which means that it takes effect for
.Vt EVP_MD
objects that do not have
.Dv EVP_MD_FLAG_DIGALGID_ABSENT
set.
Use this for PKCS#1.
.It Dv EVP_MD_FLAG_DIGALGID_ABSENT
When setting up a
.Vt DigestAlgorithmIdentifier
with
.Xr X509_ALGOR_set_md 3 ,
set the parameter type to
.Dv V_ASN1_UNDEF
and the parameter value to
.Dv NULL .
This is used by the
.Vt EVP_MD
objects documented in the manual page
.Xr EVP_sha3_224 3
and by the objects returned from
.Xr EVP_sha512 3 ,
.Xr EVP_sha512_256 3 ,
.Xr EVP_sha512_224 3 ,
.Xr EVP_sha384 3 ,
.Xr EVP_sha256 3 ,
.Xr EVP_sha224 3 ,
.Xr EVP_sha1 3 ,
and
.Xr EVP_sm3 3 .
.It Dv EVP_MD_FLAG_DIGALGID_CUSTOM
This flag is reserved for user-defined
.Vt EVP_MD
objects supporting custom
.Vt DigestAlgorithmIdentifier
handling via
.Xr EVP_MD_CTX_ctrl 3 ,
but actually, it is ignored by both LibreSSL and OpenSSL
and such user-defined behaviour is not supported by the libraries.
.It Dv EVP_MD_FLAG_FIPS
Mark the digest method as suitable for FIPS mode.
This flag is ignored by both LibreSSL and OpenSSL.
.It Dv EVP_MD_FLAG_ONESHOT
Intended to indicate that the digest method can only handle one block
of input, but actually, this flag is ignored by both LibreSSL and OpenSSL.
.El
.Pp
.Fn EVP_MD_meth_set_init
sets the digest init function for
.Fa md .
The digest init function is called by
.Xr EVP_Digest 3 ,
.Xr EVP_DigestInit 3 ,
.Xr EVP_DigestInit_ex 3 ,
EVP_SignInit,
.Xr EVP_SignInit_ex 3 ,
.Xr EVP_VerifyInit 3
and
.Xr EVP_VerifyInit_ex 3 .
.Pp
.Fn EVP_MD_meth_set_update
sets the digest update function for
.Fa md .
The digest update function is called by
.Xr EVP_Digest 3 ,
.Xr EVP_DigestUpdate 3
and
.Xr EVP_SignUpdate 3 .
.Pp
.Fn EVP_MD_meth_set_final
sets the digest final function for
.Fa md .
The digest final function is called by
.Xr EVP_Digest 3 ,
.Xr EVP_DigestFinal 3 ,
.Xr EVP_DigestFinal_ex 3 ,
.Xr EVP_SignFinal 3
and
.Xr EVP_VerifyFinal 3 .
.Pp
.Fn EVP_MD_meth_set_copy
sets the function for
.Fa md
to do extra computations after the method's private data structure has
been copied from one
.Vt EVP_MD_CTX
object to another.
If all that's needed is to copy the data, there is no need for this copy
function.
The copy function is passed two
.Vt EVP_MD_CTX
objects, the private data structure is then available with
.Xr EVP_MD_CTX_md_data 3 .
This copy function is called by
.Xr EVP_MD_CTX_copy 3
and
.Xr EVP_MD_CTX_copy_ex 3 .
.Pp
.Fn EVP_MD_meth_set_cleanup
sets the function for
.Fa md
to do extra cleanup before the method's private data structure is
cleaned out and freed.
The cleanup function is passed an
.Vt EVP_MD_CTX
object, the private data structure is then available with
.Xr EVP_MD_CTX_md_data 3 .
This cleanup function is called by
.Xr EVP_MD_CTX_reset 3
and
.Xr EVP_MD_CTX_free 3 .
.Pp
.Fn EVP_MD_meth_set_ctrl
sets the
.Fa control
function for
.Fa md .
The
.Fa control
function supplied by the application program has to return 1 to indicate
success, 0 to indicate failure, or \-1 if the
.Fa command
is not supported for this digest method.
See
.Xr EVP_MD_CTX_ctrl 3
for the available
.Fa command
arguments.
.Sh RETURN VALUES
.Fn EVP_MD_meth_new
and
.Fn EVP_MD_meth_dup
return a pointer to a newly created
.Vt EVP_MD ,
or NULL on failure.
All
.Fn EVP_MD_meth_set_*
functions return 1.
.Sh SEE ALSO
.Xr EVP_DigestInit 3 ,
.Xr EVP_SignInit 3 ,
.Xr EVP_VerifyInit 3
.Sh HISTORY
All these functions
first appeared in OpenSSL 1.1.0 and have been available since
.Ox 7.1 .