1PROVIDER-SIGNATURE(7ossl) OpenSSL PROVIDER-SIGNATURE(7ossl)
2
3
4
6 provider-signature - The signature library <-> provider functions
7
9 #include <openssl/core_dispatch.h>
10 #include <openssl/core_names.h>
11
12 /*
13 * None of these are actual functions, but are displayed like this for
14 * the function signatures for functions that are offered as function
15 * pointers in OSSL_DISPATCH arrays.
16 */
17
18 /* Context management */
19 void *OSSL_FUNC_signature_newctx(void *provctx, const char *propq);
20 void OSSL_FUNC_signature_freectx(void *ctx);
21 void *OSSL_FUNC_signature_dupctx(void *ctx);
22
23 /* Signing */
24 int OSSL_FUNC_signature_sign_init(void *ctx, void *provkey,
25 const OSSL_PARAM params[]);
26 int OSSL_FUNC_signature_sign(void *ctx, unsigned char *sig, size_t *siglen,
27 size_t sigsize, const unsigned char *tbs, size_t tbslen);
28
29 /* Verifying */
30 int OSSL_FUNC_signature_verify_init(void *ctx, void *provkey,
31 const OSSL_PARAM params[]);
32 int OSSL_FUNC_signature_verify(void *ctx, const unsigned char *sig, size_t siglen,
33 const unsigned char *tbs, size_t tbslen);
34
35 /* Verify Recover */
36 int OSSL_FUNC_signature_verify_recover_init(void *ctx, void *provkey,
37 const OSSL_PARAM params[]);
38 int OSSL_FUNC_signature_verify_recover(void *ctx, unsigned char *rout,
39 size_t *routlen, size_t routsize,
40 const unsigned char *sig, size_t siglen);
41
42 /* Digest Sign */
43 int OSSL_FUNC_signature_digest_sign_init(void *ctx, const char *mdname,
44 void *provkey,
45 const OSSL_PARAM params[]);
46 int OSSL_FUNC_signature_digest_sign_update(void *ctx, const unsigned char *data,
47 size_t datalen);
48 int OSSL_FUNC_signature_digest_sign_final(void *ctx, unsigned char *sig,
49 size_t *siglen, size_t sigsize);
50 int OSSL_FUNC_signature_digest_sign(void *ctx,
51 unsigned char *sigret, size_t *siglen,
52 size_t sigsize, const unsigned char *tbs,
53 size_t tbslen);
54
55 /* Digest Verify */
56 int OSSL_FUNC_signature_digest_verify_init(void *ctx, const char *mdname,
57 void *provkey,
58 const OSSL_PARAM params[]);
59 int OSSL_FUNC_signature_digest_verify_update(void *ctx,
60 const unsigned char *data,
61 size_t datalen);
62 int OSSL_FUNC_signature_digest_verify_final(void *ctx, const unsigned char *sig,
63 size_t siglen);
64 int OSSL_FUNC_signature_digest_verify(void *ctx, const unsigned char *sig,
65 size_t siglen, const unsigned char *tbs,
66 size_t tbslen);
67
68 /* Signature parameters */
69 int OSSL_FUNC_signature_get_ctx_params(void *ctx, OSSL_PARAM params[]);
70 const OSSL_PARAM *OSSL_FUNC_signature_gettable_ctx_params(void *ctx,
71 void *provctx);
72 int OSSL_FUNC_signature_set_ctx_params(void *ctx, const OSSL_PARAM params[]);
73 const OSSL_PARAM *OSSL_FUNC_signature_settable_ctx_params(void *ctx,
74 void *provctx);
75 /* MD parameters */
76 int OSSL_FUNC_signature_get_ctx_md_params(void *ctx, OSSL_PARAM params[]);
77 const OSSL_PARAM * OSSL_FUNC_signature_gettable_ctx_md_params(void *ctx);
78 int OSSL_FUNC_signature_set_ctx_md_params(void *ctx, const OSSL_PARAM params[]);
79 const OSSL_PARAM * OSSL_FUNC_signature_settable_ctx_md_params(void *ctx);
80
82 This documentation is primarily aimed at provider authors. See
83 provider(7) for further information.
84
85 The signature (OSSL_OP_SIGNATURE) operation enables providers to
86 implement signature algorithms and make them available to applications
87 via the API functions EVP_PKEY_sign(3), EVP_PKEY_verify(3), and
88 EVP_PKEY_verify_recover(3) (as well as other related functions).
89
90 All "functions" mentioned here are passed as function pointers between
91 libcrypto and the provider in OSSL_DISPATCH arrays via OSSL_ALGORITHM
92 arrays that are returned by the provider's provider_query_operation()
93 function (see "Provider Functions" in provider-base(7)).
94
95 All these "functions" have a corresponding function type definition
96 named OSSL_FUNC_{name}_fn, and a helper function to retrieve the
97 function pointer from an OSSL_DISPATCH element named OSSL_FUNC_{name}.
98 For example, the "function" OSSL_FUNC_signature_newctx() has these:
99
100 typedef void *(OSSL_FUNC_signature_newctx_fn)(void *provctx, const char *propq);
101 static ossl_inline OSSL_FUNC_signature_newctx_fn
102 OSSL_FUNC_signature_newctx(const OSSL_DISPATCH *opf);
103
104 OSSL_DISPATCH arrays are indexed by numbers that are provided as macros
105 in openssl-core_dispatch.h(7), as follows:
106
107 OSSL_FUNC_signature_newctx OSSL_FUNC_SIGNATURE_NEWCTX
108 OSSL_FUNC_signature_freectx OSSL_FUNC_SIGNATURE_FREECTX
109 OSSL_FUNC_signature_dupctx OSSL_FUNC_SIGNATURE_DUPCTX
110
111 OSSL_FUNC_signature_sign_init OSSL_FUNC_SIGNATURE_SIGN_INIT
112 OSSL_FUNC_signature_sign OSSL_FUNC_SIGNATURE_SIGN
113
114 OSSL_FUNC_signature_verify_init OSSL_FUNC_SIGNATURE_VERIFY_INIT
115 OSSL_FUNC_signature_verify OSSL_FUNC_SIGNATURE_VERIFY
116
117 OSSL_FUNC_signature_verify_recover_init OSSL_FUNC_SIGNATURE_VERIFY_RECOVER_INIT
118 OSSL_FUNC_signature_verify_recover OSSL_FUNC_SIGNATURE_VERIFY_RECOVER
119
120 OSSL_FUNC_signature_digest_sign_init OSSL_FUNC_SIGNATURE_DIGEST_SIGN_INIT
121 OSSL_FUNC_signature_digest_sign_update OSSL_FUNC_SIGNATURE_DIGEST_SIGN_UPDATE
122 OSSL_FUNC_signature_digest_sign_final OSSL_FUNC_SIGNATURE_DIGEST_SIGN_FINAL
123 OSSL_FUNC_signature_digest_sign OSSL_FUNC_SIGNATURE_DIGEST_SIGN
124
125 OSSL_FUNC_signature_digest_verify_init OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_INIT
126 OSSL_FUNC_signature_digest_verify_update OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_UPDATE
127 OSSL_FUNC_signature_digest_verify_final OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_FINAL
128 OSSL_FUNC_signature_digest_verify OSSL_FUNC_SIGNATURE_DIGEST_VERIFY
129
130 OSSL_FUNC_signature_get_ctx_params OSSL_FUNC_SIGNATURE_GET_CTX_PARAMS
131 OSSL_FUNC_signature_gettable_ctx_params OSSL_FUNC_SIGNATURE_GETTABLE_CTX_PARAMS
132 OSSL_FUNC_signature_set_ctx_params OSSL_FUNC_SIGNATURE_SET_CTX_PARAMS
133 OSSL_FUNC_signature_settable_ctx_params OSSL_FUNC_SIGNATURE_SETTABLE_CTX_PARAMS
134
135 OSSL_FUNC_signature_get_ctx_md_params OSSL_FUNC_SIGNATURE_GET_CTX_MD_PARAMS
136 OSSL_FUNC_signature_gettable_ctx_md_params OSSL_FUNC_SIGNATURE_GETTABLE_CTX_MD_PARAMS
137 OSSL_FUNC_signature_set_ctx_md_params OSSL_FUNC_SIGNATURE_SET_CTX_MD_PARAMS
138 OSSL_FUNC_signature_settable_ctx_md_params OSSL_FUNC_SIGNATURE_SETTABLE_CTX_MD_PARAMS
139
140 A signature algorithm implementation may not implement all of these
141 functions. In order to be a consistent set of functions we must have
142 at least a set of context functions (OSSL_FUNC_signature_newctx and
143 OSSL_FUNC_signature_freectx) as well as a set of "signature" functions,
144 i.e. at least one of:
145
146 OSSL_FUNC_signature_sign_init and OSSL_FUNC_signature_sign
147 OSSL_FUNC_signature_verify_init and OSSL_FUNC_signature_verify
148 OSSL_FUNC_signature_verify_recover_init and
149 OSSL_FUNC_signature_verify_init
150 OSSL_FUNC_signature_digest_sign_init,
151 OSSL_FUNC_signature_digest_sign_update and
152 OSSL_FUNC_signature_digest_sign_final
153 OSSL_FUNC_signature_digest_verify_init,
154 OSSL_FUNC_signature_digest_verify_update and
155 OSSL_FUNC_signature_digest_verify_final
156 OSSL_FUNC_signature_digest_sign_init and
157 OSSL_FUNC_signature_digest_sign
158 OSSL_FUNC_signature_digest_verify_init and
159 OSSL_FUNC_signature_digest_verify
160
161 OSSL_FUNC_signature_set_ctx_params and
162 OSSL_FUNC_signature_settable_ctx_params are optional, but if one of
163 them is present then the other one must also be present. The same
164 applies to OSSL_FUNC_signature_get_ctx_params and
165 OSSL_FUNC_signature_gettable_ctx_params, as well as the "md_params"
166 functions. The OSSL_FUNC_signature_dupctx function is optional.
167
168 A signature algorithm must also implement some mechanism for
169 generating, loading or importing keys via the key management
170 (OSSL_OP_KEYMGMT) operation. See provider-keymgmt(7) for further
171 details.
172
173 Context Management Functions
174 OSSL_FUNC_signature_newctx() should create and return a pointer to a
175 provider side structure for holding context information during a
176 signature operation. A pointer to this context will be passed back in
177 a number of the other signature operation function calls. The
178 parameter provctx is the provider context generated during provider
179 initialisation (see provider(7)). The propq parameter is a property
180 query string that may be (optionally) used by the provider during any
181 "fetches" that it may perform (if it performs any).
182
183 OSSL_FUNC_signature_freectx() is passed a pointer to the provider side
184 signature context in the ctx parameter. This function should free any
185 resources associated with that context.
186
187 OSSL_FUNC_signature_dupctx() should duplicate the provider side
188 signature context in the ctx parameter and return the duplicate copy.
189
190 Signing Functions
191 OSSL_FUNC_signature_sign_init() initialises a context for signing given
192 a provider side signature context in the ctx parameter, and a pointer
193 to a provider key object in the provkey parameter. The params, if not
194 NULL, should be set on the context in a manner similar to using
195 OSSL_FUNC_signature_set_ctx_params(). The key object should have been
196 previously generated, loaded or imported into the provider using the
197 key management (OSSL_OP_KEYMGMT) operation (see provider-keymgmt(7)>.
198
199 OSSL_FUNC_signature_sign() performs the actual signing itself. A
200 previously initialised signature context is passed in the ctx
201 parameter. The data to be signed is pointed to be the tbs parameter
202 which is tbslen bytes long. Unless sig is NULL, the signature should
203 be written to the location pointed to by the sig parameter and it
204 should not exceed sigsize bytes in length. The length of the signature
205 should be written to *siglen. If sig is NULL then the maximum length
206 of the signature should be written to *siglen.
207
208 Verify Functions
209 OSSL_FUNC_signature_verify_init() initialises a context for verifying a
210 signature given a provider side signature context in the ctx parameter,
211 and a pointer to a provider key object in the provkey parameter. The
212 params, if not NULL, should be set on the context in a manner similar
213 to using OSSL_FUNC_signature_set_ctx_params(). The key object should
214 have been previously generated, loaded or imported into the provider
215 using the key management (OSSL_OP_KEYMGMT) operation (see
216 provider-keymgmt(7)>.
217
218 OSSL_FUNC_signature_verify() performs the actual verification itself.
219 A previously initialised signature context is passed in the ctx
220 parameter. The data that the signature covers is pointed to be the tbs
221 parameter which is tbslen bytes long. The signature is pointed to by
222 the sig parameter which is siglen bytes long.
223
224 Verify Recover Functions
225 OSSL_FUNC_signature_verify_recover_init() initialises a context for
226 recovering the signed data given a provider side signature context in
227 the ctx parameter, and a pointer to a provider key object in the
228 provkey parameter. The params, if not NULL, should be set on the
229 context in a manner similar to using
230 OSSL_FUNC_signature_set_ctx_params(). The key object should have been
231 previously generated, loaded or imported into the provider using the
232 key management (OSSL_OP_KEYMGMT) operation (see provider-keymgmt(7)>.
233
234 OSSL_FUNC_signature_verify_recover() performs the actual verify recover
235 itself. A previously initialised signature context is passed in the
236 ctx parameter. The signature is pointed to by the sig parameter which
237 is siglen bytes long. Unless rout is NULL, the recovered data should
238 be written to the location pointed to by rout which should not exceed
239 routsize bytes in length. The length of the recovered data should be
240 written to *routlen. If rout is NULL then the maximum size of the
241 output buffer is written to the routlen parameter.
242
243 Digest Sign Functions
244 OSSL_FUNC_signature_digeset_sign_init() initialises a context for
245 signing given a provider side signature context in the ctx parameter,
246 and a pointer to a provider key object in the provkey parameter. The
247 params, if not NULL, should be set on the context in a manner similar
248 to using OSSL_FUNC_signature_set_ctx_params() and
249 OSSL_FUNC_signature_set_ctx_md_params(). The key object should have
250 been previously generated, loaded or imported into the provider using
251 the key management (OSSL_OP_KEYMGMT) operation (see
252 provider-keymgmt(7)>. The name of the digest to be used will be in the
253 mdname parameter.
254
255 OSSL_FUNC_signature_digest_sign_update() provides data to be signed in
256 the data parameter which should be of length datalen. A previously
257 initialised signature context is passed in the ctx parameter. This
258 function may be called multiple times to cumulatively add data to be
259 signed.
260
261 OSSL_FUNC_signature_digest_sign_final() finalises a signature operation
262 previously started through OSSL_FUNC_signature_digest_sign_init() and
263 OSSL_FUNC_signature_digest_sign_update() calls. Once finalised no more
264 data will be added through OSSL_FUNC_signature_digest_sign_update(). A
265 previously initialised signature context is passed in the ctx
266 parameter. Unless sig is NULL, the signature should be written to the
267 location pointed to by the sig parameter and it should not exceed
268 sigsize bytes in length. The length of the signature should be written
269 to *siglen. If sig is NULL then the maximum length of the signature
270 should be written to *siglen.
271
272 OSSL_FUNC_signature_digest_sign() implements a "one shot" digest sign
273 operation previously started through
274 OSSL_FUNC_signature_digeset_sign_init(). A previously initialised
275 signature context is passed in the ctx parameter. The data to be signed
276 is in tbs which should be tbslen bytes long. Unless sig is NULL, the
277 signature should be written to the location pointed to by the sig
278 parameter and it should not exceed sigsize bytes in length. The length
279 of the signature should be written to *siglen. If sig is NULL then the
280 maximum length of the signature should be written to *siglen.
281
282 Digest Verify Functions
283 OSSL_FUNC_signature_digeset_verify_init() initialises a context for
284 verifying given a provider side verification context in the ctx
285 parameter, and a pointer to a provider key object in the provkey
286 parameter. The params, if not NULL, should be set on the context in a
287 manner similar to OSSL_FUNC_signature_set_ctx_params() and
288 OSSL_FUNC_signature_set_ctx_md_params(). The key object should have
289 been previously generated, loaded or imported into the provider using
290 the key management (OSSL_OP_KEYMGMT) operation (see
291 provider-keymgmt(7)>. The name of the digest to be used will be in the
292 mdname parameter.
293
294 OSSL_FUNC_signature_digest_verify_update() provides data to be verified
295 in the data parameter which should be of length datalen. A previously
296 initialised verification context is passed in the ctx parameter. This
297 function may be called multiple times to cumulatively add data to be
298 verified.
299
300 OSSL_FUNC_signature_digest_verify_final() finalises a verification
301 operation previously started through
302 OSSL_FUNC_signature_digest_verify_init() and
303 OSSL_FUNC_signature_digest_verify_update() calls. Once finalised no
304 more data will be added through
305 OSSL_FUNC_signature_digest_verify_update(). A previously initialised
306 verification context is passed in the ctx parameter. The signature to
307 be verified is in sig which is siglen bytes long.
308
309 OSSL_FUNC_signature_digest_verify() implements a "one shot" digest
310 verify operation previously started through
311 OSSL_FUNC_signature_digeset_verify_init(). A previously initialised
312 verification context is passed in the ctx parameter. The data to be
313 verified is in tbs which should be tbslen bytes long. The signature to
314 be verified is in sig which is siglen bytes long.
315
316 Signature parameters
317 See OSSL_PARAM(3) for further details on the parameters structure used
318 by the OSSL_FUNC_signature_get_ctx_params() and
319 OSSL_FUNC_signature_set_ctx_params() functions.
320
321 OSSL_FUNC_signature_get_ctx_params() gets signature parameters
322 associated with the given provider side signature context ctx and
323 stored them in params. Passing NULL for params should return true.
324
325 OSSL_FUNC_signature_set_ctx_params() sets the signature parameters
326 associated with the given provider side signature context ctx to
327 params. Any parameter settings are additional to any that were
328 previously set. Passing NULL for params should return true.
329
330 Common parameters currently recognised by built-in signature algorithms
331 are as follows.
332
333 "digest" (OSSL_SIGNATURE_PARAM_DIGEST) <UTF8 string>
334 Get or sets the name of the digest algorithm used for the input to
335 the signature functions. It is required in order to calculate the
336 "algorithm-id".
337
338 "properties" (OSSL_SIGNATURE_PARAM_PROPERTIES) <UTF8 string>
339 Sets the name of the property query associated with the "digest"
340 algorithm. NULL is used if this optional value is not set.
341
342 "digest-size" (OSSL_SIGNATURE_PARAM_DIGEST_SIZE) <unsigned integer>
343 Gets or sets the output size of the digest algorithm used for the
344 input to the signature functions. The length of the "digest-size"
345 parameter should not exceed that of a size_t.
346
347 "algorithm-id" (OSSL_SIGNATURE_PARAM_ALGORITHM_ID) <octet string>
348 Gets the DER encoded AlgorithmIdentifier that corresponds to the
349 combination of signature algorithm and digest algorithm for the
350 signature operation.
351
352 "kat" (OSSL_SIGNATURE_PARAM_KAT) <unsigned integer>
353 Sets a flag to modify the sign operation to return an error if the
354 initial calculated signature is invalid. In the normal mode of
355 operation - new random values are chosen until the signature
356 operation succeeds. By default it retries until a signature is
357 calculated. Setting the value to 0 causes the sign operation to
358 retry, otherwise the sign operation is only tried once and returns
359 whether or not it was successful. Known answer tests can be
360 performed if the random generator is overridden to supply known
361 values that either pass or fail.
362
363 OSSL_FUNC_signature_gettable_ctx_params() and
364 OSSL_FUNC_signature_settable_ctx_params() get a constant OSSL_PARAM
365 array that describes the gettable and settable parameters, i.e.
366 parameters that can be used with OSSL_FUNC_signature_get_ctx_params()
367 and OSSL_FUNC_signature_set_ctx_params() respectively. See
368 OSSL_PARAM(3) for the use of OSSL_PARAM as parameter descriptor.
369
370 MD parameters
371 See OSSL_PARAM(3) for further details on the parameters structure used
372 by the OSSL_FUNC_signature_get_md_ctx_params() and
373 OSSL_FUNC_signature_set_md_ctx_params() functions.
374
375 OSSL_FUNC_signature_get_md_ctx_params() gets digest parameters
376 associated with the given provider side digest signature context ctx
377 and stores them in params. Passing NULL for params should return true.
378
379 OSSL_FUNC_signature_set_ms_ctx_params() sets the digest parameters
380 associated with the given provider side digest signature context ctx to
381 params. Any parameter settings are additional to any that were
382 previously set. Passing NULL for params should return true.
383
384 Parameters currently recognised by built-in signature algorithms are
385 the same as those for built-in digest algorithms. See "Digest
386 Parameters" in provider-digest(7) for further information.
387
388 OSSL_FUNC_signature_gettable_md_ctx_params() and
389 OSSL_FUNC_signature_settable_md_ctx_params() get a constant OSSL_PARAM
390 array that describes the gettable and settable digest parameters, i.e.
391 parameters that can be used with
392 OSSL_FUNC_signature_get_md_ctx_params() and
393 OSSL_FUNC_signature_set_md_ctx_params() respectively. See OSSL_PARAM(3)
394 for the use of OSSL_PARAM as parameter descriptor.
395
397 OSSL_FUNC_signature_newctx() and OSSL_FUNC_signature_dupctx() should
398 return the newly created provider side signature, or NULL on failure.
399
400 OSSL_FUNC_signature_gettable_ctx_params(),
401 OSSL_FUNC_signature_settable_ctx_params(),
402 OSSL_FUNC_signature_gettable_md_ctx_params() and
403 OSSL_FUNC_signature_settable_md_ctx_params(), return the gettable or
404 settable parameters in a constant OSSL_PARAM array.
405
406 All other functions should return 1 for success or 0 on error.
407
409 provider(7)
410
412 The provider SIGNATURE interface was introduced in OpenSSL 3.0.
413
415 Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
416
417 Licensed under the Apache License 2.0 (the "License"). You may not use
418 this file except in compliance with the License. You can obtain a copy
419 in the file LICENSE in the source distribution or at
420 <https://www.openssl.org/source/license.html>.
421
422
423
4243.0.5 2022-07-05 PROVIDER-SIGNATURE(7ossl)