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