1PROVIDER-KEYMGMT(7ossl) OpenSSL PROVIDER-KEYMGMT(7ossl)
2
3
4
6 provider-keymgmt - The KEYMGMT library <-> provider functions
7
9 #include <openssl/core_dispatch.h>
10
11 /*
12 * None of these are actual functions, but are displayed like this for
13 * the function signatures for functions that are offered as function
14 * pointers in OSSL_DISPATCH arrays.
15 */
16
17 /* Key object (keydata) creation and destruction */
18 void *OSSL_FUNC_keymgmt_new(void *provctx);
19 void OSSL_FUNC_keymgmt_free(void *keydata);
20
21 /* Generation, a more complex constructor */
22 void *OSSL_FUNC_keymgmt_gen_init(void *provctx, int selection,
23 const OSSL_PARAM params[]);
24 int OSSL_FUNC_keymgmt_gen_set_template(void *genctx, void *template);
25 int OSSL_FUNC_keymgmt_gen_set_params(void *genctx, const OSSL_PARAM params[]);
26 const OSSL_PARAM *OSSL_FUNC_keymgmt_gen_settable_params(void *genctx,
27 void *provctx);
28 void *OSSL_FUNC_keymgmt_gen(void *genctx, OSSL_CALLBACK *cb, void *cbarg);
29 void OSSL_FUNC_keymgmt_gen_cleanup(void *genctx);
30
31 /* Key loading by object reference, also a constructor */
32 void *OSSL_FUNC_keymgmt_load(const void *reference, size_t *reference_sz);
33
34 /* Key object information */
35 int OSSL_FUNC_keymgmt_get_params(void *keydata, OSSL_PARAM params[]);
36 const OSSL_PARAM *OSSL_FUNC_keymgmt_gettable_params(void *provctx);
37 int OSSL_FUNC_keymgmt_set_params(void *keydata, const OSSL_PARAM params[]);
38 const OSSL_PARAM *OSSL_FUNC_keymgmt_settable_params(void *provctx);
39
40 /* Key object content checks */
41 int OSSL_FUNC_keymgmt_has(const void *keydata, int selection);
42 int OSSL_FUNC_keymgmt_match(const void *keydata1, const void *keydata2,
43 int selection);
44
45 /* Discovery of supported operations */
46 const char *OSSL_FUNC_keymgmt_query_operation_name(int operation_id);
47
48 /* Key object import and export functions */
49 int OSSL_FUNC_keymgmt_import(void *keydata, int selection, const OSSL_PARAM params[]);
50 const OSSL_PARAM *OSSL_FUNC_keymgmt_import_types(int selection);
51 int OSSL_FUNC_keymgmt_export(void *keydata, int selection,
52 OSSL_CALLBACK *param_cb, void *cbarg);
53 const OSSL_PARAM *OSSL_FUNC_keymgmt_export_types(int selection);
54
55 /* Key object duplication, a constructor */
56 void *OSSL_FUNC_keymgmt_dup(const void *keydata_from, int selection);
57
58 /* Key object validation */
59 int OSSL_FUNC_keymgmt_validate(const void *keydata, int selection, int checktype);
60
62 The KEYMGMT operation doesn't have much public visibility in OpenSSL
63 libraries, it's rather an internal operation that's designed to work in
64 tandem with operations that use private/public key pairs.
65
66 Because the KEYMGMT operation shares knowledge with the operations it
67 works with in tandem, they must belong to the same provider. The
68 OpenSSL libraries will ensure that they do.
69
70 The primary responsibility of the KEYMGMT operation is to hold the
71 provider side key data for the OpenSSL library EVP_PKEY structure.
72
73 All "functions" mentioned here are passed as function pointers between
74 libcrypto and the provider in OSSL_DISPATCH arrays via OSSL_ALGORITHM
75 arrays that are returned by the provider's provider_query_operation()
76 function (see "Provider Functions" in provider-base(7)).
77
78 All these "functions" have a corresponding function type definition
79 named OSSL_FUNC_{name}_fn, and a helper function to retrieve the
80 function pointer from a OSSL_DISPATCH element named OSSL_FUNC_{name}.
81 For example, the "function" OSSL_FUNC_keymgmt_new() has these:
82
83 typedef void *(OSSL_FUNC_keymgmt_new_fn)(void *provctx);
84 static ossl_inline OSSL_FUNC_keymgmt_new_fn
85 OSSL_FUNC_keymgmt_new(const OSSL_DISPATCH *opf);
86
87 OSSL_DISPATCH arrays are indexed by numbers that are provided as macros
88 in openssl-core_dispatch.h(7), as follows:
89
90 OSSL_FUNC_keymgmt_new OSSL_FUNC_KEYMGMT_NEW
91 OSSL_FUNC_keymgmt_free OSSL_FUNC_KEYMGMT_FREE
92
93 OSSL_FUNC_keymgmt_gen_init OSSL_FUNC_KEYMGMT_GEN_INIT
94 OSSL_FUNC_keymgmt_gen_set_template OSSL_FUNC_KEYMGMT_GEN_SET_TEMPLATE
95 OSSL_FUNC_keymgmt_gen_set_params OSSL_FUNC_KEYMGMT_GEN_SET_PARAMS
96 OSSL_FUNC_keymgmt_gen_settable_params OSSL_FUNC_KEYMGMT_GEN_SETTABLE_PARAMS
97 OSSL_FUNC_keymgmt_gen OSSL_FUNC_KEYMGMT_GEN
98 OSSL_FUNC_keymgmt_gen_cleanup OSSL_FUNC_KEYMGMT_GEN_CLEANUP
99
100 OSSL_FUNC_keymgmt_load OSSL_FUNC_KEYMGMT_LOAD
101
102 OSSL_FUNC_keymgmt_get_params OSSL_FUNC_KEYMGMT_GET_PARAMS
103 OSSL_FUNC_keymgmt_gettable_params OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS
104 OSSL_FUNC_keymgmt_set_params OSSL_FUNC_KEYMGMT_SET_PARAMS
105 OSSL_FUNC_keymgmt_settable_params OSSL_FUNC_KEYMGMT_SETTABLE_PARAMS
106
107 OSSL_FUNC_keymgmt_query_operation_name OSSL_FUNC_KEYMGMT_QUERY_OPERATION_NAME
108
109 OSSL_FUNC_keymgmt_has OSSL_FUNC_KEYMGMT_HAS
110 OSSL_FUNC_keymgmt_validate OSSL_FUNC_KEYMGMT_VALIDATE
111 OSSL_FUNC_keymgmt_match OSSL_FUNC_KEYMGMT_MATCH
112
113 OSSL_FUNC_keymgmt_import OSSL_FUNC_KEYMGMT_IMPORT
114 OSSL_FUNC_keymgmt_import_types OSSL_FUNC_KEYMGMT_IMPORT_TYPES
115 OSSL_FUNC_keymgmt_export OSSL_FUNC_KEYMGMT_EXPORT
116 OSSL_FUNC_keymgmt_export_types OSSL_FUNC_KEYMGMT_EXPORT_TYPES
117
118 OSSL_FUNC_keymgmt_dup OSSL_FUNC_KEYMGMT_DUP
119
120 Key Objects
121 A key object is a collection of data for an asymmetric key, and is
122 represented as keydata in this manual.
123
124 The exact contents of a key object are defined by the provider, and it
125 is assumed that different operations in one and the same provider use
126 the exact same structure to represent this collection of data, so that
127 for example, a key object that has been created using the KEYMGMT
128 interface that we document here can be passed as is to other provider
129 operations, such as OP_signature_sign_init() (see
130 provider-signature(7)).
131
132 With some of the KEYMGMT functions, it's possible to select a specific
133 subset of data to handle, governed by the bits in a selection
134 indicator. The bits are:
135
136 OSSL_KEYMGMT_SELECT_PRIVATE_KEY
137 Indicating that the private key data in a key object should be
138 considered.
139
140 OSSL_KEYMGMT_SELECT_PUBLIC_KEY
141 Indicating that the public key data in a key object should be
142 considered.
143
144 OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS
145 Indicating that the domain parameters in a key object should be
146 considered.
147
148 OSSL_KEYMGMT_SELECT_OTHER_PARAMETERS
149 Indicating that other parameters in a key object should be
150 considered.
151
152 Other parameters are key parameters that don't fit any other
153 classification. In other words, this particular selector bit works
154 as a last resort bit bucket selector.
155
156 Some selector bits have also been combined for easier use:
157
158 OSSL_KEYMGMT_SELECT_ALL_PARAMETERS
159 Indicating that all key object parameters should be considered,
160 regardless of their more granular classification.
161
162 This is a combination of OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS and
163 OSSL_KEYMGMT_SELECT_OTHER_PARAMETERS.
164
165 OSSL_KEYMGMT_SELECT_KEYPAIR
166 Indicating that both the whole key pair in a key object should be
167 considered, i.e. the combination of public and private key.
168
169 This is a combination of OSSL_KEYMGMT_SELECT_PRIVATE_KEY and
170 OSSL_KEYMGMT_SELECT_PUBLIC_KEY.
171
172 OSSL_KEYMGMT_SELECT_ALL
173 Indicating that everything in a key object should be considered.
174
175 The exact interpretation of those bits or how they combine is left to
176 each function where you can specify a selector.
177
178 It's left to the provider implementation to decide what is reasonable
179 to do with regards to received selector bits and how to do it. Among
180 others, an implementation of OSSL_FUNC_keymgmt_match() might opt to not
181 compare the private half if it has compared the public half, since a
182 match of one half implies a match of the other half.
183
184 Constructing and Destructing Functions
185 OSSL_FUNC_keymgmt_new() should create a provider side key object. The
186 provider context provctx is passed and may be incorporated in the key
187 object, but that is not mandatory.
188
189 OSSL_FUNC_keymgmt_free() should free the passed keydata.
190
191 OSSL_FUNC_keymgmt_gen_init(), OSSL_FUNC_keymgmt_gen_set_template(),
192 OSSL_FUNC_keymgmt_gen_set_params(),
193 OSSL_FUNC_keymgmt_gen_settable_params(), OSSL_FUNC_keymgmt_gen() and
194 OSSL_FUNC_keymgmt_gen_cleanup() work together as a more elaborate
195 context based key object constructor.
196
197 OSSL_FUNC_keymgmt_gen_init() should create the key object generation
198 context and initialize it with selections, which will determine what
199 kind of contents the key object to be generated should get. The
200 params, if not NULL, should be set on the context in a manner similar
201 to using OSSL_FUNC_keymgmt_set_params().
202
203 OSSL_FUNC_keymgmt_gen_set_template() should add template to the context
204 genctx. The template is assumed to be a key object constructed with
205 the same KEYMGMT, and from which content that the implementation
206 chooses can be used as a template for the key object to be generated.
207 Typically, the generation of a DSA or DH key would get the domain
208 parameters from this template.
209
210 OSSL_FUNC_keymgmt_gen_set_params() should set additional parameters
211 from params in the key object generation context genctx.
212
213 OSSL_FUNC_keymgmt_gen_settable_params() should return a constant array
214 of descriptor OSSL_PARAM, for parameters that
215 OSSL_FUNC_keymgmt_gen_set_params() can handle.
216
217 OSSL_FUNC_keymgmt_gen() should perform the key object generation
218 itself, and return the result. The callback cb should be called at
219 regular intervals with indications on how the key object generation
220 progresses.
221
222 OSSL_FUNC_keymgmt_gen_cleanup() should clean up and free the key object
223 generation context genctx
224
225 OSSL_FUNC_keymgmt_load() creates a provider side key object based on a
226 reference object with a size of reference_sz bytes, that only the
227 provider knows how to interpret, but that may come from other
228 operations. Outside the provider, this reference is simply an array of
229 bytes.
230
231 At least one of OSSL_FUNC_keymgmt_new(), OSSL_FUNC_keymgmt_gen() and
232 OSSL_FUNC_keymgmt_load() are mandatory, as well as
233 OSSL_FUNC_keymgmt_free() and OSSL_FUNC_keymgmt_has(). Additionally, if
234 OSSL_FUNC_keymgmt_gen() is present, OSSL_FUNC_keymgmt_gen_init() and
235 OSSL_FUNC_keymgmt_gen_cleanup() must be present as well.
236
237 Key Object Information Functions
238 OSSL_FUNC_keymgmt_get_params() should extract information data
239 associated with the given keydata, see "Common Information Parameters".
240
241 OSSL_FUNC_keymgmt_gettable_params() should return a constant array of
242 descriptor OSSL_PARAM, for parameters that
243 OSSL_FUNC_keymgmt_get_params() can handle.
244
245 If OSSL_FUNC_keymgmt_gettable_params() is present,
246 OSSL_FUNC_keymgmt_get_params() must also be present, and vice versa.
247
248 OSSL_FUNC_keymgmt_set_params() should update information data
249 associated with the given keydata, see "Common Information Parameters".
250
251 OSSL_FUNC_keymgmt_settable_params() should return a constant array of
252 descriptor OSSL_PARAM, for parameters that
253 OSSL_FUNC_keymgmt_set_params() can handle.
254
255 If OSSL_FUNC_keymgmt_settable_params() is present,
256 OSSL_FUNC_keymgmt_set_params() must also be present, and vice versa.
257
258 Key Object Checking Functions
259 OSSL_FUNC_keymgmt_query_operation_name() should return the name of the
260 supported algorithm for the operation operation_id. This is similar to
261 provider_query_operation() (see provider-base(7)), but only works as an
262 advisory. If this function is not present, or returns NULL, the caller
263 is free to assume that there's an algorithm from the same provider, of
264 the same name as the one used to fetch the keymgmt and try to use that.
265
266 OSSL_FUNC_keymgmt_has() should check whether the given keydata contains
267 the subsets of data indicated by the selector. A combination of
268 several selector bits must consider all those subsets, not just one.
269 An implementation is, however, free to consider an empty subset of data
270 to still be a valid subset. For algorithms where some selection is not
271 meaningful such as OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS for RSA keys
272 the function should just return 1 as the selected subset is not really
273 missing in the key.
274
275 OSSL_FUNC_keymgmt_validate() should check if the keydata contains valid
276 data subsets indicated by selection. Some combined selections of data
277 subsets may cause validation of the combined data. For example, the
278 combination of OSSL_KEYMGMT_SELECT_PRIVATE_KEY and
279 OSSL_KEYMGMT_SELECT_PUBLIC_KEY (or OSSL_KEYMGMT_SELECT_KEYPAIR for
280 short) is expected to check that the pairwise consistency of keydata is
281 valid. The checktype parameter controls what type of check is performed
282 on the subset of data. Two types of check are defined:
283 OSSL_KEYMGMT_VALIDATE_FULL_CHECK and OSSL_KEYMGMT_VALIDATE_QUICK_CHECK.
284 The interpretation of how much checking is performed in a full check
285 versus a quick check is key type specific. Some providers may have no
286 distinction between a full check and a quick check. For algorithms
287 where some selection is not meaningful such as
288 OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS for RSA keys the function should
289 just return 1 as there is nothing to validate for that selection.
290
291 OSSL_FUNC_keymgmt_match() should check if the data subset indicated by
292 selection in keydata1 and keydata2 match. It is assumed that the
293 caller has ensured that keydata1 and keydata2 are both owned by the
294 implementation of this function.
295
296 Key Object Import, Export and Duplication Functions
297 OSSL_FUNC_keymgmt_import() should import data indicated by selection
298 into keydata with values taken from the OSSL_PARAM array params.
299
300 OSSL_FUNC_keymgmt_export() should extract values indicated by selection
301 from keydata, create an OSSL_PARAM array with them and call param_cb
302 with that array as well as the given cbarg.
303
304 OSSL_FUNC_keymgmt_import_types() should return a constant array of
305 descriptor OSSL_PARAM for data indicated by selection, for parameters
306 that OSSL_FUNC_keymgmt_import() can handle.
307
308 OSSL_FUNC_keymgmt_export_types() should return a constant array of
309 descriptor OSSL_PARAM for data indicated by selection, that the
310 OSSL_FUNC_keymgmt_export() callback can expect to receive.
311
312 OSSL_FUNC_keymgmt_dup() should duplicate data subsets indicated by
313 selection or the whole key data keydata_from and create a new provider
314 side key object with the data.
315
316 Common Information Parameters
317 See OSSL_PARAM(3) for further details on the parameters structure.
318
319 Common information parameters currently recognised by all built-in
320 keymgmt algorithms are as follows:
321
322 "bits" (OSSL_PKEY_PARAM_BITS) <integer>
323 The value should be the cryptographic length of the cryptosystem to
324 which the key belongs, in bits. The definition of cryptographic
325 length is specific to the key cryptosystem.
326
327 "max-size" (OSSL_PKEY_PARAM_MAX_SIZE) <integer>
328 The value should be the maximum size that a caller should allocate
329 to safely store a signature (called sig in provider-signature(7)),
330 the result of asymmmetric encryption / decryption (out in
331 provider-asym_cipher(7), a derived secret (secret in
332 provider-keyexch(7), and similar data).
333
334 Because an EVP_KEYMGMT method is always tightly bound to another
335 method (signature, asymmetric cipher, key exchange, ...) and must
336 be of the same provider, this number only needs to be synchronised
337 with the dimensions handled in the rest of the same provider.
338
339 "security-bits" (OSSL_PKEY_PARAM_SECURITY_BITS) <integer>
340 The value should be the number of security bits of the given key.
341 Bits of security is defined in SP800-57.
342
344 OSSL_FUNC_keymgmt_new() and OSSL_FUNC_keymgmt_dup() should return a
345 valid reference to the newly created provider side key object, or NULL
346 on failure.
347
348 OSSL_FUNC_keymgmt_import(), OSSL_FUNC_keymgmt_export(),
349 OSSL_FUNC_keymgmt_get_params() and OSSL_FUNC_keymgmt_set_params()
350 should return 1 for success or 0 on error.
351
352 OSSL_FUNC_keymgmt_validate() should return 1 on successful validation,
353 or 0 on failure.
354
355 OSSL_FUNC_keymgmt_has() should return 1 if all the selected data
356 subsets are contained in the given keydata or 0 otherwise.
357
358 OSSL_FUNC_keymgmt_query_operation_name() should return a pointer to a
359 string matching the requested operation, or NULL if the same name used
360 to fetch the keymgmt applies.
361
362 OSSL_FUNC_keymgmt_gettable_params() and
363 OSSL_FUNC_keymgmt_settable_params() OSSL_FUNC_keymgmt_import_types(),
364 OSSL_FUNC_keymgmt_export_types() should always return a constant
365 OSSL_PARAM array.
366
368 provider(7), EVP_PKEY-X25519(7), EVP_PKEY-X448(7), EVP_PKEY-ED25519(7),
369 EVP_PKEY-ED448(7), EVP_PKEY-EC(7), EVP_PKEY-RSA(7), EVP_PKEY-DSA(7),
370 EVP_PKEY-DH(7)
371
373 The KEYMGMT interface was introduced in OpenSSL 3.0.
374
376 Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
377
378 Licensed under the Apache License 2.0 (the "License"). You may not use
379 this file except in compliance with the License. You can obtain a copy
380 in the file LICENSE in the source distribution or at
381 <https://www.openssl.org/source/license.html>.
382
383
384
3853.0.5 2022-07-05 PROVIDER-KEYMGMT(7ossl)