5 provider-signature - The signature library E<lt>-E<gt> provider functions
9 =for comment multiple includes
11 #include <openssl/core_numbers.h>
12 #include <openssl/core_names.h>
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.
20 /* Context management */
21 void *OP_signature_newctx(void *provctx);
22 void OP_signature_freectx(void *ctx);
23 void *OP_signature_dupctx(void *ctx);
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);
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);
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);
41 /* Signature parameters */
42 int OP_signature_get_ctx_params(void *ctx, OSSL_PARAM params[]);
43 const OSSL_PARAM *OP_signature_gettable_ctx_params(void);
44 int OP_signature_set_ctx_params(void *ctx, const OSSL_PARAM params[]);
45 const OSSL_PARAM *OP_signature_settable_ctx_params(void);
49 This documentation is primarily aimed at provider authors. See L<provider(7)>
50 for further information.
52 The signature (OSSL_OP_SIGNATURE) operation enables providers to implement
53 signature algorithms and make them available to applications via the API
54 functions L<EVP_PKEY_sign_init_ex(3)>, L<EVP_PKEY_sign(3)>,
55 L<EVP_PKEY_verify_init_ex(3)>, L<EVP_PKEY_verify(3)>,
56 L<EVP_PKEY_verify_recover_init_ex(3)> and L<EVP_PKEY_verify_recover(3)> (as well
57 as other related functions).
59 All "functions" mentioned here are passed as function pointers between
60 F<libcrypto> and the provider in B<OSSL_DISPATCH> arrays via
61 B<OSSL_ALGORITHM> arrays that are returned by the provider's
62 provider_query_operation() function
63 (see L<provider-base(7)/Provider Functions>).
65 All these "functions" have a corresponding function type definition
66 named B<OSSL_{name}_fn>, and a helper function to retrieve the
67 function pointer from an B<OSSL_DISPATCH> element named
69 For example, the "function" OP_signature_newctx() has these:
71 typedef void *(OSSL_OP_signature_newctx_fn)(void *provctx);
72 static ossl_inline OSSL_OP_signature_newctx_fn
73 OSSL_get_OP_signature_newctx(const OSSL_DISPATCH *opf);
75 B<OSSL_DISPATCH> arrays are indexed by numbers that are provided as
76 macros in L<openssl-core_numbers.h(7)>, as follows:
78 OP_signature_newctx OSSL_FUNC_SIGNATURE_NEWCTX
79 OP_signature_freectx OSSL_FUNC_SIGNATURE_FREECTX
80 OP_signature_dupctx OSSL_FUNC_SIGNATURE_DUPCTX
82 OP_signature_sign_init OSSL_FUNC_SIGNATURE_SIGN_INIT
83 OP_signature_sign OSSL_FUNC_SIGNATURE_SIGN
85 OP_signature_verify_init OSSL_FUNC_SIGNATURE_VERIFY_INIT
86 OP_signature_verify OSSL_FUNC_SIGNATURE_VERIFY
88 OP_signature_verify_recover_init OSSL_FUNC_SIGNATURE_VERIFY_RECOVER_INIT
89 OP_signature_verify_recover OSSL_FUNC_SIGNATURE_VERIFY_RECOVER
91 OP_signature_get_ctx_params OSSL_FUNC_SIGNATURE_GET_CTX_PARAMS
92 OP_signature_gettable_ctx_params OSSL_FUNC_SIGNATURE_GETTABLE_CTX_PARAMS
93 OP_signature_set_ctx_params OSSL_FUNC_SIGNATURE_SET_CTX_PARAMS
94 OP_signature_settable_ctx_params OSSL_FUNC_SIGNATURE_SETTABLE_CTX_PARAMS
96 A signature algorithm implementation may not implement all of these functions.
97 In order to be a consistent set of functions a provider must implement
98 OP_signature_newctx and OP_signature_freectx.
99 It must also implement both of OP_signature_sign_init and OP_signature_sign,
100 or both of OP_signature_verify_init and OP_signature_verify, or both of
101 OP_signature_verify_recover_init and OP_signature_verify_recover.
102 All other functions are optional.
104 A signature algorithm must also implement some mechanism for generating,
105 loading or importing keys via the key management (OSSL_OP_KEYMGMT) operation.
106 See L<provider-keymgmt(7)> for further details.
108 =head2 Context Management Functions
110 OP_signature_newctx() should create and return a pointer to a provider side
111 structure for holding context information during a signature operation.
112 A pointer to this context will be passed back in a number of the other signature
113 operation function calls.
114 The parameter B<provctx> is the provider context generated during provider
115 initialisation (see L<provider(3)>).
117 OP_signature_freectx() is passed a pointer to the provider side signature
118 context in the B<ctx> parameter.
119 This function should free any resources associated with that context.
121 OP_signature_dupctx() should duplicate the provider side signature context in
122 the B<ctx> parameter and return the duplicate copy.
124 =head2 Signing Functions
126 OP_signature_sign_init() initialises a context for signing given a provider side
127 signature context in the B<ctx> parameter, and a pointer to a provider key object
128 in the B<provkey> parameter.
129 The key object should have been previously generated, loaded or imported into
130 the provider using the key management (OSSL_OP_KEYMGMT) operation (see
131 provider-keymgmt(7)>.
133 OP_signature_sign() performs the actual signing itself.
134 A previously initialised signature context is passed in the B<ctx>
136 The data to be signed is pointed to be the B<tbs> parameter which is B<tbslen>
138 Unless B<sig> is NULL, the signature should be written to the location pointed
139 to by the B<sig> parameter and it should not exceed B<sigsize> bytes in length.
140 The length of the signature should be written to B<*siglen>.
141 If B<sig> is NULL then the maximum length of the signature should be written to
144 =head2 Verify Functions
146 OP_signature_verify_init() initialises a context for verifying a signature given
147 a provider side signature context in the B<ctx> parameter, and a pointer to a
148 provider key object in the B<provkey> parameter.
149 The key object should have been previously generated, loaded or imported into
150 the provider using the key management (OSSL_OP_KEYMGMT) operation (see
151 provider-keymgmt(7)>.
153 OP_signature_verify() performs the actual verification itself.
154 A previously initialised signature context is passed in the B<ctx> parameter.
155 The data that the signature covers is pointed to be the B<tbs> parameter which
156 is B<tbslen> bytes long.
157 The signature is pointed to by the B<sig> parameter which is B<siglen> bytes
160 =head2 Verify Recover Functions
162 OP_signature_verify_recover_init() initialises a context for recovering the
163 signed data given a provider side signature context in the B<ctx> parameter, and
164 a pointer to a provider key object in the B<provkey> parameter.
165 The key object should have been previously generated, loaded or imported into
166 the provider using the key management (OSSL_OP_KEYMGMT) operation (see
167 provider-keymgmt(7)>.
169 OP_signature_verify_recover() performs the actual verify recover itself.
170 A previously initialised signature context is passed in the B<ctx> parameter.
171 The signature is pointed to by the B<sig> parameter which is B<siglen> bytes
173 Unless B<rout> is NULL, the recovered data should be written to the location
174 pointed to by B<rout> which should not exceed B<routsize> bytes in length.
175 The length of the recovered data should be written to B<*routlen>.
176 If B<rout> is B<NULL> then the maximum size of the output buffer is written to
177 the B<routlen> parameter.
179 =head2 Signature Parameters
181 See L<OSSL_PARAM(3)> for further details on the parameters structure used by
182 the OP_signature_get_ctx_params() and OP_signature_set_ctx_params() functions.
184 OP_signature_get_ctx_params() gets signature parameters associated with the
185 given provider side signature context B<ctx> and stored them in B<params>.
186 OP_signature_set_ctx_params() sets the signature parameters associated with the
187 given provider side signature context B<ctx> to B<params>.
188 Any parameter settings are additional to any that were previously set.
190 Parameters currently recognised by built-in signature algorithms are as
192 Not all parameters are relevant to, or are understood by all signature
197 =item "digest" (B<OSSL_SIGNATURE_PARAM_DIGEST>) <utf8 string>
199 Get or sets the name of the digest algorithm used for the input to the signature
202 =item "digest-size" (B<OSSL_SIGNATURE_PARAM_DIGEST_SIZE>) <size_t>
204 Gets or sets the output size of the digest algorithm used for the input to the
209 OP_signature_gettable_ctx_params() and OP_signature_settable_ctx_params() get a
210 constant B<OSSL_PARAM> array that decribes the gettable and settable parameters,
211 i.e. parameters that can be used with OP_signature_get_ctx_params() and
212 OP_signature_set_ctx_params() respectively.
213 See L<OSSL_PARAM(3)> for the use of B<OSSL_PARAM> as parameter descriptor.
217 OP_signature_newctx() and OP_signature_dupctx() should return the newly created
218 provider side signature, or NULL on failure.
220 All other functions should return 1 for success or 0 on error.
228 The provider SIGNATURE interface was introduced in OpenSSL 3.0.
232 Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
234 Licensed under the Apache License 2.0 (the "License"). You may not use
235 this file except in compliance with the License. You can obtain a copy
236 in the file LICENSE in the source distribution or at
237 L<https://www.openssl.org/source/license.html>.