Add missing EVP param utility functions
[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 comment multiple includes
10
11  #include <openssl/core_numbers.h>
12  #include <openssl/core_names.h>
13
14  /*
15   * None of these are actual functions, but are displayed like this for
16   * the function signatures for functions that are offered as function
17   * pointers in OSSL_DISPATCH arrays.
18   */
19
20  /* Context management */
21  void *OP_digest_newctx(void *provctx);
22  void OP_digest_freectx(void *dctx);
23  void *OP_digest_dupctx(void *dctx);
24
25  /* Digest generation */
26  int OP_digest_init(void *dctx);
27  int OP_digest_update(void *dctx, const unsigned char *in, size_t inl);
28  int OP_digest_final(void *dctx, unsigned char *out, size_t *outl,
29                      size_t outsz);
30  int OP_digest_digest(void *provctx, const unsigned char *in, size_t inl,
31                       unsigned char *out, size_t *outl, size_t outsz);
32
33  /* Digest parameter descriptors */
34  const OSSL_PARAM *OP_cipher_gettable_params(void);
35
36  /* Digest operation parameter descriptors */
37  const OSSL_PARAM *OP_cipher_gettable_ctx_params(void);
38  const OSSL_PARAM *OP_cipher_settable_ctx_params(void);
39
40  /* Digest parameters */
41  int OP_digest_get_params(OSSL_PARAM params[]);
42
43  /* Digest operation parameters */
44  int OP_digest_ctx_set_params(void *dctx, const OSSL_PARAM params[]);
45  int OP_digest_ctx_get_params(void *dctx, OSSL_PARAM params[]);
46
47 =head1 DESCRIPTION
48
49 This documentation is primarily aimed at provider authors. See L<provider(7)>
50 for further information.
51
52 The DIGEST operation enables providers to implement digest algorithms and make
53 them available to applications via the API functions L<EVP_DigestInit_ex(3)>,
54 L<EVP_DigestUpdate(3)> and L<EVP_DigestFinal(3)> (and other related functions).
55
56 All "functions" mentioned here are passed as function pointers between
57 F<libcrypto> and the provider in B<OSSL_DISPATCH> arrays via
58 B<OSSL_ALGORITHM> arrays that are returned by the provider's
59 provider_query_operation() function
60 (see L<provider-base(7)/Provider Functions>).
61
62 All these "functions" have a corresponding function type definition
63 named B<OSSL_{name}_fn>, and a helper function to retrieve the
64 function pointer from an B<OSSL_DISPATCH> element named
65 B<OSSL_get_{name}>.
66 For example, the "function" OP_digest_newctx() has these:
67
68  typedef void *(OSSL_OP_digest_newctx_fn)(void *provctx);
69  static ossl_inline OSSL_OP_digest_newctx_fn
70      OSSL_get_OP_digest_newctx(const OSSL_DISPATCH *opf);
71
72 B<OSSL_DISPATCH> arrays are indexed by numbers that are provided as
73 macros in L<openssl-core_numbers.h(7)>, as follows:
74
75  OP_digest_newctx               OSSL_FUNC_DIGEST_NEWCTX
76  OP_digest_freectx              OSSL_FUNC_DIGEST_FREECTX
77  OP_digest_dupctx               OSSL_FUNC_DIGEST_DUPCTX
78
79  OP_digest_init                 OSSL_FUNC_DIGEST_INIT
80  OP_digest_update               OSSL_FUNC_DIGEST_UPDATE
81  OP_digest_final                OSSL_FUNC_DIGEST_FINAL
82  OP_digest_digest               OSSL_FUNC_DIGEST_DIGEST
83
84  OP_digest_get_params           OSSL_FUNC_DIGEST_GET_PARAMS
85  OP_digest_ctx_get_params       OSSL_FUNC_DIGEST_CTX_GET_PARAMS
86  OP_digest_ctx_set_params       OSSL_FUNC_DIGEST_CTX_SET_PARAMS
87
88  OP_digest_gettable_params      OSSL_FUNC_DIGEST_GETTABLE_PARAMS
89  OP_digest_gettable_ctx_params  OSSL_FUNC_DIGEST_GETTABLE_CTX_PARAMS
90  OP_digest_settable_ctx_params  OSSL_FUNC_DIGEST_SETTABLE_CTX_PARAMS
91
92 A digest algorithm implementation may not implement all of these functions.
93 In order to be useable all or none of OP_digest_newctx, OP_digest_freectx,
94 OP_digest_init, OP_digest_update and OP_digest_final should be implemented.
95 All other functions are optional.
96
97 =head2 Context Management Functions
98
99 OP_digest_newctx() should create and return a pointer to a provider side
100 structure for holding context information during a digest operation.
101 A pointer to this context will be passed back in a number of the other digest
102 operation function calls.
103 The paramater B<provctx> is the provider context generated during provider
104 initialisation (see L<provider(3)>).
105
106 OP_digest_freectx() is passed a pointer to the provider side digest context in
107 the B<dctx> parameter.
108 This function should free any resources associated with that context.
109
110 OP_digest_dupctx() should duplicate the provider side digest context in the
111 B<dctx> parameter and return the duplicate copy.
112
113 =head2 Digest Generation Functions
114
115 OP_digest_init() initialises a digest operation given a newly created
116 provider side digest context in the B<dctx> paramter.
117
118 OP_digest_update() is called to supply data to be digested as part of a
119 previously initialised digest operation.
120 The B<dctx> parameter contains a pointer to a previously initialised provider
121 side context.
122 OP_digest_update() should digest B<inl> bytes of data at the location pointed to
123 by B<in>.
124 OP_digest_update() may be called multiple times for a single digest operation.
125
126 OP_digest_final() generates a digest started through previous OP_digest_init()
127 and OP_digest_update() calls.
128 The B<dctx> parameter contains a pointer to the provider side context.
129 The digest should be written to B<*out> and the length of the digest to
130 B<*outl>.
131 The digest should not exceed B<outsz> bytes.
132
133 OP_digest_digest() is a "oneshot" digest function.
134 No provider side digest context is used.
135 Instead the provider context that was created during provider initialisation is
136 passed in the B<provctx> parameter (see L<provider(3)>).
137 B<inl> bytes at B<in> should be digested and the result should be stored at
138 B<out>. The length of the digest should be stored in B<*outl> which should not
139 exceed B<outsz> bytes.
140
141 =head2 Digest Parameters
142
143 See L<OSSL_PARAM(3)> for further details on the parameters structure used by
144 these functions.
145
146 OP_digest_get_params() gets details of the algorithm implementation
147 and stores them in B<params>.
148
149 OP_digest_ctx_set_params() sets digest operation parameters for the
150 provider side digest context B<dctx> to B<params>.
151 Any parameter settings are additional to any that were previously set.
152
153 OP_digest_ctx_get_params() gets digest operation details details from
154 the given provider side digest context B<dctx> and stores them in B<params>.
155
156 OP_digest_gettable_params(), OP_digest_gettable_ctx_params(), and
157 OP_digest_settable_ctx_params() all return constant B<OSSL_PARAM> arrays
158 as descriptors of the parameters that OP_digest_get_params(),
159 OP_digest_ctx_get_params(), and OP_digest_ctx_set_params() can handle,
160 respectively.
161
162 Parameters currently recognised by built-in digests with this function
163 are as follows. Not all parametes are relevant to, or are understood
164 by all digests:
165
166 =over 4
167
168 =item B<OSSL_DIGEST_PARAM_BLOCK_SIZE> (int)
169
170 The digest block size.
171
172 =item B<OSSL_DIGEST_PARAM_SIZE> (int)
173
174 The digest output size.
175
176 =item B<OSSL_DIGEST_PARAM_FLAGS> (unsigned long)
177
178 Diverse flags that describe exceptional behaviour for the digest:
179
180 =over 4
181
182 =item B<EVP_MD_FLAG_ONESHOT>
183
184 This digest method can only handle one block of input.
185
186 =item B<EVP_MD_FLAG_XOF>
187
188 This digest method is an extensible-output function (XOF) and supports
189 setting the B<OSSL_DIGEST_PARAM_XOFLEN> parameter.
190
191 =item B<EVP_MD_FLAG_DIGALGID_NULL>
192
193 When setting up a DigestAlgorithmIdentifier, this flag will have the
194 parameter set to NULL by default.  Use this for PKCS#1.  I<Note: if
195 combined with EVP_MD_FLAG_DIGALGID_ABSENT, the latter will override.>
196
197 =item B<EVP_MD_FLAG_DIGALGID_ABSENT>
198
199 When setting up a DigestAlgorithmIdentifier, this flag will have the
200 parameter be left absent by default.  I<Note: if combined with
201 EVP_MD_FLAG_DIGALGID_NULL, the latter will be overridden.>
202
203 =item B<EVP_MD_FLAG_DIGALGID_CUSTOM>
204
205 Custom DigestAlgorithmIdentifier handling via ctrl, with
206 B<EVP_MD_FLAG_DIGALGID_ABSENT> as default.  I<Note: if combined with
207 EVP_MD_FLAG_DIGALGID_NULL, the latter will be overridden.>
208 Currently unused.
209
210 =back
211
212 =back
213
214 =head2 Digest Context Parameters
215
216 OP_digest_ctx_set_params() sets digest parameters associated with the
217 given provider side digest context B<dctx> to B<params>.
218 Any parameter settings are additional to any that were previously set.
219 See L<OSSL_PARAM(3)> for further details on the parameters structure.
220
221 OP_digest_ctx_get_params() gets details of currently set parameters
222 values associated with the give provider side digest context B<dctx>
223 and stores them in B<params>.
224 See L<OSSL_PARAM(3)> for further details on the parameters structure.
225
226 Parameters currently recognised by built-in digests are as follows. Not all
227 parametes are relevant to, or are understood by all digests:
228
229 =over 4
230
231 =item B<OSSL_DIGEST_PARAM_XOFLEN> (size_t)
232
233 Sets the digest length for extendable output functions.
234
235 =item B<OSSL_DIGEST_PARAM_SSL3_MS> (octet string)
236
237 This parameter is set by libssl in order to calculate a signature hash for an
238 SSLv3 CertificateVerify message as per RFC6101.
239 It is only set after all handshake messages have already been digested via
240 OP_digest_update() calls.
241 The parameter provides the master secret value to be added to the digest.
242 The digest implementation should calculate the complete digest as per RFC6101
243 section 5.6.8.
244 The next call after setting this parameter will be OP_digest_final().
245 This is only relevant for implementations of SHA1 or MD5_SHA1.
246
247 =item B<OSSL_DIGEST_PARAM_PAD_TYPE> (int)
248
249 Sets the pad type to be used.
250 The only built-in digest that uses this is MDC2.
251 Normally the final MDC2 block is padded with 0s.
252 If the pad type is set to 2 then the final block is padded with 0x80 followed by
253 0s.
254
255 =item B<OSSL_DIGEST_PARAM_MICALG> (utf8 string)
256
257 Gets the digest Message Integrity Check algorithm string.
258 This is used when creating S/MIME multipart/signed messages, as specified in
259 RFC 5751.
260
261 =back
262
263 =head1 RETURN VALUES
264
265 OP_digest_newctx() and OP_digest_dupctx() should return the newly created
266 provider side digest context, or NULL on failure.
267
268 OP_digest_init(), OP_digest_update(), OP_digest_final(), OP_digest_digest(),
269 OP_digest_set_params() and OP_digest_get_params() should return 1 for success or
270 0 on error.
271
272 OP_digest_size() should return the digest size.
273
274 OP_digest_block_size() should return the block size of the underlying digest
275 algorithm.
276
277 =head1 SEE ALSO
278
279 L<provider(7)>
280
281 =head1 HISTORY
282
283 The provider DIGEST interface was introduced in OpenSSL 3.0.
284
285 =head1 COPYRIGHT
286
287 Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
288
289 Licensed under the Apache License 2.0 (the "License").  You may not use
290 this file except in compliance with the License.  You can obtain a copy
291 in the file LICENSE in the source distribution or at
292 L<https://www.openssl.org/source/license.html>.
293
294 =cut