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