]>
Commit | Line | Data |
---|---|---|
4f62f5d9 MC |
1 | =pod |
2 | ||
3 | =head1 NAME | |
4 | ||
5 | provider-signature - The signature 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_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 | ||
41 | /* Signature parameters */ | |
42 | int OP_signature_set_params(void *ctx, const OSSL_PARAM params[]); | |
43 | ||
44 | ||
45 | =head1 DESCRIPTION | |
46 | ||
47 | This documentation is primarily aimed at provider authors. See L<provider(7)> | |
48 | for further information. | |
49 | ||
50 | The signature (OSSL_OP_SIGNATURE) operation enables providers to implement | |
51 | signature algorithms and make them available to applications via the API | |
52 | functions L<EVP_PKEY_sign_init_ex(3)>, L<EVP_PKEY_sign(3)>, | |
53 | L<EVP_PKEY_verify_init_ex(3)>, L<EVP_PKEY_verify(3)>, | |
54 | L<EVP_PKEY_verify_recover_init_ex(3)> and L<EVP_PKEY_verify_recover(3)> (as well | |
55 | as 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_get_{name}>. | |
67 | For example, the "function" OP_signature_newctx() has these: | |
68 | ||
69 | typedef void *(OSSL_OP_signature_newctx_fn)(void *provctx); | |
70 | static ossl_inline OSSL_OP_signature_newctx_fn | |
71 | OSSL_get_OP_signature_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_numbers.h(7)>, as follows: | |
75 | ||
76 | OP_signature_newctx OSSL_FUNC_SIGNATURE_NEWCTX | |
77 | OP_signature_freectx OSSL_FUNC_SIGNATURE_FREECTX | |
78 | OP_signature_dupctx OSSL_FUNC_SIGNATURE_DUPCTX | |
79 | ||
80 | OP_signature_sign_init OSSL_FUNC_SIGNATURE_SIGN_INIT | |
81 | OP_signature_sign OSSL_FUNC_SIGNATURE_SIGN | |
82 | ||
83 | OP_signature_verify_init OSSL_FUNC_SIGNATURE_VERIFY_INIT | |
84 | OP_signature_verify OSSL_FUNC_SIGNATURE_VERIFY | |
85 | ||
86 | OP_signature_verify_recover_init OSSL_FUNC_SIGNATURE_VERIFY_RECOVER_INIT | |
87 | OP_signature_verify_recover OSSL_FUNC_SIGNATURE_VERIFY_RECOVER | |
88 | ||
89 | OP_signature_set_params OSSL_FUNC_SIGNATURE_SET_PARAMS | |
90 | ||
91 | A signature algorithm implementation may not implement all of these functions. | |
92 | In order to be a consistent set of functions a provider must implement | |
93 | OP_signature_newctx and OP_signature_freectx. | |
94 | It must also implement both of OP_signature_sign_init and OP_signature_sign, | |
95 | or both of OP_signature_verify_init and OP_signature_verify, or both of | |
96 | OP_signature_verify_recover_init and OP_signature_verify_recover. | |
97 | All other functions are optional. | |
98 | ||
99 | A signature algorithm must also implement some mechanism for generating, | |
100 | loading or importing keys via the key management (OSSL_OP_KEYMGMT) operation. | |
101 | See L<provider-keymgmt(7)> for further details. | |
102 | ||
103 | =head2 Context Management Functions | |
104 | ||
105 | OP_signature_newctx() should create and return a pointer to a provider side | |
106 | structure for holding context information during a signature operation. | |
107 | A pointer to this context will be passed back in a number of the other signature | |
108 | operation function calls. | |
109 | The parameter B<provctx> is the provider context generated during provider | |
110 | initialisation (see L<provider(3)>). | |
111 | ||
112 | OP_signature_freectx() is passed a pointer to the provider side signature | |
113 | context in the B<ctx> parameter. | |
114 | This function should free any resources associated with that context. | |
115 | ||
116 | OP_signature_dupctx() should duplicate the provider side signature context in | |
117 | the B<ctx> parameter and return the duplicate copy. | |
118 | ||
119 | =head2 Signing Functions | |
120 | ||
121 | OP_signature_sign_init() initialises a context for signing given a provider side | |
122 | signature context in the B<ctx> parameter, and a pointer to a provider key object | |
123 | in the B<provkey> parameter. | |
124 | The key object should have been previously generated, loaded or imported into | |
125 | the provider using the key management (OSSL_OP_KEYMGMT) operation (see | |
126 | provider-keymgmt(7)>. | |
127 | ||
128 | OP_signature_sign() performs the actual signing itself. | |
129 | A previously initialised signature context is passed in the B<ctx> | |
130 | parameter. | |
131 | The data to be signed is pointed to be the B<tbs> parameter which is B<tbslen> | |
132 | bytes long. | |
133 | Unless B<sig> is NULL, the signature should be written to the location pointed | |
134 | to by the B<sig> parameter and it should not exceed B<sigsize> bytes in length. | |
135 | The length of the signature should be written to B<*siglen>. | |
136 | If B<sig> is NULL then the maximum length of the signature should be written to | |
137 | B<*siglen>. | |
138 | ||
139 | =head2 Verify Functions | |
140 | ||
141 | OP_signature_verify_init() initialises a context for verifying a signature given | |
142 | a provider side signature context in the B<ctx> parameter, and a pointer to a | |
143 | provider key object in the B<provkey> parameter. | |
144 | The key object should have been previously generated, loaded or imported into | |
145 | the provider using the key management (OSSL_OP_KEYMGMT) operation (see | |
146 | provider-keymgmt(7)>. | |
147 | ||
148 | OP_signature_verify() performs the actual verification itself. | |
149 | A previously initialised signature context is passed in the B<ctx> parameter. | |
150 | The data that the signature covers is pointed to be the B<tbs> parameter which | |
151 | is B<tbslen> bytes long. | |
152 | The signature is pointed to by the B<sig> parameter which is B<siglen> bytes | |
153 | long. | |
154 | ||
155 | =head2 Verify Recover Functions | |
156 | ||
157 | OP_signature_verify_recover_init() initialises a context for recovering the | |
158 | signed data given a provider side signature context in the B<ctx> parameter, and | |
159 | a pointer to a provider key object in the B<provkey> parameter. | |
160 | The key object should have been previously generated, loaded or imported into | |
161 | the provider using the key management (OSSL_OP_KEYMGMT) operation (see | |
162 | provider-keymgmt(7)>. | |
163 | ||
164 | OP_signature_verify_recover() performs the actual verify recover itself. | |
165 | A previously initialised signature context is passed in the B<ctx> parameter. | |
166 | The signature is pointed to by the B<sig> parameter which is B<siglen> bytes | |
167 | long. | |
168 | Unless B<rout> is NULL, the recovered data should be written to the location | |
169 | pointed to by B<rout> which should not exceed B<routsize> bytes in length. | |
170 | The length of the recovered data should be written to B<*routlen>. | |
171 | If B<rout> is B<NULL> then the maximum size of the output buffer is written to | |
172 | the B<routlen> parameter. | |
173 | ||
174 | =head2 Signature Parameters | |
175 | ||
176 | See L<OSSL_PARAM(3)> for further details on the parameters structure used by | |
177 | the OP_signature_set_params() function. | |
178 | ||
179 | OP_signature_set_params() sets signature parameters associated with the given | |
180 | provider side key exchange context B<ctx> to B<params>. | |
181 | Any parameter settings are additional to any that were previously set. | |
182 | ||
183 | Parameters currently recognised by built-in signature algorithms are as | |
184 | follows. | |
185 | Not all parameters are relevant to, or are understood by all signature | |
186 | algorithms: | |
187 | ||
188 | =over 4 | |
189 | ||
190 | =item B<OSSL_SIGNATURE_PARAM_DIGEST> (UTF8 string) | |
191 | ||
192 | Sets the name of the digest algorithm used for the input to the signature | |
193 | functions. | |
194 | ||
195 | =item B<OSSL_SIGNATURE_PARAM_DIGEST_SIZE> (size_t) | |
196 | ||
197 | Sets the output size of the digest algorithm used for the input to the signature | |
198 | functions. | |
199 | ||
200 | =back | |
201 | ||
202 | =head1 RETURN VALUES | |
203 | ||
204 | OP_signature_newctx() and OP_signature_dupctx() should return the newly created | |
205 | provider side signature, or NULL on failure. | |
206 | ||
207 | OP_signature_sign_init(), OP_signature_sign(), OP_signature_verify_init(), | |
208 | OP_signature_verify(), OP_signature_verify_recover_init(), | |
209 | OP_signature_verify_recover() and OP_signature_set_params() should return 1 for | |
210 | success or 0 on error. | |
211 | ||
212 | =head1 SEE ALSO | |
213 | ||
214 | L<provider(7)> | |
215 | ||
216 | =head1 HISTORY | |
217 | ||
218 | The provider SIGNATURE interface was introduced in OpenSSL 3.0. | |
219 | ||
220 | =head1 COPYRIGHT | |
221 | ||
222 | Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. | |
223 | ||
224 | Licensed under the Apache License 2.0 (the "License"). You may not use | |
225 | this file except in compliance with the License. You can obtain a copy | |
226 | in the file LICENSE in the source distribution or at | |
227 | L<https://www.openssl.org/source/license.html>. | |
228 | ||
229 | =cut |