1PROVIDER-DIGEST(7ossl) OpenSSL PROVIDER-DIGEST(7ossl)
2
3
4
6 provider-digest - The digest library <-> provider functions
7
9 #include <openssl/core_dispatch.h>
10 #include <openssl/core_names.h>
11
12 /*
13 * Digests support the following function signatures in OSSL_DISPATCH arrays.
14 * (The function signatures are not actual functions).
15 */
16
17 /* Context management */
18 void *OSSL_FUNC_digest_newctx(void *provctx);
19 void OSSL_FUNC_digest_freectx(void *dctx);
20 void *OSSL_FUNC_digest_dupctx(void *dctx);
21
22 /* Digest generation */
23 int OSSL_FUNC_digest_init(void *dctx, const OSSL_PARAM params[]);
24 int OSSL_FUNC_digest_update(void *dctx, const unsigned char *in, size_t inl);
25 int OSSL_FUNC_digest_final(void *dctx, unsigned char *out, size_t *outl,
26 size_t outsz);
27 int OSSL_FUNC_digest_digest(void *provctx, const unsigned char *in, size_t inl,
28 unsigned char *out, size_t *outl, size_t outsz);
29
30 /* Digest parameter descriptors */
31 const OSSL_PARAM *OSSL_FUNC_digest_gettable_params(void *provctx);
32
33 /* Digest operation parameter descriptors */
34 const OSSL_PARAM *OSSL_FUNC_digest_gettable_ctx_params(void *dctx,
35 void *provctx);
36 const OSSL_PARAM *OSSL_FUNC_digest_settable_ctx_params(void *dctx,
37 void *provctx);
38
39 /* Digest parameters */
40 int OSSL_FUNC_digest_get_params(OSSL_PARAM params[]);
41
42 /* Digest operation parameters */
43 int OSSL_FUNC_digest_set_ctx_params(void *dctx, const OSSL_PARAM params[]);
44 int OSSL_FUNC_digest_get_ctx_params(void *dctx, OSSL_PARAM params[]);
45
47 This documentation is primarily aimed at provider authors. See
48 provider(7) for further information.
49
50 The DIGEST operation enables providers to implement digest algorithms
51 and make them available to applications via the API functions
52 EVP_DigestInit_ex(3), EVP_DigestUpdate(3) and EVP_DigestFinal(3) (and
53 other related functions).
54
55 All "functions" mentioned here are passed as function pointers between
56 libcrypto and the provider in OSSL_DISPATCH(3) arrays via
57 OSSL_ALGORITHM(3) arrays that are returned by the provider's
58 provider_query_operation() function (see "Provider Functions" in
59 provider-base(7)).
60
61 All these "functions" have a corresponding function type definition
62 named OSSL_FUNC_{name}_fn, and a helper function to retrieve the
63 function pointer from an OSSL_DISPATCH(3) element named
64 OSSL_FUNC_{name}. For example, the "function"
65 OSSL_FUNC_digest_newctx() has these:
66
67 typedef void *(OSSL_FUNC_digest_newctx_fn)(void *provctx);
68 static ossl_inline OSSL_FUNC_digest_newctx_fn
69 OSSL_FUNC_digest_newctx(const OSSL_DISPATCH *opf);
70
71 OSSL_DISPATCH(3) arrays are indexed by numbers that are provided as
72 macros in openssl-core_dispatch.h(7), as follows:
73
74 OSSL_FUNC_digest_newctx OSSL_FUNC_DIGEST_NEWCTX
75 OSSL_FUNC_digest_freectx OSSL_FUNC_DIGEST_FREECTX
76 OSSL_FUNC_digest_dupctx OSSL_FUNC_DIGEST_DUPCTX
77
78 OSSL_FUNC_digest_init OSSL_FUNC_DIGEST_INIT
79 OSSL_FUNC_digest_update OSSL_FUNC_DIGEST_UPDATE
80 OSSL_FUNC_digest_final OSSL_FUNC_DIGEST_FINAL
81 OSSL_FUNC_digest_digest OSSL_FUNC_DIGEST_DIGEST
82
83 OSSL_FUNC_digest_get_params OSSL_FUNC_DIGEST_GET_PARAMS
84 OSSL_FUNC_digest_get_ctx_params OSSL_FUNC_DIGEST_GET_CTX_PARAMS
85 OSSL_FUNC_digest_set_ctx_params OSSL_FUNC_DIGEST_SET_CTX_PARAMS
86
87 OSSL_FUNC_digest_gettable_params OSSL_FUNC_DIGEST_GETTABLE_PARAMS
88 OSSL_FUNC_digest_gettable_ctx_params OSSL_FUNC_DIGEST_GETTABLE_CTX_PARAMS
89 OSSL_FUNC_digest_settable_ctx_params OSSL_FUNC_DIGEST_SETTABLE_CTX_PARAMS
90
91 A digest algorithm implementation may not implement all of these
92 functions. In order to be usable all or none of
93 OSSL_FUNC_digest_newctx, OSSL_FUNC_digest_freectx,
94 OSSL_FUNC_digest_init, OSSL_FUNC_digest_update and
95 OSSL_FUNC_digest_final should be implemented. All other functions are
96 optional.
97
98 Context Management Functions
99 OSSL_FUNC_digest_newctx() should create and return a pointer to a
100 provider side structure for holding context information during a digest
101 operation. A pointer to this context will be passed back in a number
102 of the other digest operation function calls. The parameter provctx is
103 the provider context generated during provider initialisation (see
104 provider(7)).
105
106 OSSL_FUNC_digest_freectx() is passed a pointer to the provider side
107 digest context in the dctx parameter. This function should free any
108 resources associated with that context.
109
110 OSSL_FUNC_digest_dupctx() should duplicate the provider side digest
111 context in the dctx parameter and return the duplicate copy.
112
113 Digest Generation Functions
114 OSSL_FUNC_digest_init() initialises a digest operation given a newly
115 created provider side digest context in the dctx parameter. The
116 params, if not NULL, should be set on the context in a manner similar
117 to using OSSL_FUNC_digest_set_ctx_params().
118
119 OSSL_FUNC_digest_update() is called to supply data to be digested as
120 part of a previously initialised digest operation. The dctx parameter
121 contains a pointer to a previously initialised provider side context.
122 OSSL_FUNC_digest_update() should digest inl bytes of data at the
123 location pointed to by in. OSSL_FUNC_digest_update() may be called
124 multiple times for a single digest operation.
125
126 OSSL_FUNC_digest_final() generates a digest started through previous
127 OSSL_FUNC_digest_init() and OSSL_FUNC_digest_update() calls. The dctx
128 parameter contains a pointer to the provider side context. The digest
129 should be written to *out and the length of the digest to *outl. The
130 digest should not exceed outsz bytes.
131
132 OSSL_FUNC_digest_digest() is a "oneshot" digest function. No provider
133 side digest context is used. Instead the provider context that was
134 created during provider initialisation is passed in the provctx
135 parameter (see provider(7)). inl bytes at in should be digested and
136 the result should be stored at out. The length of the digest should be
137 stored in *outl which should not exceed outsz bytes.
138
139 Digest Parameters
140 See OSSL_PARAM(3) for further details on the parameters structure used
141 by these functions.
142
143 OSSL_FUNC_digest_get_params() gets details of the algorithm
144 implementation and stores them in params.
145
146 OSSL_FUNC_digest_set_ctx_params() sets digest operation parameters for
147 the provider side digest context dctx to params. Any parameter
148 settings are additional to any that were previously set. Passing NULL
149 for params should return true.
150
151 OSSL_FUNC_digest_get_ctx_params() gets digest operation details details
152 from the given provider side digest context dctx and stores them in
153 params. Passing NULL for params should return true.
154
155 OSSL_FUNC_digest_gettable_params() returns a constant OSSL_PARAM(3)
156 array containing descriptors of the parameters that
157 OSSL_FUNC_digest_get_params() can handle.
158
159 OSSL_FUNC_digest_gettable_ctx_params() and
160 OSSL_FUNC_digest_settable_ctx_params() both return constant
161 OSSL_PARAM(3) arrays as descriptors of the parameters that
162 OSSL_FUNC_digest_get_ctx_params() and OSSL_FUNC_digest_set_ctx_params()
163 can handle, respectively. The array is based on the current state of
164 the provider side context if dctx is not NULL and on the provider side
165 algorithm provctx otherwise.
166
167 Parameters currently recognised by built-in digests with this function
168 are as follows. Not all parameters are relevant to, or are understood
169 by all digests:
170
171 "blocksize" (OSSL_DIGEST_PARAM_BLOCK_SIZE) <unsigned integer>
172 The digest block size. The length of the "blocksize" parameter
173 should not exceed that of a size_t.
174
175 "size" (OSSL_DIGEST_PARAM_SIZE) <unsigned integer>
176 The digest output size. The length of the "size" parameter should
177 not exceed that of a size_t.
178
179 "flags" (OSSL_DIGEST_PARAM_FLAGS) <unsigned integer>
180 Diverse flags that describe exceptional behaviour for the digest:
181
182 EVP_MD_FLAG_ONESHOT
183 This digest method can only handle one block of input.
184
185 EVP_MD_FLAG_XOF
186 This digest method is an extensible-output function (XOF) and
187 supports setting the OSSL_DIGEST_PARAM_XOFLEN parameter.
188
189 EVP_MD_FLAG_DIGALGID_NULL
190 When setting up a DigestAlgorithmIdentifier, this flag will
191 have the parameter set to NULL by default. Use this for
192 PKCS#1. Note: if combined with EVP_MD_FLAG_DIGALGID_ABSENT,
193 the latter will override.
194
195 EVP_MD_FLAG_DIGALGID_ABSENT
196 When setting up a DigestAlgorithmIdentifier, this flag will
197 have the parameter be left absent by default. Note: if
198 combined with EVP_MD_FLAG_DIGALGID_NULL, the latter will be
199 overridden.
200
201 EVP_MD_FLAG_DIGALGID_CUSTOM
202 Custom DigestAlgorithmIdentifier handling via ctrl, with
203 EVP_MD_FLAG_DIGALGID_ABSENT as default. Note: if combined with
204 EVP_MD_FLAG_DIGALGID_NULL, the latter will be overridden.
205 Currently unused.
206
207 The length of the "flags" parameter should equal that of an
208 unsigned long int.
209
210 Digest Context Parameters
211 OSSL_FUNC_digest_set_ctx_params() sets digest parameters associated
212 with the given provider side digest context dctx to params. Any
213 parameter settings are additional to any that were previously set. See
214 OSSL_PARAM(3) for further details on the parameters structure.
215
216 OSSL_FUNC_digest_get_ctx_params() gets details of currently set
217 parameters values associated with the give provider side digest context
218 dctx and stores them in params. See OSSL_PARAM(3) for further details
219 on the parameters structure.
220
222 OSSL_FUNC_digest_newctx() and OSSL_FUNC_digest_dupctx() should return
223 the newly created provider side digest context, or NULL on failure.
224
225 OSSL_FUNC_digest_init(), OSSL_FUNC_digest_update(),
226 OSSL_FUNC_digest_final(), OSSL_FUNC_digest_digest(),
227 OSSL_FUNC_digest_set_params() and OSSL_FUNC_digest_get_params() should
228 return 1 for success or 0 on error.
229
230 OSSL_FUNC_digest_size() should return the digest size.
231
232 OSSL_FUNC_digest_block_size() should return the block size of the
233 underlying digest algorithm.
234
236 The EVP_Q_digest(), EVP_Digest() and EVP_DigestFinal_ex() API calls do
237 not expect the digest size to be larger than EVP_MAX_MD_SIZE. Any
238 algorithm which produces larger digests is unusable with those API
239 calls.
240
242 provider(7), OSSL_PROVIDER-FIPS(7), OSSL_PROVIDER-default(7),
243 OSSL_PROVIDER-legacy(7), EVP_MD-common(7), EVP_MD-BLAKE2(7),
244 EVP_MD-MD2(7), EVP_MD-MD4(7), EVP_MD-MD5(7), EVP_MD-MD5-SHA1(7),
245 EVP_MD-MDC2(7), EVP_MD-RIPEMD160(7), EVP_MD-SHA1(7), EVP_MD-SHA2(7),
246 EVP_MD-SHA3(7), EVP_MD-SHAKE(7), EVP_MD-SM3(7), EVP_MD-WHIRLPOOL(7),
247 EVP_MD-NULL(7), life_cycle-digest(7), EVP_DigestInit(3)
248
250 The provider DIGEST interface was introduced in OpenSSL 3.0.
251
253 Copyright 2019-2023 The OpenSSL Project Authors. All Rights Reserved.
254
255 Licensed under the Apache License 2.0 (the "License"). You may not use
256 this file except in compliance with the License. You can obtain a copy
257 in the file LICENSE in the source distribution or at
258 <https://www.openssl.org/source/license.html>.
259
260
261
2623.0.9 2023-07-27 PROVIDER-DIGEST(7ossl)