/src/openssl/providers/implementations/encode_decode/decode_der2key.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright 2020-2025 The OpenSSL Project Authors. All Rights Reserved. |
3 | | * |
4 | | * Licensed under the Apache License 2.0 (the "License"). You may not use |
5 | | * this file except in compliance with the License. You can obtain a copy |
6 | | * in the file LICENSE in the source distribution or at |
7 | | * https://www.openssl.org/source/license.html |
8 | | */ |
9 | | |
10 | | /* |
11 | | * low level APIs are deprecated for public use, but still ok for |
12 | | * internal use. |
13 | | */ |
14 | | #include "internal/deprecated.h" |
15 | | |
16 | | #include <openssl/byteorder.h> |
17 | | #include <openssl/core_dispatch.h> |
18 | | #include <openssl/core_names.h> |
19 | | #include <openssl/core_object.h> |
20 | | #include <openssl/crypto.h> |
21 | | #include <openssl/err.h> |
22 | | #include <openssl/params.h> |
23 | | #include <openssl/pem.h> /* PEM_BUFSIZE and public PEM functions */ |
24 | | #include <openssl/pkcs12.h> |
25 | | #include <openssl/provider.h> |
26 | | #include <openssl/x509.h> |
27 | | #include <openssl/proverr.h> |
28 | | #include <openssl/asn1t.h> |
29 | | #include "internal/cryptlib.h" /* ossl_assert() */ |
30 | | #include "crypto/dh.h" |
31 | | #include "crypto/dsa.h" |
32 | | #include "crypto/ec.h" |
33 | | #include "crypto/evp.h" |
34 | | #include "crypto/ecx.h" |
35 | | #include "crypto/rsa.h" |
36 | | #include "crypto/ml_dsa.h" |
37 | | #include "crypto/slh_dsa.h" |
38 | | #include "crypto/x509.h" |
39 | | #include "crypto/ml_kem.h" |
40 | | #include "openssl/obj_mac.h" |
41 | | #include "prov/bio.h" |
42 | | #include "prov/implementations.h" |
43 | | #include "prov/endecoder_local.h" |
44 | | #include "internal/nelem.h" |
45 | | #include "prov/ml_dsa_codecs.h" |
46 | | #include "prov/ml_kem_codecs.h" |
47 | | #include "prov/lms_codecs.h" |
48 | | #include "providers/implementations/encode_decode/decode_der2key.inc" |
49 | | |
50 | | #ifndef OPENSSL_NO_SLH_DSA |
51 | | typedef struct { |
52 | | ASN1_OBJECT *oid; |
53 | | } BARE_ALGOR; |
54 | | |
55 | | typedef struct { |
56 | | BARE_ALGOR algor; |
57 | | ASN1_BIT_STRING *pubkey; |
58 | | } BARE_PUBKEY; |
59 | | |
60 | | ASN1_SEQUENCE(BARE_ALGOR) = { |
61 | | ASN1_SIMPLE(BARE_ALGOR, oid, ASN1_OBJECT), |
62 | 0 | } static_ASN1_SEQUENCE_END(BARE_ALGOR) |
63 | 0 |
|
64 | 0 | ASN1_SEQUENCE(BARE_PUBKEY) = { |
65 | 0 | ASN1_EMBED(BARE_PUBKEY, algor, BARE_ALGOR), |
66 | 0 | ASN1_SIMPLE(BARE_PUBKEY, pubkey, ASN1_BIT_STRING) |
67 | 0 | } static_ASN1_SEQUENCE_END(BARE_PUBKEY) |
68 | 0 | #endif /* OPENSSL_NO_SLH_DSA */ |
69 | 0 |
|
70 | 0 | struct der2key_ctx_st; /* Forward declaration */ |
71 | 0 | typedef int check_key_fn(void *, struct der2key_ctx_st *ctx); |
72 | 0 | typedef void adjust_key_fn(void *, struct der2key_ctx_st *ctx); |
73 | 0 | typedef void free_key_fn(void *); |
74 | 0 | typedef void *d2i_PKCS8_fn(const unsigned char **, long, |
75 | 0 | struct der2key_ctx_st *); |
76 | 0 | typedef void *d2i_PUBKEY_fn(const unsigned char **, long, |
77 | 0 | struct der2key_ctx_st *); |
78 | 0 | struct keytype_desc_st { |
79 | 0 | const char *keytype_name; |
80 | 0 | const OSSL_DISPATCH *fns; /* Keymgmt (to pilfer functions from) */ |
81 | 0 |
|
82 | 0 | /* The input structure name */ |
83 | 0 | const char *structure_name; |
84 | 0 |
|
85 | 0 | /* |
86 | 0 | * The EVP_PKEY_xxx type macro. Should be zero for type specific |
87 | 0 | * structures, non-zero when the outermost structure is PKCS#8 or |
88 | 0 | * SubjectPublicKeyInfo. This determines which of the function |
89 | 0 | * pointers below will be used. |
90 | 0 | */ |
91 | 0 | int evp_type; |
92 | 0 |
|
93 | 0 | /* The selection mask for OSSL_FUNC_decoder_does_selection() */ |
94 | 0 | int selection_mask; |
95 | 0 |
|
96 | 0 | /* For type specific decoders, we use the corresponding d2i */ |
97 | 0 | d2i_of_void *d2i_private_key; /* From type-specific DER */ |
98 | 0 | d2i_of_void *d2i_public_key; /* From type-specific DER */ |
99 | 0 | d2i_of_void *d2i_key_params; /* From type-specific DER */ |
100 | 0 | d2i_PKCS8_fn *d2i_PKCS8; /* Wrapped in a PrivateKeyInfo */ |
101 | 0 | d2i_PUBKEY_fn *d2i_PUBKEY; /* Wrapped in a SubjectPublicKeyInfo */ |
102 | 0 |
|
103 | 0 | /* |
104 | 0 | * For any key, we may need to check that the key meets expectations. |
105 | 0 | * This is useful when the same functions can decode several variants |
106 | 0 | * of a key. |
107 | 0 | */ |
108 | 0 | check_key_fn *check_key; |
109 | 0 |
|
110 | 0 | /* |
111 | 0 | * For any key, we may need to make provider specific adjustments, such |
112 | 0 | * as ensure the key carries the correct library context. |
113 | 0 | */ |
114 | 0 | adjust_key_fn *adjust_key; |
115 | 0 | /* {type}_free() */ |
116 | 0 | free_key_fn *free_key; |
117 | 0 | }; |
118 | 0 |
|
119 | 0 | /* |
120 | 0 | * Context used for DER to key decoding. |
121 | 0 | */ |
122 | 0 | struct der2key_ctx_st { |
123 | 0 | PROV_CTX *provctx; |
124 | 0 | char propq[OSSL_MAX_PROPQUERY_SIZE]; |
125 | 0 | const struct keytype_desc_st *desc; |
126 | 0 | /* The selection that is passed to der2key_decode() */ |
127 | 0 | int selection; |
128 | 0 | /* Flag used to signal that a failure is fatal */ |
129 | 0 | unsigned int flag_fatal : 1; |
130 | 0 | }; |
131 | 0 |
|
132 | 0 | typedef void *key_from_pkcs8_t(const PKCS8_PRIV_KEY_INFO *p8inf, |
133 | 0 | OSSL_LIB_CTX *libctx, const char *propq); |
134 | 0 | static void *der2key_decode_p8(const unsigned char **input_der, |
135 | 0 | long input_der_len, struct der2key_ctx_st *ctx, |
136 | 0 | key_from_pkcs8_t *key_from_pkcs8) |
137 | 0 | { |
138 | 0 | PKCS8_PRIV_KEY_INFO *p8inf = NULL; |
139 | 0 | const X509_ALGOR *alg = NULL; |
140 | 0 | void *key = NULL; |
141 | |
|
142 | 0 | if ((p8inf = d2i_PKCS8_PRIV_KEY_INFO(NULL, input_der, input_der_len)) != NULL |
143 | 0 | && PKCS8_pkey_get0(NULL, NULL, NULL, &alg, p8inf) |
144 | 0 | && (OBJ_obj2nid(alg->algorithm) == ctx->desc->evp_type |
145 | | /* Allow decoding sm2 private key with id_ecPublicKey */ |
146 | 0 | || (OBJ_obj2nid(alg->algorithm) == NID_X9_62_id_ecPublicKey |
147 | 0 | && ctx->desc->evp_type == NID_sm2))) |
148 | 0 | key = key_from_pkcs8(p8inf, PROV_LIBCTX_OF(ctx->provctx), ctx->propq); |
149 | 0 | PKCS8_PRIV_KEY_INFO_free(p8inf); |
150 | |
|
151 | 0 | return key; |
152 | 0 | } |
153 | | |
154 | | /* ---------------------------------------------------------------------- */ |
155 | | |
156 | | static OSSL_FUNC_decoder_freectx_fn der2key_freectx; |
157 | | static OSSL_FUNC_decoder_decode_fn der2key_decode; |
158 | | static OSSL_FUNC_decoder_export_object_fn der2key_export_object; |
159 | | static OSSL_FUNC_decoder_settable_ctx_params_fn der2key_settable_ctx_params; |
160 | | static OSSL_FUNC_decoder_set_ctx_params_fn der2key_set_ctx_params; |
161 | | |
162 | | static struct der2key_ctx_st * |
163 | | der2key_newctx(void *provctx, const struct keytype_desc_st *desc) |
164 | 0 | { |
165 | 0 | struct der2key_ctx_st *ctx = OPENSSL_zalloc(sizeof(*ctx)); |
166 | |
|
167 | 0 | if (ctx != NULL) { |
168 | 0 | ctx->provctx = provctx; |
169 | 0 | ctx->desc = desc; |
170 | 0 | } |
171 | 0 | return ctx; |
172 | 0 | } |
173 | | |
174 | | static const OSSL_PARAM *der2key_settable_ctx_params(ossl_unused void *provctx) |
175 | 0 | { |
176 | 0 | return der2key_set_ctx_params_list; |
177 | 0 | } |
178 | | |
179 | | static int der2key_set_ctx_params(void *vctx, const OSSL_PARAM params[]) |
180 | 0 | { |
181 | 0 | struct der2key_ctx_st *ctx = vctx; |
182 | 0 | struct der2key_set_ctx_params_st p; |
183 | 0 | char *str; |
184 | |
|
185 | 0 | if (ctx == NULL || !der2key_set_ctx_params_decoder(params, &p)) |
186 | 0 | return 0; |
187 | | |
188 | 0 | str = ctx->propq; |
189 | 0 | if (p.propq != NULL |
190 | 0 | && !OSSL_PARAM_get_utf8_string(p.propq, &str, sizeof(ctx->propq))) |
191 | 0 | return 0; |
192 | | |
193 | 0 | return 1; |
194 | 0 | } |
195 | | |
196 | | static void der2key_freectx(void *vctx) |
197 | 0 | { |
198 | 0 | struct der2key_ctx_st *ctx = vctx; |
199 | |
|
200 | 0 | OPENSSL_free(ctx); |
201 | 0 | } |
202 | | |
203 | | static int der2key_check_selection(int selection, |
204 | | const struct keytype_desc_st *desc) |
205 | 0 | { |
206 | | /* |
207 | | * The selections are kinda sorta "levels", i.e. each selection given |
208 | | * here is assumed to include those following. |
209 | | */ |
210 | 0 | int checks[] = { |
211 | 0 | OSSL_KEYMGMT_SELECT_PRIVATE_KEY, |
212 | 0 | OSSL_KEYMGMT_SELECT_PUBLIC_KEY, |
213 | 0 | OSSL_KEYMGMT_SELECT_ALL_PARAMETERS |
214 | 0 | }; |
215 | 0 | size_t i; |
216 | | |
217 | | /* The decoder implementations made here support guessing */ |
218 | 0 | if (selection == 0) |
219 | 0 | return 1; |
220 | | |
221 | 0 | for (i = 0; i < OSSL_NELEM(checks); i++) { |
222 | 0 | int check1 = (selection & checks[i]) != 0; |
223 | 0 | int check2 = (desc->selection_mask & checks[i]) != 0; |
224 | | |
225 | | /* |
226 | | * If the caller asked for the currently checked bit(s), return |
227 | | * whether the decoder description says it's supported. |
228 | | */ |
229 | 0 | if (check1) |
230 | 0 | return check2; |
231 | 0 | } |
232 | | |
233 | | /* This should be dead code, but just to be safe... */ |
234 | 0 | return 0; |
235 | 0 | } |
236 | | |
237 | | static int der2key_decode(void *vctx, OSSL_CORE_BIO *cin, int selection, |
238 | | OSSL_CALLBACK *data_cb, void *data_cbarg, |
239 | | OSSL_PASSPHRASE_CALLBACK *pw_cb, void *pw_cbarg) |
240 | 0 | { |
241 | 0 | struct der2key_ctx_st *ctx = vctx; |
242 | 0 | unsigned char *der = NULL; |
243 | 0 | const unsigned char *derp; |
244 | 0 | long der_len = 0; |
245 | 0 | void *key = NULL; |
246 | 0 | int ok = 0; |
247 | |
|
248 | 0 | ctx->selection = selection; |
249 | | /* |
250 | | * The caller is allowed to specify 0 as a selection mask, to have the |
251 | | * structure and key type guessed. For type-specific structures, this |
252 | | * is not recommended, as some structures are very similar. |
253 | | * Note that 0 isn't the same as OSSL_KEYMGMT_SELECT_ALL, as the latter |
254 | | * signifies a private key structure, where everything else is assumed |
255 | | * to be present as well. |
256 | | */ |
257 | 0 | if (selection == 0) |
258 | 0 | selection = ctx->desc->selection_mask; |
259 | 0 | if ((selection & ctx->desc->selection_mask) == 0) { |
260 | 0 | ERR_raise(ERR_LIB_PROV, ERR_R_PASSED_INVALID_ARGUMENT); |
261 | 0 | return 0; |
262 | 0 | } |
263 | | |
264 | 0 | ok = ossl_read_der(ctx->provctx, cin, &der, &der_len); |
265 | 0 | if (!ok) |
266 | 0 | goto next; |
267 | | |
268 | 0 | ok = 0; /* Assume that we fail */ |
269 | |
|
270 | 0 | ERR_set_mark(); |
271 | 0 | if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0) { |
272 | 0 | derp = der; |
273 | 0 | if (ctx->desc->d2i_PKCS8 != NULL) { |
274 | 0 | key = ctx->desc->d2i_PKCS8(&derp, der_len, ctx); |
275 | 0 | if (ctx->flag_fatal) { |
276 | 0 | ERR_clear_last_mark(); |
277 | 0 | goto end; |
278 | 0 | } |
279 | 0 | } else if (ctx->desc->d2i_private_key != NULL) { |
280 | 0 | key = ctx->desc->d2i_private_key(NULL, &derp, der_len); |
281 | 0 | } |
282 | 0 | if (key == NULL && ctx->selection != 0) { |
283 | 0 | ERR_clear_last_mark(); |
284 | 0 | goto next; |
285 | 0 | } |
286 | 0 | } |
287 | 0 | if (key == NULL && (selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0) { |
288 | 0 | derp = der; |
289 | 0 | if (ctx->desc->d2i_PUBKEY != NULL) |
290 | 0 | key = ctx->desc->d2i_PUBKEY(&derp, der_len, ctx); |
291 | 0 | else if (ctx->desc->d2i_public_key != NULL) |
292 | 0 | key = ctx->desc->d2i_public_key(NULL, &derp, der_len); |
293 | 0 | if (key == NULL && ctx->selection != 0) { |
294 | 0 | ERR_clear_last_mark(); |
295 | 0 | goto next; |
296 | 0 | } |
297 | 0 | } |
298 | 0 | if (key == NULL && (selection & OSSL_KEYMGMT_SELECT_ALL_PARAMETERS) != 0) { |
299 | 0 | derp = der; |
300 | 0 | if (ctx->desc->d2i_key_params != NULL) |
301 | 0 | key = ctx->desc->d2i_key_params(NULL, &derp, der_len); |
302 | 0 | if (key == NULL && ctx->selection != 0) { |
303 | 0 | ERR_clear_last_mark(); |
304 | 0 | goto next; |
305 | 0 | } |
306 | 0 | } |
307 | 0 | if (key == NULL) |
308 | 0 | ERR_clear_last_mark(); |
309 | 0 | else |
310 | 0 | ERR_pop_to_mark(); |
311 | | |
312 | | /* |
313 | | * Last minute check to see if this was the correct type of key. This |
314 | | * should never lead to a fatal error, i.e. the decoding itself was |
315 | | * correct, it was just an unexpected key type. This is generally for |
316 | | * classes of key types that have subtle variants, like RSA-PSS keys as |
317 | | * opposed to plain RSA keys. |
318 | | */ |
319 | 0 | if (key != NULL |
320 | 0 | && ctx->desc->check_key != NULL |
321 | 0 | && !ctx->desc->check_key(key, ctx)) { |
322 | 0 | ctx->desc->free_key(key); |
323 | 0 | key = NULL; |
324 | 0 | } |
325 | |
|
326 | 0 | if (key != NULL && ctx->desc->adjust_key != NULL) |
327 | 0 | ctx->desc->adjust_key(key, ctx); |
328 | |
|
329 | 0 | next: |
330 | | /* |
331 | | * Indicated that we successfully decoded something, or not at all. |
332 | | * Ending up "empty handed" is not an error. |
333 | | */ |
334 | 0 | ok = 1; |
335 | | |
336 | | /* |
337 | | * We free memory here so it's not held up during the callback, because |
338 | | * we know the process is recursive and the allocated chunks of memory |
339 | | * add up. |
340 | | */ |
341 | 0 | OPENSSL_free(der); |
342 | 0 | der = NULL; |
343 | |
|
344 | 0 | if (key != NULL) { |
345 | 0 | OSSL_PARAM params[4]; |
346 | 0 | int object_type = OSSL_OBJECT_PKEY; |
347 | |
|
348 | 0 | params[0] = OSSL_PARAM_construct_int(OSSL_OBJECT_PARAM_TYPE, &object_type); |
349 | |
|
350 | 0 | #ifndef OPENSSL_NO_SM2 |
351 | 0 | if (strcmp(ctx->desc->keytype_name, "EC") == 0 |
352 | 0 | && (EC_KEY_get_flags(key) & EC_FLAG_SM2_RANGE) != 0) |
353 | 0 | params[1] = OSSL_PARAM_construct_utf8_string(OSSL_OBJECT_PARAM_DATA_TYPE, |
354 | 0 | "SM2", 0); |
355 | 0 | else |
356 | 0 | #endif |
357 | 0 | params[1] = OSSL_PARAM_construct_utf8_string(OSSL_OBJECT_PARAM_DATA_TYPE, |
358 | 0 | (char *)ctx->desc->keytype_name, |
359 | 0 | 0); |
360 | | /* The address of the key becomes the octet string */ |
361 | 0 | params[2] = OSSL_PARAM_construct_octet_string(OSSL_OBJECT_PARAM_REFERENCE, |
362 | 0 | &key, sizeof(key)); |
363 | 0 | params[3] = OSSL_PARAM_construct_end(); |
364 | |
|
365 | 0 | ok = data_cb(params, data_cbarg); |
366 | 0 | } |
367 | |
|
368 | 0 | end: |
369 | 0 | ctx->desc->free_key(key); |
370 | 0 | OPENSSL_free(der); |
371 | |
|
372 | 0 | return ok; |
373 | 0 | } |
374 | | |
375 | | static int der2key_export_object(void *vctx, |
376 | | const void *reference, size_t reference_sz, |
377 | | OSSL_CALLBACK *export_cb, void *export_cbarg) |
378 | 0 | { |
379 | 0 | struct der2key_ctx_st *ctx = vctx; |
380 | 0 | OSSL_FUNC_keymgmt_export_fn *export = ossl_prov_get_keymgmt_export(ctx->desc->fns); |
381 | 0 | void *keydata; |
382 | |
|
383 | 0 | if (reference_sz == sizeof(keydata) && export != NULL) { |
384 | 0 | int selection = ctx->selection; |
385 | |
|
386 | 0 | if (selection == 0) |
387 | 0 | selection = OSSL_KEYMGMT_SELECT_ALL; |
388 | | /* The contents of the reference is the address to our object */ |
389 | 0 | keydata = *(void **)reference; |
390 | |
|
391 | 0 | return export(keydata, selection, export_cb, export_cbarg); |
392 | 0 | } |
393 | 0 | return 0; |
394 | 0 | } |
395 | | |
396 | | #define D2I_PUBKEY_NOCTX(n, f) \ |
397 | | static void * \ |
398 | | n##_d2i_PUBKEY(const unsigned char **der, long der_len, \ |
399 | | ossl_unused struct der2key_ctx_st *ctx) \ |
400 | 0 | { \ |
401 | 0 | return f(NULL, der, der_len); \ |
402 | 0 | } |
403 | | |
404 | | /* ---------------------------------------------------------------------- */ |
405 | | |
406 | | #ifndef OPENSSL_NO_DH |
407 | | #define dh_evp_type EVP_PKEY_DH |
408 | | #define dh_d2i_private_key NULL |
409 | | #define dh_d2i_public_key NULL |
410 | | #define dh_d2i_key_params (d2i_of_void *)d2i_DHparams |
411 | | #define dh_free (free_key_fn *)DH_free |
412 | | #define dh_check NULL |
413 | | |
414 | | static void *dh_d2i_PKCS8(const unsigned char **der, long der_len, |
415 | | struct der2key_ctx_st *ctx) |
416 | 0 | { |
417 | 0 | return der2key_decode_p8(der, der_len, ctx, |
418 | 0 | (key_from_pkcs8_t *)ossl_dh_key_from_pkcs8); |
419 | 0 | } |
420 | | |
421 | 0 | D2I_PUBKEY_NOCTX(dh, ossl_d2i_DH_PUBKEY) |
422 | 0 | D2I_PUBKEY_NOCTX(dhx, ossl_d2i_DHx_PUBKEY) |
423 | | |
424 | | static void dh_adjust(void *key, struct der2key_ctx_st *ctx) |
425 | 0 | { |
426 | 0 | ossl_dh_set0_libctx(key, PROV_LIBCTX_OF(ctx->provctx)); |
427 | 0 | } |
428 | | |
429 | | #define dhx_evp_type EVP_PKEY_DHX |
430 | | #define dhx_d2i_private_key NULL |
431 | | #define dhx_d2i_public_key NULL |
432 | | #define dhx_d2i_key_params (d2i_of_void *)d2i_DHxparams |
433 | | #define dhx_d2i_PKCS8 dh_d2i_PKCS8 |
434 | | #define dhx_free (free_key_fn *)DH_free |
435 | | #define dhx_check NULL |
436 | | #define dhx_adjust dh_adjust |
437 | | #endif |
438 | | |
439 | | /* ---------------------------------------------------------------------- */ |
440 | | |
441 | | #ifndef OPENSSL_NO_DSA |
442 | | #define dsa_evp_type EVP_PKEY_DSA |
443 | | #define dsa_d2i_private_key (d2i_of_void *)d2i_DSAPrivateKey |
444 | | #define dsa_d2i_public_key (d2i_of_void *)d2i_DSAPublicKey |
445 | | #define dsa_d2i_key_params (d2i_of_void *)d2i_DSAparams |
446 | | #define dsa_free (free_key_fn *)DSA_free |
447 | | #define dsa_check NULL |
448 | | |
449 | | static void *dsa_d2i_PKCS8(const unsigned char **der, long der_len, |
450 | | struct der2key_ctx_st *ctx) |
451 | 0 | { |
452 | 0 | return der2key_decode_p8(der, der_len, ctx, |
453 | 0 | (key_from_pkcs8_t *)ossl_dsa_key_from_pkcs8); |
454 | 0 | } |
455 | | |
456 | 0 | D2I_PUBKEY_NOCTX(dsa, ossl_d2i_DSA_PUBKEY) |
457 | | |
458 | | static void dsa_adjust(void *key, struct der2key_ctx_st *ctx) |
459 | 0 | { |
460 | 0 | ossl_dsa_set0_libctx(key, PROV_LIBCTX_OF(ctx->provctx)); |
461 | 0 | } |
462 | | #endif |
463 | | |
464 | | /* ---------------------------------------------------------------------- */ |
465 | | |
466 | | #ifndef OPENSSL_NO_EC |
467 | | #define ec_evp_type EVP_PKEY_EC |
468 | | #define ec_d2i_private_key (d2i_of_void *)d2i_ECPrivateKey |
469 | | #define ec_d2i_public_key NULL |
470 | | #define ec_d2i_key_params (d2i_of_void *)d2i_ECParameters |
471 | | #define ec_free (free_key_fn *)EC_KEY_free |
472 | | |
473 | | static void *ec_d2i_PKCS8(const unsigned char **der, long der_len, |
474 | | struct der2key_ctx_st *ctx) |
475 | 0 | { |
476 | 0 | return der2key_decode_p8(der, der_len, ctx, |
477 | 0 | (key_from_pkcs8_t *)ossl_ec_key_from_pkcs8); |
478 | 0 | } |
479 | | |
480 | 0 | D2I_PUBKEY_NOCTX(ec, d2i_EC_PUBKEY) |
481 | | |
482 | | static int ec_check(void *key, struct der2key_ctx_st *ctx) |
483 | 0 | { |
484 | | /* We're trying to be clever by comparing two truths */ |
485 | 0 | int ret = 0; |
486 | 0 | int sm2 = (EC_KEY_get_flags(key) & EC_FLAG_SM2_RANGE) != 0; |
487 | |
|
488 | 0 | if (sm2) |
489 | 0 | ret = ctx->desc->evp_type == EVP_PKEY_SM2 |
490 | 0 | || ctx->desc->evp_type == NID_X9_62_id_ecPublicKey; |
491 | 0 | else |
492 | 0 | ret = ctx->desc->evp_type != EVP_PKEY_SM2; |
493 | |
|
494 | 0 | return ret; |
495 | 0 | } |
496 | | |
497 | | static void ec_adjust(void *key, struct der2key_ctx_st *ctx) |
498 | 0 | { |
499 | 0 | ossl_ec_key_set0_libctx(key, PROV_LIBCTX_OF(ctx->provctx)); |
500 | 0 | } |
501 | | |
502 | | #ifndef OPENSSL_NO_ECX |
503 | | /* |
504 | | * ED25519, ED448, X25519, X448 only implement PKCS#8 and SubjectPublicKeyInfo, |
505 | | * so no d2i functions to be had. |
506 | | */ |
507 | | |
508 | | static void *ecx_d2i_PKCS8(const unsigned char **der, long der_len, |
509 | | struct der2key_ctx_st *ctx) |
510 | 0 | { |
511 | 0 | return der2key_decode_p8(der, der_len, ctx, |
512 | 0 | (key_from_pkcs8_t *)ossl_ecx_key_from_pkcs8); |
513 | 0 | } |
514 | | |
515 | 0 | D2I_PUBKEY_NOCTX(ed25519, ossl_d2i_ED25519_PUBKEY) |
516 | 0 | D2I_PUBKEY_NOCTX(ed448, ossl_d2i_ED448_PUBKEY) |
517 | 0 | D2I_PUBKEY_NOCTX(x25519, ossl_d2i_X25519_PUBKEY) |
518 | 0 | D2I_PUBKEY_NOCTX(x448, ossl_d2i_X448_PUBKEY) |
519 | | |
520 | | static void ecx_key_adjust(void *key, struct der2key_ctx_st *ctx) |
521 | 0 | { |
522 | 0 | ossl_ecx_key_set0_libctx(key, PROV_LIBCTX_OF(ctx->provctx)); |
523 | 0 | } |
524 | | |
525 | | #define ed25519_evp_type EVP_PKEY_ED25519 |
526 | | #define ed25519_d2i_private_key NULL |
527 | | #define ed25519_d2i_public_key NULL |
528 | | #define ed25519_d2i_key_params NULL |
529 | | #define ed25519_d2i_PKCS8 ecx_d2i_PKCS8 |
530 | | #define ed25519_free (free_key_fn *)ossl_ecx_key_free |
531 | | #define ed25519_check NULL |
532 | | #define ed25519_adjust ecx_key_adjust |
533 | | |
534 | | #define ed448_evp_type EVP_PKEY_ED448 |
535 | | #define ed448_d2i_private_key NULL |
536 | | #define ed448_d2i_public_key NULL |
537 | | #define ed448_d2i_key_params NULL |
538 | | #define ed448_d2i_PKCS8 ecx_d2i_PKCS8 |
539 | | #define ed448_free (free_key_fn *)ossl_ecx_key_free |
540 | | #define ed448_check NULL |
541 | | #define ed448_adjust ecx_key_adjust |
542 | | |
543 | | #define x25519_evp_type EVP_PKEY_X25519 |
544 | | #define x25519_d2i_private_key NULL |
545 | | #define x25519_d2i_public_key NULL |
546 | | #define x25519_d2i_key_params NULL |
547 | | #define x25519_d2i_PKCS8 ecx_d2i_PKCS8 |
548 | | #define x25519_free (free_key_fn *)ossl_ecx_key_free |
549 | | #define x25519_check NULL |
550 | | #define x25519_adjust ecx_key_adjust |
551 | | |
552 | | #define x448_evp_type EVP_PKEY_X448 |
553 | | #define x448_d2i_private_key NULL |
554 | | #define x448_d2i_public_key NULL |
555 | | #define x448_d2i_key_params NULL |
556 | | #define x448_d2i_PKCS8 ecx_d2i_PKCS8 |
557 | | #define x448_free (free_key_fn *)ossl_ecx_key_free |
558 | | #define x448_check NULL |
559 | | #define x448_adjust ecx_key_adjust |
560 | | #endif /* OPENSSL_NO_ECX */ |
561 | | |
562 | | #ifndef OPENSSL_NO_SM2 |
563 | | #define sm2_evp_type EVP_PKEY_SM2 |
564 | | #define sm2_d2i_private_key (d2i_of_void *)d2i_ECPrivateKey |
565 | | #define sm2_d2i_public_key NULL |
566 | | #define sm2_d2i_key_params (d2i_of_void *)d2i_ECParameters |
567 | | #define sm2_d2i_PUBKEY ec_d2i_PUBKEY |
568 | | #define sm2_free (free_key_fn *)EC_KEY_free |
569 | | #define sm2_check ec_check |
570 | | #define sm2_adjust ec_adjust |
571 | | |
572 | | static void *sm2_d2i_PKCS8(const unsigned char **der, long der_len, |
573 | | struct der2key_ctx_st *ctx) |
574 | 0 | { |
575 | 0 | return der2key_decode_p8(der, der_len, ctx, |
576 | 0 | (key_from_pkcs8_t *)ossl_ec_key_from_pkcs8); |
577 | 0 | } |
578 | | #endif |
579 | | |
580 | | #endif |
581 | | |
582 | | /* ---------------------------------------------------------------------- */ |
583 | | |
584 | | #ifndef OPENSSL_NO_ML_KEM |
585 | | static void * |
586 | | ml_kem_d2i_PKCS8(const uint8_t **der, long der_len, struct der2key_ctx_st *ctx) |
587 | 0 | { |
588 | 0 | ML_KEM_KEY *key; |
589 | |
|
590 | 0 | key = ossl_ml_kem_d2i_PKCS8(*der, der_len, ctx->desc->evp_type, |
591 | 0 | ctx->provctx, ctx->propq); |
592 | 0 | if (key != NULL) |
593 | 0 | *der += der_len; |
594 | 0 | return key; |
595 | 0 | } |
596 | | |
597 | | static ossl_inline void * |
598 | | ml_kem_d2i_PUBKEY(const uint8_t **der, long der_len, |
599 | | struct der2key_ctx_st *ctx) |
600 | 0 | { |
601 | 0 | ML_KEM_KEY *key; |
602 | |
|
603 | 0 | key = ossl_ml_kem_d2i_PUBKEY(*der, der_len, ctx->desc->evp_type, |
604 | 0 | ctx->provctx, ctx->propq); |
605 | 0 | if (key != NULL) |
606 | 0 | *der += der_len; |
607 | 0 | return key; |
608 | 0 | } |
609 | | |
610 | | #define ml_kem_512_evp_type EVP_PKEY_ML_KEM_512 |
611 | | #define ml_kem_512_d2i_private_key NULL |
612 | | #define ml_kem_512_d2i_public_key NULL |
613 | | #define ml_kem_512_d2i_key_params NULL |
614 | | #define ml_kem_512_d2i_PUBKEY ml_kem_d2i_PUBKEY |
615 | | #define ml_kem_512_d2i_PKCS8 ml_kem_d2i_PKCS8 |
616 | | #define ml_kem_512_free (free_key_fn *)ossl_ml_kem_key_free |
617 | | #define ml_kem_512_check NULL |
618 | | #define ml_kem_512_adjust NULL |
619 | | |
620 | | #define ml_kem_768_evp_type EVP_PKEY_ML_KEM_768 |
621 | | #define ml_kem_768_d2i_private_key NULL |
622 | | #define ml_kem_768_d2i_public_key NULL |
623 | | #define ml_kem_768_d2i_key_params NULL |
624 | | #define ml_kem_768_d2i_PUBKEY ml_kem_d2i_PUBKEY |
625 | | #define ml_kem_768_d2i_PKCS8 ml_kem_d2i_PKCS8 |
626 | | #define ml_kem_768_free (free_key_fn *)ossl_ml_kem_key_free |
627 | | #define ml_kem_768_check NULL |
628 | | #define ml_kem_768_adjust NULL |
629 | | |
630 | | #define ml_kem_1024_evp_type EVP_PKEY_ML_KEM_1024 |
631 | | #define ml_kem_1024_d2i_private_key NULL |
632 | | #define ml_kem_1024_d2i_public_key NULL |
633 | | #define ml_kem_1024_d2i_PUBKEY ml_kem_d2i_PUBKEY |
634 | | #define ml_kem_1024_d2i_PKCS8 ml_kem_d2i_PKCS8 |
635 | | #define ml_kem_1024_d2i_key_params NULL |
636 | | #define ml_kem_1024_free (free_key_fn *)ossl_ml_kem_key_free |
637 | | #define ml_kem_1024_check NULL |
638 | | #define ml_kem_1024_adjust NULL |
639 | | |
640 | | #endif |
641 | | |
642 | | #ifndef OPENSSL_NO_SLH_DSA |
643 | | static void * |
644 | | slh_dsa_d2i_PKCS8(const uint8_t **der, long der_len, struct der2key_ctx_st *ctx) |
645 | 0 | { |
646 | 0 | SLH_DSA_KEY *key = NULL, *ret = NULL; |
647 | 0 | OSSL_LIB_CTX *libctx = PROV_LIBCTX_OF(ctx->provctx); |
648 | 0 | PKCS8_PRIV_KEY_INFO *p8inf = NULL; |
649 | 0 | const unsigned char *p; |
650 | 0 | const X509_ALGOR *alg = NULL; |
651 | 0 | int plen, ptype; |
652 | |
|
653 | 0 | if ((p8inf = d2i_PKCS8_PRIV_KEY_INFO(NULL, der, der_len)) == NULL |
654 | 0 | || !PKCS8_pkey_get0(NULL, &p, &plen, &alg, p8inf)) |
655 | 0 | goto end; |
656 | | |
657 | | /* Algorithm parameters must be absent. */ |
658 | 0 | if ((X509_ALGOR_get0(NULL, &ptype, NULL, alg), ptype != V_ASN1_UNDEF)) { |
659 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_UNEXPECTED_KEY_PARAMETERS, |
660 | 0 | "unexpected parameters with a PKCS#8 %s private key", |
661 | 0 | ctx->desc->keytype_name); |
662 | 0 | goto end; |
663 | 0 | } |
664 | 0 | if (OBJ_obj2nid(alg->algorithm) != ctx->desc->evp_type) |
665 | 0 | goto end; |
666 | 0 | if ((key = ossl_slh_dsa_key_new(libctx, ctx->propq, |
667 | 0 | ctx->desc->keytype_name)) |
668 | 0 | == NULL) |
669 | 0 | goto end; |
670 | | |
671 | 0 | if (!ossl_slh_dsa_set_priv(key, p, plen)) |
672 | 0 | goto end; |
673 | 0 | ret = key; |
674 | 0 | end: |
675 | 0 | PKCS8_PRIV_KEY_INFO_free(p8inf); |
676 | 0 | if (ret == NULL) |
677 | 0 | ossl_slh_dsa_key_free(key); |
678 | 0 | return ret; |
679 | 0 | } |
680 | | |
681 | | static ossl_inline void *slh_dsa_d2i_PUBKEY(const uint8_t **der, long der_len, |
682 | | struct der2key_ctx_st *ctx) |
683 | 0 | { |
684 | 0 | int ok = 0; |
685 | 0 | OSSL_LIB_CTX *libctx = PROV_LIBCTX_OF(ctx->provctx); |
686 | 0 | SLH_DSA_KEY *ret = NULL; |
687 | 0 | BARE_PUBKEY *spki = NULL; |
688 | 0 | const uint8_t *end = *der; |
689 | 0 | size_t len; |
690 | |
|
691 | 0 | ret = ossl_slh_dsa_key_new(libctx, ctx->propq, ctx->desc->keytype_name); |
692 | 0 | if (ret == NULL) |
693 | 0 | return NULL; |
694 | 0 | len = ossl_slh_dsa_key_get_pub_len(ret); |
695 | | |
696 | | /*- |
697 | | * The DER ASN.1 encoding of SLH-DSA public keys prepends 18 bytes to the |
698 | | * encoded public key (since the largest public key size is 64 bytes): |
699 | | * |
700 | | * - 2 byte outer sequence tag and length |
701 | | * - 2 byte algorithm sequence tag and length |
702 | | * - 2 byte algorithm OID tag and length |
703 | | * - 9 byte algorithm OID |
704 | | * - 2 byte bit string tag and length |
705 | | * - 1 bitstring lead byte |
706 | | * |
707 | | * Check that we have the right OID, the bit string has no "bits left" and |
708 | | * that we consume all the input exactly. |
709 | | */ |
710 | 0 | if (der_len != 18 + (long)len) { |
711 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_BAD_ENCODING, |
712 | 0 | "unexpected %s public key length: %ld != %ld", |
713 | 0 | ctx->desc->keytype_name, der_len, |
714 | 0 | 18 + (long)len); |
715 | 0 | goto err; |
716 | 0 | } |
717 | | |
718 | 0 | if ((spki = OPENSSL_zalloc(sizeof(*spki))) == NULL) |
719 | 0 | goto err; |
720 | | |
721 | | /* The spki storage is freed on error */ |
722 | 0 | if (ASN1_item_d2i_ex((ASN1_VALUE **)&spki, &end, der_len, |
723 | 0 | ASN1_ITEM_rptr(BARE_PUBKEY), NULL, NULL) |
724 | 0 | == NULL) { |
725 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_BAD_ENCODING, |
726 | 0 | "malformed %s public key ASN.1 encoding", |
727 | 0 | ossl_slh_dsa_key_get_name(ret)); |
728 | 0 | goto err; |
729 | 0 | } |
730 | | |
731 | | /* The spki structure now owns some memory */ |
732 | 0 | if ((spki->pubkey->flags & 0x7) != 0 || end != *der + der_len) { |
733 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_BAD_ENCODING, |
734 | 0 | "malformed %s public key ASN.1 encoding", |
735 | 0 | ossl_slh_dsa_key_get_name(ret)); |
736 | 0 | goto err; |
737 | 0 | } |
738 | 0 | if (OBJ_cmp(OBJ_nid2obj(ctx->desc->evp_type), spki->algor.oid) != 0) { |
739 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_BAD_ENCODING, |
740 | 0 | "unexpected algorithm OID for an %s public key", |
741 | 0 | ossl_slh_dsa_key_get_name(ret)); |
742 | 0 | goto err; |
743 | 0 | } |
744 | | |
745 | 0 | if (!ossl_slh_dsa_set_pub(ret, spki->pubkey->data, spki->pubkey->length)) { |
746 | 0 | ERR_raise_data(ERR_LIB_PROV, PROV_R_BAD_ENCODING, |
747 | 0 | "failed to parse %s public key from the input data", |
748 | 0 | ossl_slh_dsa_key_get_name(ret)); |
749 | 0 | goto err; |
750 | 0 | } |
751 | 0 | ok = 1; |
752 | 0 | err: |
753 | 0 | if (spki != NULL) { |
754 | 0 | ASN1_OBJECT_free(spki->algor.oid); |
755 | 0 | ASN1_BIT_STRING_free(spki->pubkey); |
756 | 0 | OPENSSL_free(spki); |
757 | 0 | } |
758 | 0 | if (!ok) { |
759 | 0 | ossl_slh_dsa_key_free(ret); |
760 | 0 | ret = NULL; |
761 | 0 | } |
762 | 0 | return ret; |
763 | 0 | } |
764 | | |
765 | | #define slh_dsa_sha2_128s_evp_type EVP_PKEY_SLH_DSA_SHA2_128S |
766 | | #define slh_dsa_sha2_128s_d2i_private_key NULL |
767 | | #define slh_dsa_sha2_128s_d2i_public_key NULL |
768 | | #define slh_dsa_sha2_128s_d2i_key_params NULL |
769 | | #define slh_dsa_sha2_128s_d2i_PKCS8 slh_dsa_d2i_PKCS8 |
770 | | #define slh_dsa_sha2_128s_d2i_PUBKEY slh_dsa_d2i_PUBKEY |
771 | | #define slh_dsa_sha2_128s_free (free_key_fn *)ossl_slh_dsa_key_free |
772 | | #define slh_dsa_sha2_128s_check NULL |
773 | | #define slh_dsa_sha2_128s_adjust NULL |
774 | | |
775 | | #define slh_dsa_sha2_128f_evp_type EVP_PKEY_SLH_DSA_SHA2_128F |
776 | | #define slh_dsa_sha2_128f_d2i_private_key NULL |
777 | | #define slh_dsa_sha2_128f_d2i_public_key NULL |
778 | | #define slh_dsa_sha2_128f_d2i_key_params NULL |
779 | | #define slh_dsa_sha2_128f_d2i_PKCS8 slh_dsa_d2i_PKCS8 |
780 | | #define slh_dsa_sha2_128f_d2i_PUBKEY slh_dsa_d2i_PUBKEY |
781 | | #define slh_dsa_sha2_128f_free (free_key_fn *)ossl_slh_dsa_key_free |
782 | | #define slh_dsa_sha2_128f_check NULL |
783 | | #define slh_dsa_sha2_128f_adjust NULL |
784 | | |
785 | | #define slh_dsa_sha2_192s_evp_type EVP_PKEY_SLH_DSA_SHA2_192S |
786 | | #define slh_dsa_sha2_192s_d2i_private_key NULL |
787 | | #define slh_dsa_sha2_192s_d2i_public_key NULL |
788 | | #define slh_dsa_sha2_192s_d2i_key_params NULL |
789 | | #define slh_dsa_sha2_192s_d2i_PKCS8 slh_dsa_d2i_PKCS8 |
790 | | #define slh_dsa_sha2_192s_d2i_PUBKEY slh_dsa_d2i_PUBKEY |
791 | | #define slh_dsa_sha2_192s_free (free_key_fn *)ossl_slh_dsa_key_free |
792 | | #define slh_dsa_sha2_192s_check NULL |
793 | | #define slh_dsa_sha2_192s_adjust NULL |
794 | | |
795 | | #define slh_dsa_sha2_192f_evp_type EVP_PKEY_SLH_DSA_SHA2_192F |
796 | | #define slh_dsa_sha2_192f_d2i_private_key NULL |
797 | | #define slh_dsa_sha2_192f_d2i_public_key NULL |
798 | | #define slh_dsa_sha2_192f_d2i_key_params NULL |
799 | | #define slh_dsa_sha2_192f_d2i_PKCS8 slh_dsa_d2i_PKCS8 |
800 | | #define slh_dsa_sha2_192f_d2i_PUBKEY slh_dsa_d2i_PUBKEY |
801 | | #define slh_dsa_sha2_192f_free (free_key_fn *)ossl_slh_dsa_key_free |
802 | | #define slh_dsa_sha2_192f_check NULL |
803 | | #define slh_dsa_sha2_192f_adjust NULL |
804 | | |
805 | | #define slh_dsa_sha2_256s_evp_type EVP_PKEY_SLH_DSA_SHA2_256S |
806 | | #define slh_dsa_sha2_256s_d2i_private_key NULL |
807 | | #define slh_dsa_sha2_256s_d2i_public_key NULL |
808 | | #define slh_dsa_sha2_256s_d2i_key_params NULL |
809 | | #define slh_dsa_sha2_256s_d2i_PKCS8 slh_dsa_d2i_PKCS8 |
810 | | #define slh_dsa_sha2_256s_d2i_PUBKEY slh_dsa_d2i_PUBKEY |
811 | | #define slh_dsa_sha2_256s_free (free_key_fn *)ossl_slh_dsa_key_free |
812 | | #define slh_dsa_sha2_256s_check NULL |
813 | | #define slh_dsa_sha2_256s_adjust NULL |
814 | | |
815 | | #define slh_dsa_sha2_256f_evp_type EVP_PKEY_SLH_DSA_SHA2_256F |
816 | | #define slh_dsa_sha2_256f_d2i_private_key NULL |
817 | | #define slh_dsa_sha2_256f_d2i_public_key NULL |
818 | | #define slh_dsa_sha2_256f_d2i_key_params NULL |
819 | | #define slh_dsa_sha2_256f_d2i_PKCS8 slh_dsa_d2i_PKCS8 |
820 | | #define slh_dsa_sha2_256f_d2i_PUBKEY slh_dsa_d2i_PUBKEY |
821 | | #define slh_dsa_sha2_256f_free (free_key_fn *)ossl_slh_dsa_key_free |
822 | | #define slh_dsa_sha2_256f_check NULL |
823 | | #define slh_dsa_sha2_256f_adjust NULL |
824 | | |
825 | | #define slh_dsa_shake_128s_evp_type EVP_PKEY_SLH_DSA_SHAKE_128S |
826 | | #define slh_dsa_shake_128s_d2i_private_key NULL |
827 | | #define slh_dsa_shake_128s_d2i_public_key NULL |
828 | | #define slh_dsa_shake_128s_d2i_key_params NULL |
829 | | #define slh_dsa_shake_128s_d2i_PKCS8 slh_dsa_d2i_PKCS8 |
830 | | #define slh_dsa_shake_128s_d2i_PUBKEY slh_dsa_d2i_PUBKEY |
831 | | #define slh_dsa_shake_128s_free (free_key_fn *)ossl_slh_dsa_key_free |
832 | | #define slh_dsa_shake_128s_check NULL |
833 | | #define slh_dsa_shake_128s_adjust NULL |
834 | | |
835 | | #define slh_dsa_shake_128f_evp_type EVP_PKEY_SLH_DSA_SHAKE_128F |
836 | | #define slh_dsa_shake_128f_d2i_private_key NULL |
837 | | #define slh_dsa_shake_128f_d2i_public_key NULL |
838 | | #define slh_dsa_shake_128f_d2i_key_params NULL |
839 | | #define slh_dsa_shake_128f_d2i_PKCS8 slh_dsa_d2i_PKCS8 |
840 | | #define slh_dsa_shake_128f_d2i_PUBKEY slh_dsa_d2i_PUBKEY |
841 | | #define slh_dsa_shake_128f_free (free_key_fn *)ossl_slh_dsa_key_free |
842 | | #define slh_dsa_shake_128f_check NULL |
843 | | #define slh_dsa_shake_128f_adjust NULL |
844 | | |
845 | | #define slh_dsa_shake_192s_evp_type EVP_PKEY_SLH_DSA_SHAKE_192S |
846 | | #define slh_dsa_shake_192s_d2i_private_key NULL |
847 | | #define slh_dsa_shake_192s_d2i_public_key NULL |
848 | | #define slh_dsa_shake_192s_d2i_key_params NULL |
849 | | #define slh_dsa_shake_192s_d2i_PKCS8 slh_dsa_d2i_PKCS8 |
850 | | #define slh_dsa_shake_192s_d2i_PUBKEY slh_dsa_d2i_PUBKEY |
851 | | #define slh_dsa_shake_192s_free (free_key_fn *)ossl_slh_dsa_key_free |
852 | | #define slh_dsa_shake_192s_check NULL |
853 | | #define slh_dsa_shake_192s_adjust NULL |
854 | | |
855 | | #define slh_dsa_shake_192f_evp_type EVP_PKEY_SLH_DSA_SHAKE_192F |
856 | | #define slh_dsa_shake_192f_d2i_private_key NULL |
857 | | #define slh_dsa_shake_192f_d2i_public_key NULL |
858 | | #define slh_dsa_shake_192f_d2i_key_params NULL |
859 | | #define slh_dsa_shake_192f_d2i_PKCS8 slh_dsa_d2i_PKCS8 |
860 | | #define slh_dsa_shake_192f_d2i_PUBKEY slh_dsa_d2i_PUBKEY |
861 | | #define slh_dsa_shake_192f_free (free_key_fn *)ossl_slh_dsa_key_free |
862 | | #define slh_dsa_shake_192f_check NULL |
863 | | #define slh_dsa_shake_192f_adjust NULL |
864 | | |
865 | | #define slh_dsa_shake_256s_evp_type EVP_PKEY_SLH_DSA_SHAKE_256S |
866 | | #define slh_dsa_shake_256s_d2i_private_key NULL |
867 | | #define slh_dsa_shake_256s_d2i_public_key NULL |
868 | | #define slh_dsa_shake_256s_d2i_key_params NULL |
869 | | #define slh_dsa_shake_256s_d2i_PKCS8 slh_dsa_d2i_PKCS8 |
870 | | #define slh_dsa_shake_256s_d2i_PUBKEY slh_dsa_d2i_PUBKEY |
871 | | #define slh_dsa_shake_256s_free (free_key_fn *)ossl_slh_dsa_key_free |
872 | | #define slh_dsa_shake_256s_check NULL |
873 | | #define slh_dsa_shake_256s_adjust NULL |
874 | | |
875 | | #define slh_dsa_shake_256f_evp_type EVP_PKEY_SLH_DSA_SHAKE_256F |
876 | | #define slh_dsa_shake_256f_d2i_private_key NULL |
877 | | #define slh_dsa_shake_256f_d2i_public_key NULL |
878 | | #define slh_dsa_shake_256f_d2i_key_params NULL |
879 | | #define slh_dsa_shake_256f_d2i_PKCS8 slh_dsa_d2i_PKCS8 |
880 | | #define slh_dsa_shake_256f_d2i_PUBKEY slh_dsa_d2i_PUBKEY |
881 | | #define slh_dsa_shake_256f_free (free_key_fn *)ossl_slh_dsa_key_free |
882 | | #define slh_dsa_shake_256f_check NULL |
883 | | #define slh_dsa_shake_256f_adjust NULL |
884 | | #endif /* OPENSSL_NO_SLH_DSA */ |
885 | | |
886 | | /* ---------------------------------------------------------------------- */ |
887 | | |
888 | | #define rsa_evp_type EVP_PKEY_RSA |
889 | | #define rsa_d2i_private_key (d2i_of_void *)d2i_RSAPrivateKey |
890 | | #define rsa_d2i_public_key (d2i_of_void *)d2i_RSAPublicKey |
891 | | #define rsa_d2i_key_params NULL |
892 | | #define rsa_free (free_key_fn *)RSA_free |
893 | | |
894 | | static void *rsa_d2i_PKCS8(const unsigned char **der, long der_len, |
895 | | struct der2key_ctx_st *ctx) |
896 | 0 | { |
897 | 0 | return der2key_decode_p8(der, der_len, ctx, |
898 | 0 | (key_from_pkcs8_t *)ossl_rsa_key_from_pkcs8); |
899 | 0 | } |
900 | | |
901 | | static void * |
902 | | rsa_d2i_PUBKEY(const unsigned char **der, long der_len, |
903 | | ossl_unused struct der2key_ctx_st *ctx) |
904 | 0 | { |
905 | 0 | return d2i_RSA_PUBKEY(NULL, der, der_len); |
906 | 0 | } |
907 | | |
908 | | static int rsa_check(void *key, struct der2key_ctx_st *ctx) |
909 | 0 | { |
910 | 0 | int valid; |
911 | |
|
912 | 0 | switch (RSA_test_flags(key, RSA_FLAG_TYPE_MASK)) { |
913 | 0 | case RSA_FLAG_TYPE_RSA: |
914 | 0 | valid = (ctx->desc->evp_type == EVP_PKEY_RSA); |
915 | 0 | break; |
916 | 0 | case RSA_FLAG_TYPE_RSASSAPSS: |
917 | 0 | valid = (ctx->desc->evp_type == EVP_PKEY_RSA_PSS); |
918 | 0 | break; |
919 | 0 | default: |
920 | | /* Currently unsupported RSA key type */ |
921 | 0 | valid = 0; |
922 | 0 | } |
923 | | |
924 | 0 | valid = (valid && ossl_rsa_check_factors(key)); |
925 | |
|
926 | 0 | return valid; |
927 | 0 | } |
928 | | |
929 | | static void rsa_adjust(void *key, struct der2key_ctx_st *ctx) |
930 | 0 | { |
931 | 0 | ossl_rsa_set0_libctx(key, PROV_LIBCTX_OF(ctx->provctx)); |
932 | 0 | } |
933 | | |
934 | | #define rsapss_evp_type EVP_PKEY_RSA_PSS |
935 | | #define rsapss_d2i_private_key (d2i_of_void *)d2i_RSAPrivateKey |
936 | | #define rsapss_d2i_public_key (d2i_of_void *)d2i_RSAPublicKey |
937 | | #define rsapss_d2i_key_params NULL |
938 | | #define rsapss_d2i_PKCS8 rsa_d2i_PKCS8 |
939 | | #define rsapss_d2i_PUBKEY rsa_d2i_PUBKEY |
940 | | #define rsapss_free (free_key_fn *)RSA_free |
941 | | #define rsapss_check rsa_check |
942 | | #define rsapss_adjust rsa_adjust |
943 | | |
944 | | /* ---------------------------------------------------------------------- */ |
945 | | |
946 | | #ifndef OPENSSL_NO_ML_DSA |
947 | | static void * |
948 | | ml_dsa_d2i_PKCS8(const uint8_t **der, long der_len, struct der2key_ctx_st *ctx) |
949 | 0 | { |
950 | 0 | ML_DSA_KEY *key; |
951 | |
|
952 | 0 | key = ossl_ml_dsa_d2i_PKCS8(*der, der_len, ctx->desc->evp_type, |
953 | 0 | ctx->provctx, ctx->propq); |
954 | 0 | if (key != NULL) |
955 | 0 | *der += der_len; |
956 | 0 | return key; |
957 | 0 | } |
958 | | |
959 | | static ossl_inline void *ml_dsa_d2i_PUBKEY(const uint8_t **der, long der_len, |
960 | | struct der2key_ctx_st *ctx) |
961 | 0 | { |
962 | 0 | ML_DSA_KEY *key; |
963 | |
|
964 | 0 | key = ossl_ml_dsa_d2i_PUBKEY(*der, der_len, ctx->desc->evp_type, |
965 | 0 | ctx->provctx, ctx->propq); |
966 | 0 | if (key != NULL) |
967 | 0 | *der += der_len; |
968 | 0 | return key; |
969 | 0 | } |
970 | | |
971 | | #define ml_dsa_44_evp_type EVP_PKEY_ML_DSA_44 |
972 | | #define ml_dsa_44_d2i_private_key NULL |
973 | | #define ml_dsa_44_d2i_public_key NULL |
974 | | #define ml_dsa_44_d2i_key_params NULL |
975 | | #define ml_dsa_44_d2i_PUBKEY ml_dsa_d2i_PUBKEY |
976 | | #define ml_dsa_44_d2i_PKCS8 ml_dsa_d2i_PKCS8 |
977 | | #define ml_dsa_44_free (free_key_fn *)ossl_ml_dsa_key_free |
978 | | #define ml_dsa_44_check NULL |
979 | | #define ml_dsa_44_adjust NULL |
980 | | |
981 | | #define ml_dsa_65_evp_type EVP_PKEY_ML_DSA_65 |
982 | | #define ml_dsa_65_d2i_private_key NULL |
983 | | #define ml_dsa_65_d2i_public_key NULL |
984 | | #define ml_dsa_65_d2i_key_params NULL |
985 | | #define ml_dsa_65_d2i_PUBKEY ml_dsa_d2i_PUBKEY |
986 | | #define ml_dsa_65_d2i_PKCS8 ml_dsa_d2i_PKCS8 |
987 | | #define ml_dsa_65_free (free_key_fn *)ossl_ml_dsa_key_free |
988 | | #define ml_dsa_65_check NULL |
989 | | #define ml_dsa_65_adjust NULL |
990 | | |
991 | | #define ml_dsa_87_evp_type EVP_PKEY_ML_DSA_87 |
992 | | #define ml_dsa_87_d2i_private_key NULL |
993 | | #define ml_dsa_87_d2i_public_key NULL |
994 | | #define ml_dsa_87_d2i_PUBKEY ml_dsa_d2i_PUBKEY |
995 | | #define ml_dsa_87_d2i_PKCS8 ml_dsa_d2i_PKCS8 |
996 | | #define ml_dsa_87_d2i_key_params NULL |
997 | | #define ml_dsa_87_free (free_key_fn *)ossl_ml_dsa_key_free |
998 | | #define ml_dsa_87_check NULL |
999 | | #define ml_dsa_87_adjust NULL |
1000 | | |
1001 | | #endif |
1002 | | |
1003 | | /* ---------------------------------------------------------------------- */ |
1004 | | |
1005 | | #ifndef OPENSSL_NO_LMS |
1006 | | #define lms_evp_type EVP_PKEY_HSS_LMS |
1007 | | #define lms_free (free_key_fn *)ossl_lms_key_free |
1008 | | #define lms_check NULL |
1009 | | #define lms_adjust NULL |
1010 | | |
1011 | | static ossl_inline void *lms_d2i_PUBKEY(const uint8_t **der, long der_len, |
1012 | | struct der2key_ctx_st *ctx) |
1013 | | { |
1014 | | LMS_KEY *key; |
1015 | | |
1016 | | key = ossl_lms_d2i_PUBKEY(*der, der_len, ctx->provctx); |
1017 | | if (key != NULL) |
1018 | | *der += der_len; |
1019 | | return key; |
1020 | | } |
1021 | | #endif |
1022 | | /* ---------------------------------------------------------------------- */ |
1023 | | |
1024 | | /* |
1025 | | * The DO_ macros help define the selection mask and the method functions |
1026 | | * for each kind of object we want to decode. |
1027 | | */ |
1028 | | #define DO_type_specific_keypair(keytype) \ |
1029 | | "type-specific", keytype##_evp_type, \ |
1030 | | (OSSL_KEYMGMT_SELECT_KEYPAIR), \ |
1031 | | keytype##_d2i_private_key, \ |
1032 | | keytype##_d2i_public_key, \ |
1033 | | NULL, \ |
1034 | | NULL, \ |
1035 | | NULL, \ |
1036 | | keytype##_check, \ |
1037 | | keytype##_adjust, \ |
1038 | | keytype##_free |
1039 | | |
1040 | | #define DO_type_specific_pub(keytype) \ |
1041 | | "type-specific", keytype##_evp_type, \ |
1042 | | (OSSL_KEYMGMT_SELECT_PUBLIC_KEY), \ |
1043 | | NULL, \ |
1044 | | keytype##_d2i_public_key, \ |
1045 | | NULL, \ |
1046 | | NULL, \ |
1047 | | NULL, \ |
1048 | | keytype##_check, \ |
1049 | | keytype##_adjust, \ |
1050 | | keytype##_free |
1051 | | |
1052 | | #define DO_type_specific_priv(keytype) \ |
1053 | | "type-specific", keytype##_evp_type, \ |
1054 | | (OSSL_KEYMGMT_SELECT_PRIVATE_KEY), \ |
1055 | | keytype##_d2i_private_key, \ |
1056 | | NULL, \ |
1057 | | NULL, \ |
1058 | | NULL, \ |
1059 | | NULL, \ |
1060 | | keytype##_check, \ |
1061 | | keytype##_adjust, \ |
1062 | | keytype##_free |
1063 | | |
1064 | | #define DO_type_specific_params(keytype) \ |
1065 | | "type-specific", keytype##_evp_type, \ |
1066 | | (OSSL_KEYMGMT_SELECT_ALL_PARAMETERS), \ |
1067 | | NULL, \ |
1068 | | NULL, \ |
1069 | | keytype##_d2i_key_params, \ |
1070 | | NULL, \ |
1071 | | NULL, \ |
1072 | | keytype##_check, \ |
1073 | | keytype##_adjust, \ |
1074 | | keytype##_free |
1075 | | |
1076 | | #define DO_type_specific(keytype) \ |
1077 | | "type-specific", keytype##_evp_type, \ |
1078 | | (OSSL_KEYMGMT_SELECT_ALL), \ |
1079 | | keytype##_d2i_private_key, \ |
1080 | | keytype##_d2i_public_key, \ |
1081 | | keytype##_d2i_key_params, \ |
1082 | | NULL, \ |
1083 | | NULL, \ |
1084 | | keytype##_check, \ |
1085 | | keytype##_adjust, \ |
1086 | | keytype##_free |
1087 | | |
1088 | | #define DO_type_specific_no_pub(keytype) \ |
1089 | | "type-specific", keytype##_evp_type, \ |
1090 | | (OSSL_KEYMGMT_SELECT_PRIVATE_KEY \ |
1091 | | | OSSL_KEYMGMT_SELECT_ALL_PARAMETERS), \ |
1092 | | keytype##_d2i_private_key, \ |
1093 | | NULL, \ |
1094 | | keytype##_d2i_key_params, \ |
1095 | | NULL, \ |
1096 | | NULL, \ |
1097 | | keytype##_check, \ |
1098 | | keytype##_adjust, \ |
1099 | | keytype##_free |
1100 | | |
1101 | | #define DO_PrivateKeyInfo(keytype) \ |
1102 | | "PrivateKeyInfo", keytype##_evp_type, \ |
1103 | | (OSSL_KEYMGMT_SELECT_PRIVATE_KEY), \ |
1104 | | NULL, \ |
1105 | | NULL, \ |
1106 | | NULL, \ |
1107 | | keytype##_d2i_PKCS8, \ |
1108 | | NULL, \ |
1109 | | keytype##_check, \ |
1110 | | keytype##_adjust, \ |
1111 | | keytype##_free |
1112 | | |
1113 | | #define DO_SubjectPublicKeyInfo(keytype) \ |
1114 | | "SubjectPublicKeyInfo", keytype##_evp_type, \ |
1115 | | (OSSL_KEYMGMT_SELECT_PUBLIC_KEY), \ |
1116 | | NULL, \ |
1117 | | NULL, \ |
1118 | | NULL, \ |
1119 | | NULL, \ |
1120 | | keytype##_d2i_PUBKEY, \ |
1121 | | keytype##_check, \ |
1122 | | keytype##_adjust, \ |
1123 | | keytype##_free |
1124 | | |
1125 | | #define DO_DH(keytype) \ |
1126 | | "DH", keytype##_evp_type, \ |
1127 | | (OSSL_KEYMGMT_SELECT_ALL_PARAMETERS), \ |
1128 | | NULL, \ |
1129 | | NULL, \ |
1130 | | keytype##_d2i_key_params, \ |
1131 | | NULL, \ |
1132 | | NULL, \ |
1133 | | keytype##_check, \ |
1134 | | keytype##_adjust, \ |
1135 | | keytype##_free |
1136 | | |
1137 | | #define DO_DHX(keytype) \ |
1138 | | "DHX", keytype##_evp_type, \ |
1139 | | (OSSL_KEYMGMT_SELECT_ALL_PARAMETERS), \ |
1140 | | NULL, \ |
1141 | | NULL, \ |
1142 | | keytype##_d2i_key_params, \ |
1143 | | NULL, \ |
1144 | | NULL, \ |
1145 | | keytype##_check, \ |
1146 | | keytype##_adjust, \ |
1147 | | keytype##_free |
1148 | | |
1149 | | #define DO_DSA(keytype) \ |
1150 | | "DSA", keytype##_evp_type, \ |
1151 | | (OSSL_KEYMGMT_SELECT_ALL), \ |
1152 | | keytype##_d2i_private_key, \ |
1153 | | keytype##_d2i_public_key, \ |
1154 | | keytype##_d2i_key_params, \ |
1155 | | NULL, \ |
1156 | | NULL, \ |
1157 | | keytype##_check, \ |
1158 | | keytype##_adjust, \ |
1159 | | keytype##_free |
1160 | | |
1161 | | #define DO_EC(keytype) \ |
1162 | | "EC", keytype##_evp_type, \ |
1163 | | (OSSL_KEYMGMT_SELECT_PRIVATE_KEY \ |
1164 | | | OSSL_KEYMGMT_SELECT_ALL_PARAMETERS), \ |
1165 | | keytype##_d2i_private_key, \ |
1166 | | NULL, \ |
1167 | | keytype##_d2i_key_params, \ |
1168 | | NULL, \ |
1169 | | NULL, \ |
1170 | | keytype##_check, \ |
1171 | | keytype##_adjust, \ |
1172 | | keytype##_free |
1173 | | |
1174 | | #define DO_RSA(keytype) \ |
1175 | | "RSA", keytype##_evp_type, \ |
1176 | | (OSSL_KEYMGMT_SELECT_KEYPAIR), \ |
1177 | | keytype##_d2i_private_key, \ |
1178 | | keytype##_d2i_public_key, \ |
1179 | | NULL, \ |
1180 | | NULL, \ |
1181 | | NULL, \ |
1182 | | keytype##_check, \ |
1183 | | keytype##_adjust, \ |
1184 | | keytype##_free |
1185 | | |
1186 | | /* |
1187 | | * MAKE_DECODER is the single driver for creating OSSL_DISPATCH tables. |
1188 | | * It takes the following arguments: |
1189 | | * |
1190 | | * keytype_name The implementation key type as a string. |
1191 | | * keytype The implementation key type. This must correspond exactly |
1192 | | * to our existing keymgmt keytype names... in other words, |
1193 | | * there must exist an ossl_##keytype##_keymgmt_functions. |
1194 | | * type The type name for the set of functions that implement the |
1195 | | * decoder for the key type. This isn't necessarily the same |
1196 | | * as keytype. For example, the key types ed25519, ed448, |
1197 | | * x25519 and x448 are all handled by the same functions with |
1198 | | * the common type name ecx. |
1199 | | * kind The kind of support to implement. This translates into |
1200 | | * the DO_##kind macros above, to populate the keytype_desc_st |
1201 | | * structure. |
1202 | | */ |
1203 | | #define MAKE_DECODER(keytype_name, keytype, type, kind) \ |
1204 | | static const struct keytype_desc_st kind##_##keytype##_desc = { keytype_name, ossl_##keytype##_keymgmt_functions, \ |
1205 | | DO_##kind(keytype) }; \ |
1206 | | \ |
1207 | | static OSSL_FUNC_decoder_newctx_fn kind##_der2##keytype##_newctx; \ |
1208 | | \ |
1209 | | static void *kind##_der2##keytype##_newctx(void *provctx) \ |
1210 | 0 | { \ |
1211 | 0 | return der2key_newctx(provctx, &kind##_##keytype##_desc); \ |
1212 | 0 | } \ Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2dh_newctx Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2dh_newctx Unexecuted instantiation: decode_der2key.c:type_specific_params_der2dh_newctx Unexecuted instantiation: decode_der2key.c:DH_der2dh_newctx Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2dhx_newctx Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2dhx_newctx Unexecuted instantiation: decode_der2key.c:type_specific_params_der2dhx_newctx Unexecuted instantiation: decode_der2key.c:DHX_der2dhx_newctx Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2dsa_newctx Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2dsa_newctx Unexecuted instantiation: decode_der2key.c:type_specific_der2dsa_newctx Unexecuted instantiation: decode_der2key.c:DSA_der2dsa_newctx Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2ec_newctx Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2ec_newctx Unexecuted instantiation: decode_der2key.c:type_specific_no_pub_der2ec_newctx Unexecuted instantiation: decode_der2key.c:EC_der2ec_newctx Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2x25519_newctx Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2x25519_newctx Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2x448_newctx Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2x448_newctx Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2ed25519_newctx Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2ed25519_newctx Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2ed448_newctx Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2ed448_newctx Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2sm2_newctx Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2sm2_newctx Unexecuted instantiation: decode_der2key.c:type_specific_no_pub_der2sm2_newctx Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2ml_kem_512_newctx Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2ml_kem_512_newctx Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2ml_kem_768_newctx Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2ml_kem_768_newctx Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2ml_kem_1024_newctx Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2ml_kem_1024_newctx Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_sha2_128s_newctx Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_sha2_128f_newctx Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_sha2_192s_newctx Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_sha2_192f_newctx Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_sha2_256s_newctx Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_sha2_256f_newctx Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_shake_128s_newctx Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_shake_128f_newctx Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_shake_192s_newctx Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_shake_192f_newctx Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_shake_256s_newctx Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_shake_256f_newctx Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_sha2_128s_newctx Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_sha2_128f_newctx Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_sha2_192s_newctx Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_sha2_192f_newctx Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_sha2_256s_newctx Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_sha2_256f_newctx Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_shake_128s_newctx Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_shake_128f_newctx Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_shake_192s_newctx Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_shake_192f_newctx Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_shake_256s_newctx Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_shake_256f_newctx Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2rsa_newctx Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2rsa_newctx Unexecuted instantiation: decode_der2key.c:type_specific_keypair_der2rsa_newctx Unexecuted instantiation: decode_der2key.c:RSA_der2rsa_newctx Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2rsapss_newctx Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2rsapss_newctx Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2ml_dsa_44_newctx Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2ml_dsa_44_newctx Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2ml_dsa_65_newctx Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2ml_dsa_65_newctx Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2ml_dsa_87_newctx Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2ml_dsa_87_newctx |
1213 | | static int kind##_der2##keytype##_does_selection(void *provctx, \ |
1214 | | int selection) \ |
1215 | 0 | { \ |
1216 | 0 | return der2key_check_selection(selection, \ |
1217 | 0 | &kind##_##keytype##_desc); \ |
1218 | 0 | } \ Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2dh_does_selection Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2dh_does_selection Unexecuted instantiation: decode_der2key.c:type_specific_params_der2dh_does_selection Unexecuted instantiation: decode_der2key.c:DH_der2dh_does_selection Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2dhx_does_selection Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2dhx_does_selection Unexecuted instantiation: decode_der2key.c:type_specific_params_der2dhx_does_selection Unexecuted instantiation: decode_der2key.c:DHX_der2dhx_does_selection Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2dsa_does_selection Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2dsa_does_selection Unexecuted instantiation: decode_der2key.c:type_specific_der2dsa_does_selection Unexecuted instantiation: decode_der2key.c:DSA_der2dsa_does_selection Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2ec_does_selection Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2ec_does_selection Unexecuted instantiation: decode_der2key.c:type_specific_no_pub_der2ec_does_selection Unexecuted instantiation: decode_der2key.c:EC_der2ec_does_selection Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2x25519_does_selection Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2x25519_does_selection Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2x448_does_selection Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2x448_does_selection Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2ed25519_does_selection Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2ed25519_does_selection Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2ed448_does_selection Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2ed448_does_selection Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2sm2_does_selection Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2sm2_does_selection Unexecuted instantiation: decode_der2key.c:type_specific_no_pub_der2sm2_does_selection Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2ml_kem_512_does_selection Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2ml_kem_512_does_selection Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2ml_kem_768_does_selection Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2ml_kem_768_does_selection Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2ml_kem_1024_does_selection Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2ml_kem_1024_does_selection Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_sha2_128s_does_selection Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_sha2_128f_does_selection Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_sha2_192s_does_selection Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_sha2_192f_does_selection Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_sha2_256s_does_selection Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_sha2_256f_does_selection Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_shake_128s_does_selection Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_shake_128f_does_selection Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_shake_192s_does_selection Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_shake_192f_does_selection Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_shake_256s_does_selection Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_shake_256f_does_selection Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_sha2_128s_does_selection Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_sha2_128f_does_selection Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_sha2_192s_does_selection Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_sha2_192f_does_selection Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_sha2_256s_does_selection Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_sha2_256f_does_selection Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_shake_128s_does_selection Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_shake_128f_does_selection Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_shake_192s_does_selection Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_shake_192f_does_selection Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_shake_256s_does_selection Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_shake_256f_does_selection Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2rsa_does_selection Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2rsa_does_selection Unexecuted instantiation: decode_der2key.c:type_specific_keypair_der2rsa_does_selection Unexecuted instantiation: decode_der2key.c:RSA_der2rsa_does_selection Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2rsapss_does_selection Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2rsapss_does_selection Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2ml_dsa_44_does_selection Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2ml_dsa_44_does_selection Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2ml_dsa_65_does_selection Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2ml_dsa_65_does_selection Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2ml_dsa_87_does_selection Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2ml_dsa_87_does_selection |
1219 | | const OSSL_DISPATCH \ |
1220 | | ossl_##kind##_der_to_##keytype##_decoder_functions[] \ |
1221 | | = { \ |
1222 | | { OSSL_FUNC_DECODER_NEWCTX, \ |
1223 | | (void (*)(void))kind##_der2##keytype##_newctx }, \ |
1224 | | { OSSL_FUNC_DECODER_FREECTX, \ |
1225 | | (void (*)(void))der2key_freectx }, \ |
1226 | | { OSSL_FUNC_DECODER_DOES_SELECTION, \ |
1227 | | (void (*)(void))kind##_der2##keytype##_does_selection }, \ |
1228 | | { OSSL_FUNC_DECODER_DECODE, \ |
1229 | | (void (*)(void))der2key_decode }, \ |
1230 | | { OSSL_FUNC_DECODER_EXPORT_OBJECT, \ |
1231 | | (void (*)(void))der2key_export_object }, \ |
1232 | | { OSSL_FUNC_DECODER_SETTABLE_CTX_PARAMS, \ |
1233 | | (void (*)(void))der2key_settable_ctx_params }, \ |
1234 | | { OSSL_FUNC_DECODER_SET_CTX_PARAMS, \ |
1235 | | (void (*)(void))der2key_set_ctx_params }, \ |
1236 | | OSSL_DISPATCH_END \ |
1237 | | } |
1238 | | |
1239 | | #ifndef OPENSSL_NO_DH |
1240 | | MAKE_DECODER("DH", dh, dh, PrivateKeyInfo); |
1241 | | MAKE_DECODER("DH", dh, dh, SubjectPublicKeyInfo); |
1242 | | MAKE_DECODER("DH", dh, dh, type_specific_params); |
1243 | | MAKE_DECODER("DH", dh, dh, DH); |
1244 | | MAKE_DECODER("DHX", dhx, dhx, PrivateKeyInfo); |
1245 | | MAKE_DECODER("DHX", dhx, dhx, SubjectPublicKeyInfo); |
1246 | | MAKE_DECODER("DHX", dhx, dhx, type_specific_params); |
1247 | | MAKE_DECODER("DHX", dhx, dhx, DHX); |
1248 | | #endif |
1249 | | #ifndef OPENSSL_NO_DSA |
1250 | | MAKE_DECODER("DSA", dsa, dsa, PrivateKeyInfo); |
1251 | | MAKE_DECODER("DSA", dsa, dsa, SubjectPublicKeyInfo); |
1252 | | MAKE_DECODER("DSA", dsa, dsa, type_specific); |
1253 | | MAKE_DECODER("DSA", dsa, dsa, DSA); |
1254 | | #endif |
1255 | | #ifndef OPENSSL_NO_EC |
1256 | | MAKE_DECODER("EC", ec, ec, PrivateKeyInfo); |
1257 | | MAKE_DECODER("EC", ec, ec, SubjectPublicKeyInfo); |
1258 | | MAKE_DECODER("EC", ec, ec, type_specific_no_pub); |
1259 | | MAKE_DECODER("EC", ec, ec, EC); |
1260 | | #ifndef OPENSSL_NO_ECX |
1261 | | MAKE_DECODER("X25519", x25519, ecx, PrivateKeyInfo); |
1262 | | MAKE_DECODER("X25519", x25519, ecx, SubjectPublicKeyInfo); |
1263 | | MAKE_DECODER("X448", x448, ecx, PrivateKeyInfo); |
1264 | | MAKE_DECODER("X448", x448, ecx, SubjectPublicKeyInfo); |
1265 | | MAKE_DECODER("ED25519", ed25519, ecx, PrivateKeyInfo); |
1266 | | MAKE_DECODER("ED25519", ed25519, ecx, SubjectPublicKeyInfo); |
1267 | | MAKE_DECODER("ED448", ed448, ecx, PrivateKeyInfo); |
1268 | | MAKE_DECODER("ED448", ed448, ecx, SubjectPublicKeyInfo); |
1269 | | #endif |
1270 | | #ifndef OPENSSL_NO_SM2 |
1271 | | MAKE_DECODER("SM2", sm2, ec, PrivateKeyInfo); |
1272 | | MAKE_DECODER("SM2", sm2, ec, SubjectPublicKeyInfo); |
1273 | | MAKE_DECODER("SM2", sm2, sm2, type_specific_no_pub); |
1274 | | #endif |
1275 | | #endif |
1276 | | #ifndef OPENSSL_NO_ML_KEM |
1277 | | MAKE_DECODER("ML-KEM-512", ml_kem_512, ml_kem_512, PrivateKeyInfo); |
1278 | | MAKE_DECODER("ML-KEM-512", ml_kem_512, ml_kem_512, SubjectPublicKeyInfo); |
1279 | | MAKE_DECODER("ML-KEM-768", ml_kem_768, ml_kem_768, PrivateKeyInfo); |
1280 | | MAKE_DECODER("ML-KEM-768", ml_kem_768, ml_kem_768, SubjectPublicKeyInfo); |
1281 | | MAKE_DECODER("ML-KEM-1024", ml_kem_1024, ml_kem_1024, PrivateKeyInfo); |
1282 | | MAKE_DECODER("ML-KEM-1024", ml_kem_1024, ml_kem_1024, SubjectPublicKeyInfo); |
1283 | | #endif |
1284 | | #ifndef OPENSSL_NO_SLH_DSA |
1285 | | MAKE_DECODER("SLH-DSA-SHA2-128s", slh_dsa_sha2_128s, slh_dsa, PrivateKeyInfo); |
1286 | | MAKE_DECODER("SLH-DSA-SHA2-128f", slh_dsa_sha2_128f, slh_dsa, PrivateKeyInfo); |
1287 | | MAKE_DECODER("SLH-DSA-SHA2-192s", slh_dsa_sha2_192s, slh_dsa, PrivateKeyInfo); |
1288 | | MAKE_DECODER("SLH-DSA-SHA2-192f", slh_dsa_sha2_192f, slh_dsa, PrivateKeyInfo); |
1289 | | MAKE_DECODER("SLH-DSA-SHA2-256s", slh_dsa_sha2_256s, slh_dsa, PrivateKeyInfo); |
1290 | | MAKE_DECODER("SLH-DSA-SHA2-256f", slh_dsa_sha2_256f, slh_dsa, PrivateKeyInfo); |
1291 | | MAKE_DECODER("SLH-DSA-SHAKE-128s", slh_dsa_shake_128s, slh_dsa, PrivateKeyInfo); |
1292 | | MAKE_DECODER("SLH-DSA-SHAKE-128f", slh_dsa_shake_128f, slh_dsa, PrivateKeyInfo); |
1293 | | MAKE_DECODER("SLH-DSA-SHAKE-192s", slh_dsa_shake_192s, slh_dsa, PrivateKeyInfo); |
1294 | | MAKE_DECODER("SLH-DSA-SHAKE-192f", slh_dsa_shake_192f, slh_dsa, PrivateKeyInfo); |
1295 | | MAKE_DECODER("SLH-DSA-SHAKE-256s", slh_dsa_shake_256s, slh_dsa, PrivateKeyInfo); |
1296 | | MAKE_DECODER("SLH-DSA-SHAKE-256f", slh_dsa_shake_256f, slh_dsa, PrivateKeyInfo); |
1297 | | |
1298 | | MAKE_DECODER("SLH-DSA-SHA2-128s", slh_dsa_sha2_128s, slh_dsa, SubjectPublicKeyInfo); |
1299 | | MAKE_DECODER("SLH-DSA-SHA2-128f", slh_dsa_sha2_128f, slh_dsa, SubjectPublicKeyInfo); |
1300 | | MAKE_DECODER("SLH-DSA-SHA2-192s", slh_dsa_sha2_192s, slh_dsa, SubjectPublicKeyInfo); |
1301 | | MAKE_DECODER("SLH-DSA-SHA2-192f", slh_dsa_sha2_192f, slh_dsa, SubjectPublicKeyInfo); |
1302 | | MAKE_DECODER("SLH-DSA-SHA2-256s", slh_dsa_sha2_256s, slh_dsa, SubjectPublicKeyInfo); |
1303 | | MAKE_DECODER("SLH-DSA-SHA2-256f", slh_dsa_sha2_256f, slh_dsa, SubjectPublicKeyInfo); |
1304 | | MAKE_DECODER("SLH-DSA-SHAKE-128s", slh_dsa_shake_128s, slh_dsa, SubjectPublicKeyInfo); |
1305 | | MAKE_DECODER("SLH-DSA-SHAKE-128f", slh_dsa_shake_128f, slh_dsa, SubjectPublicKeyInfo); |
1306 | | MAKE_DECODER("SLH-DSA-SHAKE-192s", slh_dsa_shake_192s, slh_dsa, SubjectPublicKeyInfo); |
1307 | | MAKE_DECODER("SLH-DSA-SHAKE-192f", slh_dsa_shake_192f, slh_dsa, SubjectPublicKeyInfo); |
1308 | | MAKE_DECODER("SLH-DSA-SHAKE-256s", slh_dsa_shake_256s, slh_dsa, SubjectPublicKeyInfo); |
1309 | | MAKE_DECODER("SLH-DSA-SHAKE-256f", slh_dsa_shake_256f, slh_dsa, SubjectPublicKeyInfo); |
1310 | | #endif /* OPENSSL_NO_SLH_DSA */ |
1311 | | MAKE_DECODER("RSA", rsa, rsa, PrivateKeyInfo); |
1312 | | MAKE_DECODER("RSA", rsa, rsa, SubjectPublicKeyInfo); |
1313 | | MAKE_DECODER("RSA", rsa, rsa, type_specific_keypair); |
1314 | | MAKE_DECODER("RSA", rsa, rsa, RSA); |
1315 | | MAKE_DECODER("RSA-PSS", rsapss, rsapss, PrivateKeyInfo); |
1316 | | MAKE_DECODER("RSA-PSS", rsapss, rsapss, SubjectPublicKeyInfo); |
1317 | | |
1318 | | #ifndef OPENSSL_NO_ML_DSA |
1319 | | MAKE_DECODER("ML-DSA-44", ml_dsa_44, ml_dsa_44, PrivateKeyInfo); |
1320 | | MAKE_DECODER("ML-DSA-44", ml_dsa_44, ml_dsa_44, SubjectPublicKeyInfo); |
1321 | | MAKE_DECODER("ML-DSA-65", ml_dsa_65, ml_dsa_65, PrivateKeyInfo); |
1322 | | MAKE_DECODER("ML-DSA-65", ml_dsa_65, ml_dsa_65, SubjectPublicKeyInfo); |
1323 | | MAKE_DECODER("ML-DSA-87", ml_dsa_87, ml_dsa_87, PrivateKeyInfo); |
1324 | | MAKE_DECODER("ML-DSA-87", ml_dsa_87, ml_dsa_87, SubjectPublicKeyInfo); |
1325 | | #endif |
1326 | | |
1327 | | #ifndef OPENSSL_NO_LMS |
1328 | | MAKE_DECODER("LMS", lms, lms, SubjectPublicKeyInfo); |
1329 | | #endif |