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