/src/openssl32/providers/implementations/encode_decode/decode_der2key.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 2020-2024 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/core_dispatch.h> |
17 | | #include <openssl/core_names.h> |
18 | | #include <openssl/core_object.h> |
19 | | #include <openssl/crypto.h> |
20 | | #include <openssl/err.h> |
21 | | #include <openssl/params.h> |
22 | | #include <openssl/pem.h> /* PEM_BUFSIZE and public PEM functions */ |
23 | | #include <openssl/pkcs12.h> |
24 | | #include <openssl/x509.h> |
25 | | #include <openssl/proverr.h> |
26 | | #include "internal/cryptlib.h" /* ossl_assert() */ |
27 | | #include "internal/asn1.h" |
28 | | #include "crypto/dh.h" |
29 | | #include "crypto/dsa.h" |
30 | | #include "crypto/ec.h" |
31 | | #include "crypto/evp.h" |
32 | | #include "crypto/ecx.h" |
33 | | #include "crypto/rsa.h" |
34 | | #include "crypto/x509.h" |
35 | | #include "openssl/obj_mac.h" |
36 | | #include "prov/bio.h" |
37 | | #include "prov/implementations.h" |
38 | | #include "endecoder_local.h" |
39 | | #include "internal/nelem.h" |
40 | | |
41 | | struct der2key_ctx_st; /* Forward declaration */ |
42 | | typedef int check_key_fn(void *, struct der2key_ctx_st *ctx); |
43 | | typedef void adjust_key_fn(void *, struct der2key_ctx_st *ctx); |
44 | | typedef void free_key_fn(void *); |
45 | | typedef void *d2i_PKCS8_fn(void **, const unsigned char **, long, |
46 | | struct der2key_ctx_st *); |
47 | | struct keytype_desc_st { |
48 | | const char *keytype_name; |
49 | | const OSSL_DISPATCH *fns; /* Keymgmt (to pilfer functions from) */ |
50 | | |
51 | | /* The input structure name */ |
52 | | const char *structure_name; |
53 | | |
54 | | /* |
55 | | * The EVP_PKEY_xxx type macro. Should be zero for type specific |
56 | | * structures, non-zero when the outermost structure is PKCS#8 or |
57 | | * SubjectPublicKeyInfo. This determines which of the function |
58 | | * pointers below will be used. |
59 | | */ |
60 | | int evp_type; |
61 | | |
62 | | /* The selection mask for OSSL_FUNC_decoder_does_selection() */ |
63 | | int selection_mask; |
64 | | |
65 | | /* For type specific decoders, we use the corresponding d2i */ |
66 | | d2i_of_void *d2i_private_key; /* From type-specific DER */ |
67 | | d2i_of_void *d2i_public_key; /* From type-specific DER */ |
68 | | d2i_of_void *d2i_key_params; /* From type-specific DER */ |
69 | | d2i_PKCS8_fn *d2i_PKCS8; /* Wrapped in a PrivateKeyInfo */ |
70 | | d2i_of_void *d2i_PUBKEY; /* Wrapped in a SubjectPublicKeyInfo */ |
71 | | |
72 | | /* |
73 | | * For any key, we may need to check that the key meets expectations. |
74 | | * This is useful when the same functions can decode several variants |
75 | | * of a key. |
76 | | */ |
77 | | check_key_fn *check_key; |
78 | | |
79 | | /* |
80 | | * For any key, we may need to make provider specific adjustments, such |
81 | | * as ensure the key carries the correct library context. |
82 | | */ |
83 | | adjust_key_fn *adjust_key; |
84 | | /* {type}_free() */ |
85 | | free_key_fn *free_key; |
86 | | }; |
87 | | |
88 | | /* |
89 | | * Context used for DER to key decoding. |
90 | | */ |
91 | | struct der2key_ctx_st { |
92 | | PROV_CTX *provctx; |
93 | | char propq[OSSL_MAX_PROPQUERY_SIZE]; |
94 | | const struct keytype_desc_st *desc; |
95 | | /* The selection that is passed to der2key_decode() */ |
96 | | int selection; |
97 | | /* Flag used to signal that a failure is fatal */ |
98 | | unsigned int flag_fatal : 1; |
99 | | }; |
100 | | |
101 | | typedef void *key_from_pkcs8_t(const PKCS8_PRIV_KEY_INFO *p8inf, |
102 | | OSSL_LIB_CTX *libctx, const char *propq); |
103 | | static void *der2key_decode_p8(const unsigned char **input_der, |
104 | | long input_der_len, struct der2key_ctx_st *ctx, |
105 | | key_from_pkcs8_t *key_from_pkcs8) |
106 | 644k | { |
107 | 644k | PKCS8_PRIV_KEY_INFO *p8inf = NULL; |
108 | 644k | const X509_ALGOR *alg = NULL; |
109 | 644k | void *key = NULL; |
110 | | |
111 | 644k | if ((p8inf = d2i_PKCS8_PRIV_KEY_INFO(NULL, input_der, input_der_len)) != NULL |
112 | 644k | && PKCS8_pkey_get0(NULL, NULL, NULL, &alg, p8inf) |
113 | 644k | && (OBJ_obj2nid(alg->algorithm) == ctx->desc->evp_type |
114 | | /* Allow decoding sm2 private key with id_ecPublicKey */ |
115 | 15.1k | || (OBJ_obj2nid(alg->algorithm) == NID_X9_62_id_ecPublicKey |
116 | 8.11k | && ctx->desc->evp_type == NID_sm2))) |
117 | 7.35k | key = key_from_pkcs8(p8inf, PROV_LIBCTX_OF(ctx->provctx), ctx->propq); |
118 | 644k | PKCS8_PRIV_KEY_INFO_free(p8inf); |
119 | | |
120 | 644k | return key; |
121 | 644k | } |
122 | | |
123 | | /* ---------------------------------------------------------------------- */ |
124 | | |
125 | | static OSSL_FUNC_decoder_freectx_fn der2key_freectx; |
126 | | static OSSL_FUNC_decoder_decode_fn der2key_decode; |
127 | | static OSSL_FUNC_decoder_export_object_fn der2key_export_object; |
128 | | static OSSL_FUNC_decoder_settable_ctx_params_fn der2key_settable_ctx_params; |
129 | | static OSSL_FUNC_decoder_set_ctx_params_fn der2key_set_ctx_params; |
130 | | |
131 | | static struct der2key_ctx_st * |
132 | | der2key_newctx(void *provctx, const struct keytype_desc_st *desc) |
133 | 5.33M | { |
134 | 5.33M | struct der2key_ctx_st *ctx = OPENSSL_zalloc(sizeof(*ctx)); |
135 | | |
136 | 5.33M | if (ctx != NULL) { |
137 | 5.33M | ctx->provctx = provctx; |
138 | 5.33M | ctx->desc = desc; |
139 | 5.33M | } |
140 | 5.33M | return ctx; |
141 | 5.33M | } |
142 | | |
143 | | static const OSSL_PARAM *der2key_settable_ctx_params(ossl_unused void *provctx) |
144 | 0 | { |
145 | 0 | static const OSSL_PARAM settables[] = { |
146 | 0 | OSSL_PARAM_utf8_string(OSSL_DECODER_PARAM_PROPERTIES, NULL, 0), |
147 | 0 | OSSL_PARAM_END |
148 | 0 | }; |
149 | 0 | return settables; |
150 | 0 | } |
151 | | |
152 | | static int der2key_set_ctx_params(void *vctx, const OSSL_PARAM params[]) |
153 | 0 | { |
154 | 0 | struct der2key_ctx_st *ctx = vctx; |
155 | 0 | const OSSL_PARAM *p; |
156 | 0 | char *str = ctx->propq; |
157 | |
|
158 | 0 | p = OSSL_PARAM_locate_const(params, OSSL_DECODER_PARAM_PROPERTIES); |
159 | 0 | if (p != NULL && !OSSL_PARAM_get_utf8_string(p, &str, sizeof(ctx->propq))) |
160 | 0 | return 0; |
161 | | |
162 | 0 | return 1; |
163 | 0 | } |
164 | | |
165 | | static void der2key_freectx(void *vctx) |
166 | 5.33M | { |
167 | 5.33M | struct der2key_ctx_st *ctx = vctx; |
168 | | |
169 | 5.33M | OPENSSL_free(ctx); |
170 | 5.33M | } |
171 | | |
172 | | static int der2key_check_selection(int selection, |
173 | | const struct keytype_desc_st *desc) |
174 | 16.3M | { |
175 | | /* |
176 | | * The selections are kinda sorta "levels", i.e. each selection given |
177 | | * here is assumed to include those following. |
178 | | */ |
179 | 16.3M | int checks[] = { |
180 | 16.3M | OSSL_KEYMGMT_SELECT_PRIVATE_KEY, |
181 | 16.3M | OSSL_KEYMGMT_SELECT_PUBLIC_KEY, |
182 | 16.3M | OSSL_KEYMGMT_SELECT_ALL_PARAMETERS |
183 | 16.3M | }; |
184 | 16.3M | size_t i; |
185 | | |
186 | | /* The decoder implementations made here support guessing */ |
187 | 16.3M | if (selection == 0) |
188 | 102 | return 1; |
189 | | |
190 | 30.4M | for (i = 0; i < OSSL_NELEM(checks); i++) { |
191 | 30.4M | int check1 = (selection & checks[i]) != 0; |
192 | 30.4M | int check2 = (desc->selection_mask & checks[i]) != 0; |
193 | | |
194 | | /* |
195 | | * If the caller asked for the currently checked bit(s), return |
196 | | * whether the decoder description says it's supported. |
197 | | */ |
198 | 30.4M | if (check1) |
199 | 16.3M | return check2; |
200 | 30.4M | } |
201 | | |
202 | | /* This should be dead code, but just to be safe... */ |
203 | 0 | return 0; |
204 | 16.3M | } |
205 | | |
206 | | static int der2key_decode(void *vctx, OSSL_CORE_BIO *cin, int selection, |
207 | | OSSL_CALLBACK *data_cb, void *data_cbarg, |
208 | | OSSL_PASSPHRASE_CALLBACK *pw_cb, void *pw_cbarg) |
209 | 2.83M | { |
210 | 2.83M | struct der2key_ctx_st *ctx = vctx; |
211 | 2.83M | unsigned char *der = NULL; |
212 | 2.83M | const unsigned char *derp; |
213 | 2.83M | long der_len = 0; |
214 | 2.83M | void *key = NULL; |
215 | 2.83M | int ok = 0; |
216 | | |
217 | 2.83M | ctx->selection = selection; |
218 | | /* |
219 | | * The caller is allowed to specify 0 as a selection mark, to have the |
220 | | * structure and key type guessed. For type-specific structures, this |
221 | | * is not recommended, as some structures are very similar. |
222 | | * Note that 0 isn't the same as OSSL_KEYMGMT_SELECT_ALL, as the latter |
223 | | * signifies a private key structure, where everything else is assumed |
224 | | * to be present as well. |
225 | | */ |
226 | 2.83M | if (selection == 0) |
227 | 600k | selection = ctx->desc->selection_mask; |
228 | 2.83M | if ((selection & ctx->desc->selection_mask) == 0) { |
229 | 0 | ERR_raise(ERR_LIB_PROV, ERR_R_PASSED_INVALID_ARGUMENT); |
230 | 0 | return 0; |
231 | 0 | } |
232 | | |
233 | 2.83M | ok = ossl_read_der(ctx->provctx, cin, &der, &der_len); |
234 | 2.83M | if (!ok) |
235 | 471k | goto next; |
236 | | |
237 | 2.36M | ok = 0; /* Assume that we fail */ |
238 | | |
239 | 2.36M | ERR_set_mark(); |
240 | 2.36M | if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0) { |
241 | 1.32M | derp = der; |
242 | 1.32M | if (ctx->desc->d2i_PKCS8 != NULL) { |
243 | 913k | key = ctx->desc->d2i_PKCS8(NULL, &derp, der_len, ctx); |
244 | 913k | if (ctx->flag_fatal) { |
245 | 0 | ERR_clear_last_mark(); |
246 | 0 | goto end; |
247 | 0 | } |
248 | 913k | } else if (ctx->desc->d2i_private_key != NULL) { |
249 | 407k | key = ctx->desc->d2i_private_key(NULL, &derp, der_len); |
250 | 407k | } |
251 | 1.32M | if (key == NULL && ctx->selection != 0) { |
252 | 988k | ERR_clear_last_mark(); |
253 | 988k | goto next; |
254 | 988k | } |
255 | 1.32M | } |
256 | 1.37M | if (key == NULL && (selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0) { |
257 | 1.03M | derp = der; |
258 | 1.03M | if (ctx->desc->d2i_PUBKEY != NULL) |
259 | 985k | key = ctx->desc->d2i_PUBKEY(NULL, &derp, der_len); |
260 | 45.9k | else if (ctx->desc->d2i_public_key != NULL) |
261 | 45.9k | key = ctx->desc->d2i_public_key(NULL, &derp, der_len); |
262 | 1.03M | if (key == NULL && ctx->selection != 0) { |
263 | 399k | ERR_clear_last_mark(); |
264 | 399k | goto next; |
265 | 399k | } |
266 | 1.03M | } |
267 | 976k | if (key == NULL && (selection & OSSL_KEYMGMT_SELECT_ALL_PARAMETERS) != 0) { |
268 | 76.1k | derp = der; |
269 | 76.1k | if (ctx->desc->d2i_key_params != NULL) |
270 | 76.1k | key = ctx->desc->d2i_key_params(NULL, &derp, der_len); |
271 | 76.1k | if (key == NULL && ctx->selection != 0) { |
272 | 0 | ERR_clear_last_mark(); |
273 | 0 | goto next; |
274 | 0 | } |
275 | 76.1k | } |
276 | 976k | if (key == NULL) |
277 | 511k | ERR_clear_last_mark(); |
278 | 464k | else |
279 | 464k | ERR_pop_to_mark(); |
280 | | |
281 | | /* |
282 | | * Last minute check to see if this was the correct type of key. This |
283 | | * should never lead to a fatal error, i.e. the decoding itself was |
284 | | * correct, it was just an unexpected key type. This is generally for |
285 | | * classes of key types that have subtle variants, like RSA-PSS keys as |
286 | | * opposed to plain RSA keys. |
287 | | */ |
288 | 976k | if (key != NULL |
289 | 976k | && ctx->desc->check_key != NULL |
290 | 976k | && !ctx->desc->check_key(key, ctx)) { |
291 | 3.87k | ctx->desc->free_key(key); |
292 | 3.87k | key = NULL; |
293 | 3.87k | } |
294 | | |
295 | 976k | if (key != NULL && ctx->desc->adjust_key != NULL) |
296 | 460k | ctx->desc->adjust_key(key, ctx); |
297 | | |
298 | 2.83M | next: |
299 | | /* |
300 | | * Indicated that we successfully decoded something, or not at all. |
301 | | * Ending up "empty handed" is not an error. |
302 | | */ |
303 | 2.83M | ok = 1; |
304 | | |
305 | | /* |
306 | | * We free memory here so it's not held up during the callback, because |
307 | | * we know the process is recursive and the allocated chunks of memory |
308 | | * add up. |
309 | | */ |
310 | 2.83M | OPENSSL_free(der); |
311 | 2.83M | der = NULL; |
312 | | |
313 | 2.83M | if (key != NULL) { |
314 | 460k | OSSL_PARAM params[4]; |
315 | 460k | int object_type = OSSL_OBJECT_PKEY; |
316 | | |
317 | 460k | params[0] = |
318 | 460k | OSSL_PARAM_construct_int(OSSL_OBJECT_PARAM_TYPE, &object_type); |
319 | | |
320 | 460k | #ifndef OPENSSL_NO_SM2 |
321 | 460k | if (strcmp(ctx->desc->keytype_name, "EC") == 0 |
322 | 460k | && (EC_KEY_get_flags(key) & EC_FLAG_SM2_RANGE) != 0) |
323 | 7 | params[1] = |
324 | 7 | OSSL_PARAM_construct_utf8_string(OSSL_OBJECT_PARAM_DATA_TYPE, |
325 | 7 | "SM2", 0); |
326 | 460k | else |
327 | 460k | #endif |
328 | 460k | params[1] = |
329 | 460k | OSSL_PARAM_construct_utf8_string(OSSL_OBJECT_PARAM_DATA_TYPE, |
330 | 460k | (char *)ctx->desc->keytype_name, |
331 | 460k | 0); |
332 | | /* The address of the key becomes the octet string */ |
333 | 460k | params[2] = |
334 | 460k | OSSL_PARAM_construct_octet_string(OSSL_OBJECT_PARAM_REFERENCE, |
335 | 460k | &key, sizeof(key)); |
336 | 460k | params[3] = OSSL_PARAM_construct_end(); |
337 | | |
338 | 460k | ok = data_cb(params, data_cbarg); |
339 | 460k | } |
340 | | |
341 | 2.83M | end: |
342 | 2.83M | ctx->desc->free_key(key); |
343 | 2.83M | OPENSSL_free(der); |
344 | | |
345 | 2.83M | return ok; |
346 | 2.83M | } |
347 | | |
348 | | static int der2key_export_object(void *vctx, |
349 | | const void *reference, size_t reference_sz, |
350 | | OSSL_CALLBACK *export_cb, void *export_cbarg) |
351 | 0 | { |
352 | 0 | struct der2key_ctx_st *ctx = vctx; |
353 | 0 | OSSL_FUNC_keymgmt_export_fn *export = |
354 | 0 | ossl_prov_get_keymgmt_export(ctx->desc->fns); |
355 | 0 | void *keydata; |
356 | |
|
357 | 0 | if (reference_sz == sizeof(keydata) && export != NULL) { |
358 | 0 | int selection = ctx->selection; |
359 | |
|
360 | 0 | if (selection == 0) |
361 | 0 | selection = OSSL_KEYMGMT_SELECT_ALL; |
362 | | /* The contents of the reference is the address to our object */ |
363 | 0 | keydata = *(void **)reference; |
364 | |
|
365 | 0 | return export(keydata, selection, export_cb, export_cbarg); |
366 | 0 | } |
367 | 0 | return 0; |
368 | 0 | } |
369 | | |
370 | | /* ---------------------------------------------------------------------- */ |
371 | | |
372 | | #ifndef OPENSSL_NO_DH |
373 | | # define dh_evp_type EVP_PKEY_DH |
374 | | # define dh_d2i_private_key NULL |
375 | | # define dh_d2i_public_key NULL |
376 | | # define dh_d2i_key_params (d2i_of_void *)d2i_DHparams |
377 | | |
378 | | static void *dh_d2i_PKCS8(void **key, const unsigned char **der, long der_len, |
379 | | struct der2key_ctx_st *ctx) |
380 | 111k | { |
381 | 111k | return der2key_decode_p8(der, der_len, ctx, |
382 | 111k | (key_from_pkcs8_t *)ossl_dh_key_from_pkcs8); |
383 | 111k | } |
384 | | |
385 | | # define dh_d2i_PUBKEY (d2i_of_void *)ossl_d2i_DH_PUBKEY |
386 | | # define dh_free (free_key_fn *)DH_free |
387 | | # define dh_check NULL |
388 | | |
389 | | static void dh_adjust(void *key, struct der2key_ctx_st *ctx) |
390 | 35.1k | { |
391 | 35.1k | ossl_dh_set0_libctx(key, PROV_LIBCTX_OF(ctx->provctx)); |
392 | 35.1k | } |
393 | | |
394 | | # define dhx_evp_type EVP_PKEY_DHX |
395 | | # define dhx_d2i_private_key NULL |
396 | | # define dhx_d2i_public_key NULL |
397 | | # define dhx_d2i_key_params (d2i_of_void *)d2i_DHxparams |
398 | | # define dhx_d2i_PKCS8 dh_d2i_PKCS8 |
399 | | # define dhx_d2i_PUBKEY (d2i_of_void *)ossl_d2i_DHx_PUBKEY |
400 | | # define dhx_free (free_key_fn *)DH_free |
401 | | # define dhx_check NULL |
402 | | # define dhx_adjust dh_adjust |
403 | | #endif |
404 | | |
405 | | /* ---------------------------------------------------------------------- */ |
406 | | |
407 | | #ifndef OPENSSL_NO_DSA |
408 | | # define dsa_evp_type EVP_PKEY_DSA |
409 | | # define dsa_d2i_private_key (d2i_of_void *)d2i_DSAPrivateKey |
410 | | # define dsa_d2i_public_key (d2i_of_void *)d2i_DSAPublicKey |
411 | | # define dsa_d2i_key_params (d2i_of_void *)d2i_DSAparams |
412 | | |
413 | | static void *dsa_d2i_PKCS8(void **key, const unsigned char **der, long der_len, |
414 | | struct der2key_ctx_st *ctx) |
415 | 55.4k | { |
416 | 55.4k | return der2key_decode_p8(der, der_len, ctx, |
417 | 55.4k | (key_from_pkcs8_t *)ossl_dsa_key_from_pkcs8); |
418 | 55.4k | } |
419 | | |
420 | | # define dsa_d2i_PUBKEY (d2i_of_void *)ossl_d2i_DSA_PUBKEY |
421 | | # define dsa_free (free_key_fn *)DSA_free |
422 | | # define dsa_check NULL |
423 | | |
424 | | static void dsa_adjust(void *key, struct der2key_ctx_st *ctx) |
425 | 63.8k | { |
426 | 63.8k | ossl_dsa_set0_libctx(key, PROV_LIBCTX_OF(ctx->provctx)); |
427 | 63.8k | } |
428 | | #endif |
429 | | |
430 | | /* ---------------------------------------------------------------------- */ |
431 | | |
432 | | #ifndef OPENSSL_NO_EC |
433 | | # define ec_evp_type EVP_PKEY_EC |
434 | | # define ec_d2i_private_key (d2i_of_void *)d2i_ECPrivateKey |
435 | | # define ec_d2i_public_key NULL |
436 | | # define ec_d2i_key_params (d2i_of_void *)d2i_ECParameters |
437 | | |
438 | | static void *ec_d2i_PKCS8(void **key, const unsigned char **der, long der_len, |
439 | | struct der2key_ctx_st *ctx) |
440 | 55.5k | { |
441 | 55.5k | return der2key_decode_p8(der, der_len, ctx, |
442 | 55.5k | (key_from_pkcs8_t *)ossl_ec_key_from_pkcs8); |
443 | 55.5k | } |
444 | | |
445 | | # define ec_d2i_PUBKEY (d2i_of_void *)d2i_EC_PUBKEY |
446 | | # define ec_free (free_key_fn *)EC_KEY_free |
447 | | |
448 | | static int ec_check(void *key, struct der2key_ctx_st *ctx) |
449 | 257k | { |
450 | | /* We're trying to be clever by comparing two truths */ |
451 | 257k | int ret = 0; |
452 | 257k | int sm2 = (EC_KEY_get_flags(key) & EC_FLAG_SM2_RANGE) != 0; |
453 | | |
454 | 257k | if (sm2) |
455 | 7.59k | ret = ctx->desc->evp_type == EVP_PKEY_SM2 |
456 | 7.59k | || ctx->desc->evp_type == NID_X9_62_id_ecPublicKey; |
457 | 250k | else |
458 | 250k | ret = ctx->desc->evp_type != EVP_PKEY_SM2; |
459 | | |
460 | 257k | return ret; |
461 | 257k | } |
462 | | |
463 | | static void ec_adjust(void *key, struct der2key_ctx_st *ctx) |
464 | 254k | { |
465 | 254k | ossl_ec_key_set0_libctx(key, PROV_LIBCTX_OF(ctx->provctx)); |
466 | 254k | } |
467 | | |
468 | | # ifndef OPENSSL_NO_ECX |
469 | | /* |
470 | | * ED25519, ED448, X25519, X448 only implement PKCS#8 and SubjectPublicKeyInfo, |
471 | | * so no d2i functions to be had. |
472 | | */ |
473 | | |
474 | | static void *ecx_d2i_PKCS8(void **key, const unsigned char **der, long der_len, |
475 | | struct der2key_ctx_st *ctx) |
476 | 246k | { |
477 | 246k | return der2key_decode_p8(der, der_len, ctx, |
478 | 246k | (key_from_pkcs8_t *)ossl_ecx_key_from_pkcs8); |
479 | 246k | } |
480 | | |
481 | | static void ecx_key_adjust(void *key, struct der2key_ctx_st *ctx) |
482 | 3.74k | { |
483 | 3.74k | ossl_ecx_key_set0_libctx(key, PROV_LIBCTX_OF(ctx->provctx)); |
484 | 3.74k | } |
485 | | |
486 | | # define ed25519_evp_type EVP_PKEY_ED25519 |
487 | | # define ed25519_d2i_private_key NULL |
488 | | # define ed25519_d2i_public_key NULL |
489 | | # define ed25519_d2i_key_params NULL |
490 | | # define ed25519_d2i_PKCS8 ecx_d2i_PKCS8 |
491 | | # define ed25519_d2i_PUBKEY (d2i_of_void *)ossl_d2i_ED25519_PUBKEY |
492 | | # define ed25519_free (free_key_fn *)ossl_ecx_key_free |
493 | | # define ed25519_check NULL |
494 | | # define ed25519_adjust ecx_key_adjust |
495 | | |
496 | | # define ed448_evp_type EVP_PKEY_ED448 |
497 | | # define ed448_d2i_private_key NULL |
498 | | # define ed448_d2i_public_key NULL |
499 | | # define ed448_d2i_key_params NULL |
500 | | # define ed448_d2i_PKCS8 ecx_d2i_PKCS8 |
501 | | # define ed448_d2i_PUBKEY (d2i_of_void *)ossl_d2i_ED448_PUBKEY |
502 | | # define ed448_free (free_key_fn *)ossl_ecx_key_free |
503 | | # define ed448_check NULL |
504 | | # define ed448_adjust ecx_key_adjust |
505 | | |
506 | | # define x25519_evp_type EVP_PKEY_X25519 |
507 | | # define x25519_d2i_private_key NULL |
508 | | # define x25519_d2i_public_key NULL |
509 | | # define x25519_d2i_key_params NULL |
510 | | # define x25519_d2i_PKCS8 ecx_d2i_PKCS8 |
511 | | # define x25519_d2i_PUBKEY (d2i_of_void *)ossl_d2i_X25519_PUBKEY |
512 | | # define x25519_free (free_key_fn *)ossl_ecx_key_free |
513 | | # define x25519_check NULL |
514 | | # define x25519_adjust ecx_key_adjust |
515 | | |
516 | | # define x448_evp_type EVP_PKEY_X448 |
517 | | # define x448_d2i_private_key NULL |
518 | | # define x448_d2i_public_key NULL |
519 | | # define x448_d2i_key_params NULL |
520 | | # define x448_d2i_PKCS8 ecx_d2i_PKCS8 |
521 | | # define x448_d2i_PUBKEY (d2i_of_void *)ossl_d2i_X448_PUBKEY |
522 | | # define x448_free (free_key_fn *)ossl_ecx_key_free |
523 | | # define x448_check NULL |
524 | | # define x448_adjust ecx_key_adjust |
525 | | # endif /* OPENSSL_NO_ECX */ |
526 | | |
527 | | # ifndef OPENSSL_NO_SM2 |
528 | | # define sm2_evp_type EVP_PKEY_SM2 |
529 | | # define sm2_d2i_private_key (d2i_of_void *)d2i_ECPrivateKey |
530 | | # define sm2_d2i_public_key NULL |
531 | | # define sm2_d2i_key_params (d2i_of_void *)d2i_ECParameters |
532 | | |
533 | | static void *sm2_d2i_PKCS8(void **key, const unsigned char **der, long der_len, |
534 | | struct der2key_ctx_st *ctx) |
535 | 61.9k | { |
536 | 61.9k | return der2key_decode_p8(der, der_len, ctx, |
537 | 61.9k | (key_from_pkcs8_t *)ossl_ec_key_from_pkcs8); |
538 | 61.9k | } |
539 | | |
540 | | # define sm2_d2i_PUBKEY (d2i_of_void *)d2i_EC_PUBKEY |
541 | | # define sm2_free (free_key_fn *)EC_KEY_free |
542 | | # define sm2_check ec_check |
543 | | # define sm2_adjust ec_adjust |
544 | | # endif |
545 | | #endif |
546 | | |
547 | | /* ---------------------------------------------------------------------- */ |
548 | | |
549 | | #define rsa_evp_type EVP_PKEY_RSA |
550 | | #define rsa_d2i_private_key (d2i_of_void *)d2i_RSAPrivateKey |
551 | | #define rsa_d2i_public_key (d2i_of_void *)d2i_RSAPublicKey |
552 | | #define rsa_d2i_key_params NULL |
553 | | |
554 | | static void *rsa_d2i_PKCS8(void **key, const unsigned char **der, long der_len, |
555 | | struct der2key_ctx_st *ctx) |
556 | 113k | { |
557 | 113k | return der2key_decode_p8(der, der_len, ctx, |
558 | 113k | (key_from_pkcs8_t *)ossl_rsa_key_from_pkcs8); |
559 | 113k | } |
560 | | |
561 | | #define rsa_d2i_PUBKEY (d2i_of_void *)d2i_RSA_PUBKEY |
562 | | #define rsa_free (free_key_fn *)RSA_free |
563 | | |
564 | | static int rsa_check(void *key, struct der2key_ctx_st *ctx) |
565 | 75.0k | { |
566 | 75.0k | switch (RSA_test_flags(key, RSA_FLAG_TYPE_MASK)) { |
567 | 39.6k | case RSA_FLAG_TYPE_RSA: |
568 | 39.6k | return ctx->desc->evp_type == EVP_PKEY_RSA; |
569 | 35.3k | case RSA_FLAG_TYPE_RSASSAPSS: |
570 | 35.3k | return ctx->desc->evp_type == EVP_PKEY_RSA_PSS; |
571 | 75.0k | } |
572 | | |
573 | | /* Currently unsupported RSA key type */ |
574 | 0 | return 0; |
575 | 75.0k | } |
576 | | |
577 | | static void rsa_adjust(void *key, struct der2key_ctx_st *ctx) |
578 | 103k | { |
579 | 103k | ossl_rsa_set0_libctx(key, PROV_LIBCTX_OF(ctx->provctx)); |
580 | 103k | } |
581 | | |
582 | | #define rsapss_evp_type EVP_PKEY_RSA_PSS |
583 | | #define rsapss_d2i_private_key (d2i_of_void *)d2i_RSAPrivateKey |
584 | | #define rsapss_d2i_public_key (d2i_of_void *)d2i_RSAPublicKey |
585 | | #define rsapss_d2i_key_params NULL |
586 | | #define rsapss_d2i_PKCS8 rsa_d2i_PKCS8 |
587 | | #define rsapss_d2i_PUBKEY (d2i_of_void *)d2i_RSA_PUBKEY |
588 | | #define rsapss_free (free_key_fn *)RSA_free |
589 | | #define rsapss_check rsa_check |
590 | | #define rsapss_adjust rsa_adjust |
591 | | |
592 | | /* ---------------------------------------------------------------------- */ |
593 | | |
594 | | /* |
595 | | * The DO_ macros help define the selection mask and the method functions |
596 | | * for each kind of object we want to decode. |
597 | | */ |
598 | | #define DO_type_specific_keypair(keytype) \ |
599 | | "type-specific", keytype##_evp_type, \ |
600 | | ( OSSL_KEYMGMT_SELECT_KEYPAIR ), \ |
601 | | keytype##_d2i_private_key, \ |
602 | | keytype##_d2i_public_key, \ |
603 | | NULL, \ |
604 | | NULL, \ |
605 | | NULL, \ |
606 | | keytype##_check, \ |
607 | | keytype##_adjust, \ |
608 | | keytype##_free |
609 | | |
610 | | #define DO_type_specific_pub(keytype) \ |
611 | | "type-specific", keytype##_evp_type, \ |
612 | | ( OSSL_KEYMGMT_SELECT_PUBLIC_KEY ), \ |
613 | | NULL, \ |
614 | | keytype##_d2i_public_key, \ |
615 | | NULL, \ |
616 | | NULL, \ |
617 | | NULL, \ |
618 | | keytype##_check, \ |
619 | | keytype##_adjust, \ |
620 | | keytype##_free |
621 | | |
622 | | #define DO_type_specific_priv(keytype) \ |
623 | | "type-specific", keytype##_evp_type, \ |
624 | | ( OSSL_KEYMGMT_SELECT_PRIVATE_KEY ), \ |
625 | | keytype##_d2i_private_key, \ |
626 | | NULL, \ |
627 | | NULL, \ |
628 | | NULL, \ |
629 | | NULL, \ |
630 | | keytype##_check, \ |
631 | | keytype##_adjust, \ |
632 | | keytype##_free |
633 | | |
634 | | #define DO_type_specific_params(keytype) \ |
635 | | "type-specific", keytype##_evp_type, \ |
636 | | ( OSSL_KEYMGMT_SELECT_ALL_PARAMETERS ), \ |
637 | | NULL, \ |
638 | | NULL, \ |
639 | | keytype##_d2i_key_params, \ |
640 | | NULL, \ |
641 | | NULL, \ |
642 | | keytype##_check, \ |
643 | | keytype##_adjust, \ |
644 | | keytype##_free |
645 | | |
646 | | #define DO_type_specific(keytype) \ |
647 | | "type-specific", keytype##_evp_type, \ |
648 | | ( OSSL_KEYMGMT_SELECT_ALL ), \ |
649 | | keytype##_d2i_private_key, \ |
650 | | keytype##_d2i_public_key, \ |
651 | | keytype##_d2i_key_params, \ |
652 | | NULL, \ |
653 | | NULL, \ |
654 | | keytype##_check, \ |
655 | | keytype##_adjust, \ |
656 | | keytype##_free |
657 | | |
658 | | #define DO_type_specific_no_pub(keytype) \ |
659 | | "type-specific", keytype##_evp_type, \ |
660 | | ( OSSL_KEYMGMT_SELECT_PRIVATE_KEY \ |
661 | | | OSSL_KEYMGMT_SELECT_ALL_PARAMETERS ), \ |
662 | | keytype##_d2i_private_key, \ |
663 | | NULL, \ |
664 | | keytype##_d2i_key_params, \ |
665 | | NULL, \ |
666 | | NULL, \ |
667 | | keytype##_check, \ |
668 | | keytype##_adjust, \ |
669 | | keytype##_free |
670 | | |
671 | | #define DO_PrivateKeyInfo(keytype) \ |
672 | | "PrivateKeyInfo", keytype##_evp_type, \ |
673 | | ( OSSL_KEYMGMT_SELECT_PRIVATE_KEY ), \ |
674 | | NULL, \ |
675 | | NULL, \ |
676 | | NULL, \ |
677 | | keytype##_d2i_PKCS8, \ |
678 | | NULL, \ |
679 | | keytype##_check, \ |
680 | | keytype##_adjust, \ |
681 | | keytype##_free |
682 | | |
683 | | #define DO_SubjectPublicKeyInfo(keytype) \ |
684 | | "SubjectPublicKeyInfo", keytype##_evp_type, \ |
685 | | ( OSSL_KEYMGMT_SELECT_PUBLIC_KEY ), \ |
686 | | NULL, \ |
687 | | NULL, \ |
688 | | NULL, \ |
689 | | NULL, \ |
690 | | keytype##_d2i_PUBKEY, \ |
691 | | keytype##_check, \ |
692 | | keytype##_adjust, \ |
693 | | keytype##_free |
694 | | |
695 | | #define DO_DH(keytype) \ |
696 | | "DH", keytype##_evp_type, \ |
697 | | ( OSSL_KEYMGMT_SELECT_ALL_PARAMETERS ), \ |
698 | | NULL, \ |
699 | | NULL, \ |
700 | | keytype##_d2i_key_params, \ |
701 | | NULL, \ |
702 | | NULL, \ |
703 | | keytype##_check, \ |
704 | | keytype##_adjust, \ |
705 | | keytype##_free |
706 | | |
707 | | #define DO_DHX(keytype) \ |
708 | | "DHX", keytype##_evp_type, \ |
709 | | ( OSSL_KEYMGMT_SELECT_ALL_PARAMETERS ), \ |
710 | | NULL, \ |
711 | | NULL, \ |
712 | | keytype##_d2i_key_params, \ |
713 | | NULL, \ |
714 | | NULL, \ |
715 | | keytype##_check, \ |
716 | | keytype##_adjust, \ |
717 | | keytype##_free |
718 | | |
719 | | #define DO_DSA(keytype) \ |
720 | | "DSA", keytype##_evp_type, \ |
721 | | ( OSSL_KEYMGMT_SELECT_ALL ), \ |
722 | | keytype##_d2i_private_key, \ |
723 | | keytype##_d2i_public_key, \ |
724 | | keytype##_d2i_key_params, \ |
725 | | NULL, \ |
726 | | NULL, \ |
727 | | keytype##_check, \ |
728 | | keytype##_adjust, \ |
729 | | keytype##_free |
730 | | |
731 | | #define DO_EC(keytype) \ |
732 | | "EC", keytype##_evp_type, \ |
733 | | ( OSSL_KEYMGMT_SELECT_PRIVATE_KEY \ |
734 | | | OSSL_KEYMGMT_SELECT_ALL_PARAMETERS ), \ |
735 | | keytype##_d2i_private_key, \ |
736 | | NULL, \ |
737 | | keytype##_d2i_key_params, \ |
738 | | NULL, \ |
739 | | NULL, \ |
740 | | keytype##_check, \ |
741 | | keytype##_adjust, \ |
742 | | keytype##_free |
743 | | |
744 | | #define DO_RSA(keytype) \ |
745 | | "RSA", keytype##_evp_type, \ |
746 | | ( OSSL_KEYMGMT_SELECT_KEYPAIR ), \ |
747 | | keytype##_d2i_private_key, \ |
748 | | keytype##_d2i_public_key, \ |
749 | | NULL, \ |
750 | | NULL, \ |
751 | | NULL, \ |
752 | | keytype##_check, \ |
753 | | keytype##_adjust, \ |
754 | | keytype##_free |
755 | | |
756 | | /* |
757 | | * MAKE_DECODER is the single driver for creating OSSL_DISPATCH tables. |
758 | | * It takes the following arguments: |
759 | | * |
760 | | * keytype_name The implementation key type as a string. |
761 | | * keytype The implementation key type. This must correspond exactly |
762 | | * to our existing keymgmt keytype names... in other words, |
763 | | * there must exist an ossl_##keytype##_keymgmt_functions. |
764 | | * type The type name for the set of functions that implement the |
765 | | * decoder for the key type. This isn't necessarily the same |
766 | | * as keytype. For example, the key types ed25519, ed448, |
767 | | * x25519 and x448 are all handled by the same functions with |
768 | | * the common type name ecx. |
769 | | * kind The kind of support to implement. This translates into |
770 | | * the DO_##kind macros above, to populate the keytype_desc_st |
771 | | * structure. |
772 | | */ |
773 | | #define MAKE_DECODER(keytype_name, keytype, type, kind) \ |
774 | | static const struct keytype_desc_st kind##_##keytype##_desc = \ |
775 | | { keytype_name, ossl_##keytype##_keymgmt_functions, \ |
776 | | DO_##kind(keytype) }; \ |
777 | | \ |
778 | | static OSSL_FUNC_decoder_newctx_fn kind##_der2##keytype##_newctx; \ |
779 | | \ |
780 | | static void *kind##_der2##keytype##_newctx(void *provctx) \ |
781 | 4.36M | { \ |
782 | 4.36M | return der2key_newctx(provctx, &kind##_##keytype##_desc); \ |
783 | 4.36M | } \ decode_der2key.c:PrivateKeyInfo_der2dh_newctx Line | Count | Source | 781 | 145k | { \ | 782 | 145k | return der2key_newctx(provctx, &kind##_##keytype##_desc); \ | 783 | 145k | } \ |
decode_der2key.c:SubjectPublicKeyInfo_der2dh_newctx Line | Count | Source | 781 | 39.2k | { \ | 782 | 39.2k | return der2key_newctx(provctx, &kind##_##keytype##_desc); \ | 783 | 39.2k | } \ |
decode_der2key.c:type_specific_params_der2dh_newctx Line | Count | Source | 781 | 16.4k | { \ | 782 | 16.4k | return der2key_newctx(provctx, &kind##_##keytype##_desc); \ | 783 | 16.4k | } \ |
decode_der2key.c:DH_der2dh_newctx Line | Count | Source | 781 | 16.4k | { \ | 782 | 16.4k | return der2key_newctx(provctx, &kind##_##keytype##_desc); \ | 783 | 16.4k | } \ |
decode_der2key.c:PrivateKeyInfo_der2dhx_newctx Line | Count | Source | 781 | 145k | { \ | 782 | 145k | return der2key_newctx(provctx, &kind##_##keytype##_desc); \ | 783 | 145k | } \ |
decode_der2key.c:SubjectPublicKeyInfo_der2dhx_newctx Line | Count | Source | 781 | 62.5k | { \ | 782 | 62.5k | return der2key_newctx(provctx, &kind##_##keytype##_desc); \ | 783 | 62.5k | } \ |
decode_der2key.c:type_specific_params_der2dhx_newctx Line | Count | Source | 781 | 16.4k | { \ | 782 | 16.4k | return der2key_newctx(provctx, &kind##_##keytype##_desc); \ | 783 | 16.4k | } \ |
decode_der2key.c:DHX_der2dhx_newctx Line | Count | Source | 781 | 16.4k | { \ | 782 | 16.4k | return der2key_newctx(provctx, &kind##_##keytype##_desc); \ | 783 | 16.4k | } \ |
decode_der2key.c:PrivateKeyInfo_der2dsa_newctx Line | Count | Source | 781 | 147k | { \ | 782 | 147k | return der2key_newctx(provctx, &kind##_##keytype##_desc); \ | 783 | 147k | } \ |
decode_der2key.c:SubjectPublicKeyInfo_der2dsa_newctx Line | Count | Source | 781 | 126k | { \ | 782 | 126k | return der2key_newctx(provctx, &kind##_##keytype##_desc); \ | 783 | 126k | } \ |
decode_der2key.c:type_specific_der2dsa_newctx Line | Count | Source | 781 | 257k | { \ | 782 | 257k | return der2key_newctx(provctx, &kind##_##keytype##_desc); \ | 783 | 257k | } \ |
decode_der2key.c:DSA_der2dsa_newctx Line | Count | Source | 781 | 257k | { \ | 782 | 257k | return der2key_newctx(provctx, &kind##_##keytype##_desc); \ | 783 | 257k | } \ |
decode_der2key.c:PrivateKeyInfo_der2ec_newctx Line | Count | Source | 781 | 145k | { \ | 782 | 145k | return der2key_newctx(provctx, &kind##_##keytype##_desc); \ | 783 | 145k | } \ |
decode_der2key.c:SubjectPublicKeyInfo_der2ec_newctx Line | Count | Source | 781 | 458k | { \ | 782 | 458k | return der2key_newctx(provctx, &kind##_##keytype##_desc); \ | 783 | 458k | } \ |
decode_der2key.c:type_specific_no_pub_der2ec_newctx Line | Count | Source | 781 | 145k | { \ | 782 | 145k | return der2key_newctx(provctx, &kind##_##keytype##_desc); \ | 783 | 145k | } \ |
decode_der2key.c:EC_der2ec_newctx Line | Count | Source | 781 | 145k | { \ | 782 | 145k | return der2key_newctx(provctx, &kind##_##keytype##_desc); \ | 783 | 145k | } \ |
decode_der2key.c:PrivateKeyInfo_der2x25519_newctx Line | Count | Source | 781 | 145k | { \ | 782 | 145k | return der2key_newctx(provctx, &kind##_##keytype##_desc); \ | 783 | 145k | } \ |
decode_der2key.c:SubjectPublicKeyInfo_der2x25519_newctx Line | Count | Source | 781 | 17.5k | { \ | 782 | 17.5k | return der2key_newctx(provctx, &kind##_##keytype##_desc); \ | 783 | 17.5k | } \ |
decode_der2key.c:PrivateKeyInfo_der2x448_newctx Line | Count | Source | 781 | 145k | { \ | 782 | 145k | return der2key_newctx(provctx, &kind##_##keytype##_desc); \ | 783 | 145k | } \ |
decode_der2key.c:SubjectPublicKeyInfo_der2x448_newctx Line | Count | Source | 781 | 25.4k | { \ | 782 | 25.4k | return der2key_newctx(provctx, &kind##_##keytype##_desc); \ | 783 | 25.4k | } \ |
decode_der2key.c:PrivateKeyInfo_der2ed25519_newctx Line | Count | Source | 781 | 145k | { \ | 782 | 145k | return der2key_newctx(provctx, &kind##_##keytype##_desc); \ | 783 | 145k | } \ |
decode_der2key.c:SubjectPublicKeyInfo_der2ed25519_newctx Line | Count | Source | 781 | 30.3k | { \ | 782 | 30.3k | return der2key_newctx(provctx, &kind##_##keytype##_desc); \ | 783 | 30.3k | } \ |
decode_der2key.c:PrivateKeyInfo_der2ed448_newctx Line | Count | Source | 781 | 145k | { \ | 782 | 145k | return der2key_newctx(provctx, &kind##_##keytype##_desc); \ | 783 | 145k | } \ |
decode_der2key.c:SubjectPublicKeyInfo_der2ed448_newctx Line | Count | Source | 781 | 18.1k | { \ | 782 | 18.1k | return der2key_newctx(provctx, &kind##_##keytype##_desc); \ | 783 | 18.1k | } \ |
decode_der2key.c:PrivateKeyInfo_der2sm2_newctx Line | Count | Source | 781 | 145k | { \ | 782 | 145k | return der2key_newctx(provctx, &kind##_##keytype##_desc); \ | 783 | 145k | } \ |
decode_der2key.c:SubjectPublicKeyInfo_der2sm2_newctx Line | Count | Source | 781 | 458k | { \ | 782 | 458k | return der2key_newctx(provctx, &kind##_##keytype##_desc); \ | 783 | 458k | } \ |
decode_der2key.c:type_specific_no_pub_der2sm2_newctx Line | Count | Source | 781 | 76.4k | { \ | 782 | 76.4k | return der2key_newctx(provctx, &kind##_##keytype##_desc); \ | 783 | 76.4k | } \ |
decode_der2key.c:PrivateKeyInfo_der2rsa_newctx Line | Count | Source | 781 | 145k | { \ | 782 | 145k | return der2key_newctx(provctx, &kind##_##keytype##_desc); \ | 783 | 145k | } \ |
decode_der2key.c:SubjectPublicKeyInfo_der2rsa_newctx Line | Count | Source | 781 | 84.7k | { \ | 782 | 84.7k | return der2key_newctx(provctx, &kind##_##keytype##_desc); \ | 783 | 84.7k | } \ |
decode_der2key.c:type_specific_keypair_der2rsa_newctx Line | Count | Source | 781 | 213k | { \ | 782 | 213k | return der2key_newctx(provctx, &kind##_##keytype##_desc); \ | 783 | 213k | } \ |
decode_der2key.c:RSA_der2rsa_newctx Line | Count | Source | 781 | 213k | { \ | 782 | 213k | return der2key_newctx(provctx, &kind##_##keytype##_desc); \ | 783 | 213k | } \ |
decode_der2key.c:PrivateKeyInfo_der2rsapss_newctx Line | Count | Source | 781 | 145k | { \ | 782 | 145k | return der2key_newctx(provctx, &kind##_##keytype##_desc); \ | 783 | 145k | } \ |
decode_der2key.c:SubjectPublicKeyInfo_der2rsapss_newctx Line | Count | Source | 781 | 63.6k | { \ | 782 | 63.6k | return der2key_newctx(provctx, &kind##_##keytype##_desc); \ | 783 | 63.6k | } \ |
|
784 | | static int kind##_der2##keytype##_does_selection(void *provctx, \ |
785 | | int selection) \ |
786 | 16.2M | { \ |
787 | 16.2M | return der2key_check_selection(selection, \ |
788 | 16.2M | &kind##_##keytype##_desc); \ |
789 | 16.2M | } \ decode_der2key.c:PrivateKeyInfo_der2dh_does_selection Line | Count | Source | 786 | 506k | { \ | 787 | 506k | return der2key_check_selection(selection, \ | 788 | 506k | &kind##_##keytype##_desc); \ | 789 | 506k | } \ |
decode_der2key.c:SubjectPublicKeyInfo_der2dh_does_selection Line | Count | Source | 786 | 506k | { \ | 787 | 506k | return der2key_check_selection(selection, \ | 788 | 506k | &kind##_##keytype##_desc); \ | 789 | 506k | } \ |
decode_der2key.c:type_specific_params_der2dh_does_selection Line | Count | Source | 786 | 506k | { \ | 787 | 506k | return der2key_check_selection(selection, \ | 788 | 506k | &kind##_##keytype##_desc); \ | 789 | 506k | } \ |
decode_der2key.c:DH_der2dh_does_selection Line | Count | Source | 786 | 506k | { \ | 787 | 506k | return der2key_check_selection(selection, \ | 788 | 506k | &kind##_##keytype##_desc); \ | 789 | 506k | } \ |
decode_der2key.c:PrivateKeyInfo_der2dhx_does_selection Line | Count | Source | 786 | 506k | { \ | 787 | 506k | return der2key_check_selection(selection, \ | 788 | 506k | &kind##_##keytype##_desc); \ | 789 | 506k | } \ |
decode_der2key.c:SubjectPublicKeyInfo_der2dhx_does_selection Line | Count | Source | 786 | 506k | { \ | 787 | 506k | return der2key_check_selection(selection, \ | 788 | 506k | &kind##_##keytype##_desc); \ | 789 | 506k | } \ |
decode_der2key.c:type_specific_params_der2dhx_does_selection Line | Count | Source | 786 | 506k | { \ | 787 | 506k | return der2key_check_selection(selection, \ | 788 | 506k | &kind##_##keytype##_desc); \ | 789 | 506k | } \ |
decode_der2key.c:DHX_der2dhx_does_selection Line | Count | Source | 786 | 506k | { \ | 787 | 506k | return der2key_check_selection(selection, \ | 788 | 506k | &kind##_##keytype##_desc); \ | 789 | 506k | } \ |
decode_der2key.c:PrivateKeyInfo_der2dsa_does_selection Line | Count | Source | 786 | 506k | { \ | 787 | 506k | return der2key_check_selection(selection, \ | 788 | 506k | &kind##_##keytype##_desc); \ | 789 | 506k | } \ |
decode_der2key.c:SubjectPublicKeyInfo_der2dsa_does_selection Line | Count | Source | 786 | 506k | { \ | 787 | 506k | return der2key_check_selection(selection, \ | 788 | 506k | &kind##_##keytype##_desc); \ | 789 | 506k | } \ |
decode_der2key.c:type_specific_der2dsa_does_selection Line | Count | Source | 786 | 506k | { \ | 787 | 506k | return der2key_check_selection(selection, \ | 788 | 506k | &kind##_##keytype##_desc); \ | 789 | 506k | } \ |
decode_der2key.c:DSA_der2dsa_does_selection Line | Count | Source | 786 | 506k | { \ | 787 | 506k | return der2key_check_selection(selection, \ | 788 | 506k | &kind##_##keytype##_desc); \ | 789 | 506k | } \ |
decode_der2key.c:PrivateKeyInfo_der2ec_does_selection Line | Count | Source | 786 | 506k | { \ | 787 | 506k | return der2key_check_selection(selection, \ | 788 | 506k | &kind##_##keytype##_desc); \ | 789 | 506k | } \ |
decode_der2key.c:SubjectPublicKeyInfo_der2ec_does_selection Line | Count | Source | 786 | 506k | { \ | 787 | 506k | return der2key_check_selection(selection, \ | 788 | 506k | &kind##_##keytype##_desc); \ | 789 | 506k | } \ |
decode_der2key.c:type_specific_no_pub_der2ec_does_selection Line | Count | Source | 786 | 506k | { \ | 787 | 506k | return der2key_check_selection(selection, \ | 788 | 506k | &kind##_##keytype##_desc); \ | 789 | 506k | } \ |
decode_der2key.c:EC_der2ec_does_selection Line | Count | Source | 786 | 506k | { \ | 787 | 506k | return der2key_check_selection(selection, \ | 788 | 506k | &kind##_##keytype##_desc); \ | 789 | 506k | } \ |
decode_der2key.c:PrivateKeyInfo_der2x25519_does_selection Line | Count | Source | 786 | 506k | { \ | 787 | 506k | return der2key_check_selection(selection, \ | 788 | 506k | &kind##_##keytype##_desc); \ | 789 | 506k | } \ |
decode_der2key.c:SubjectPublicKeyInfo_der2x25519_does_selection Line | Count | Source | 786 | 506k | { \ | 787 | 506k | return der2key_check_selection(selection, \ | 788 | 506k | &kind##_##keytype##_desc); \ | 789 | 506k | } \ |
decode_der2key.c:PrivateKeyInfo_der2x448_does_selection Line | Count | Source | 786 | 506k | { \ | 787 | 506k | return der2key_check_selection(selection, \ | 788 | 506k | &kind##_##keytype##_desc); \ | 789 | 506k | } \ |
decode_der2key.c:SubjectPublicKeyInfo_der2x448_does_selection Line | Count | Source | 786 | 506k | { \ | 787 | 506k | return der2key_check_selection(selection, \ | 788 | 506k | &kind##_##keytype##_desc); \ | 789 | 506k | } \ |
decode_der2key.c:PrivateKeyInfo_der2ed25519_does_selection Line | Count | Source | 786 | 506k | { \ | 787 | 506k | return der2key_check_selection(selection, \ | 788 | 506k | &kind##_##keytype##_desc); \ | 789 | 506k | } \ |
decode_der2key.c:SubjectPublicKeyInfo_der2ed25519_does_selection Line | Count | Source | 786 | 506k | { \ | 787 | 506k | return der2key_check_selection(selection, \ | 788 | 506k | &kind##_##keytype##_desc); \ | 789 | 506k | } \ |
decode_der2key.c:PrivateKeyInfo_der2ed448_does_selection Line | Count | Source | 786 | 506k | { \ | 787 | 506k | return der2key_check_selection(selection, \ | 788 | 506k | &kind##_##keytype##_desc); \ | 789 | 506k | } \ |
decode_der2key.c:SubjectPublicKeyInfo_der2ed448_does_selection Line | Count | Source | 786 | 506k | { \ | 787 | 506k | return der2key_check_selection(selection, \ | 788 | 506k | &kind##_##keytype##_desc); \ | 789 | 506k | } \ |
decode_der2key.c:PrivateKeyInfo_der2sm2_does_selection Line | Count | Source | 786 | 506k | { \ | 787 | 506k | return der2key_check_selection(selection, \ | 788 | 506k | &kind##_##keytype##_desc); \ | 789 | 506k | } \ |
decode_der2key.c:SubjectPublicKeyInfo_der2sm2_does_selection Line | Count | Source | 786 | 506k | { \ | 787 | 506k | return der2key_check_selection(selection, \ | 788 | 506k | &kind##_##keytype##_desc); \ | 789 | 506k | } \ |
decode_der2key.c:type_specific_no_pub_der2sm2_does_selection Line | Count | Source | 786 | 8.04k | { \ | 787 | 8.04k | return der2key_check_selection(selection, \ | 788 | 8.04k | &kind##_##keytype##_desc); \ | 789 | 8.04k | } \ |
decode_der2key.c:PrivateKeyInfo_der2rsa_does_selection Line | Count | Source | 786 | 506k | { \ | 787 | 506k | return der2key_check_selection(selection, \ | 788 | 506k | &kind##_##keytype##_desc); \ | 789 | 506k | } \ |
decode_der2key.c:SubjectPublicKeyInfo_der2rsa_does_selection Line | Count | Source | 786 | 506k | { \ | 787 | 506k | return der2key_check_selection(selection, \ | 788 | 506k | &kind##_##keytype##_desc); \ | 789 | 506k | } \ |
decode_der2key.c:type_specific_keypair_der2rsa_does_selection Line | Count | Source | 786 | 506k | { \ | 787 | 506k | return der2key_check_selection(selection, \ | 788 | 506k | &kind##_##keytype##_desc); \ | 789 | 506k | } \ |
decode_der2key.c:RSA_der2rsa_does_selection Line | Count | Source | 786 | 506k | { \ | 787 | 506k | return der2key_check_selection(selection, \ | 788 | 506k | &kind##_##keytype##_desc); \ | 789 | 506k | } \ |
decode_der2key.c:PrivateKeyInfo_der2rsapss_does_selection Line | Count | Source | 786 | 506k | { \ | 787 | 506k | return der2key_check_selection(selection, \ | 788 | 506k | &kind##_##keytype##_desc); \ | 789 | 506k | } \ |
decode_der2key.c:SubjectPublicKeyInfo_der2rsapss_does_selection Line | Count | Source | 786 | 506k | { \ | 787 | 506k | return der2key_check_selection(selection, \ | 788 | 506k | &kind##_##keytype##_desc); \ | 789 | 506k | } \ |
|
790 | | const OSSL_DISPATCH \ |
791 | | ossl_##kind##_der_to_##keytype##_decoder_functions[] = { \ |
792 | | { OSSL_FUNC_DECODER_NEWCTX, \ |
793 | | (void (*)(void))kind##_der2##keytype##_newctx }, \ |
794 | | { OSSL_FUNC_DECODER_FREECTX, \ |
795 | | (void (*)(void))der2key_freectx }, \ |
796 | | { OSSL_FUNC_DECODER_DOES_SELECTION, \ |
797 | | (void (*)(void))kind##_der2##keytype##_does_selection }, \ |
798 | | { OSSL_FUNC_DECODER_DECODE, \ |
799 | | (void (*)(void))der2key_decode }, \ |
800 | | { OSSL_FUNC_DECODER_EXPORT_OBJECT, \ |
801 | | (void (*)(void))der2key_export_object }, \ |
802 | | { OSSL_FUNC_DECODER_SETTABLE_CTX_PARAMS, \ |
803 | | (void (*)(void))der2key_settable_ctx_params }, \ |
804 | | { OSSL_FUNC_DECODER_SET_CTX_PARAMS, \ |
805 | | (void (*)(void))der2key_set_ctx_params }, \ |
806 | | OSSL_DISPATCH_END \ |
807 | | } |
808 | | |
809 | | #ifndef OPENSSL_NO_DH |
810 | | MAKE_DECODER("DH", dh, dh, PrivateKeyInfo); |
811 | | MAKE_DECODER("DH", dh, dh, SubjectPublicKeyInfo); |
812 | | MAKE_DECODER("DH", dh, dh, type_specific_params); |
813 | | MAKE_DECODER("DH", dh, dh, DH); |
814 | | MAKE_DECODER("DHX", dhx, dhx, PrivateKeyInfo); |
815 | | MAKE_DECODER("DHX", dhx, dhx, SubjectPublicKeyInfo); |
816 | | MAKE_DECODER("DHX", dhx, dhx, type_specific_params); |
817 | | MAKE_DECODER("DHX", dhx, dhx, DHX); |
818 | | #endif |
819 | | #ifndef OPENSSL_NO_DSA |
820 | | MAKE_DECODER("DSA", dsa, dsa, PrivateKeyInfo); |
821 | | MAKE_DECODER("DSA", dsa, dsa, SubjectPublicKeyInfo); |
822 | | MAKE_DECODER("DSA", dsa, dsa, type_specific); |
823 | | MAKE_DECODER("DSA", dsa, dsa, DSA); |
824 | | #endif |
825 | | #ifndef OPENSSL_NO_EC |
826 | | MAKE_DECODER("EC", ec, ec, PrivateKeyInfo); |
827 | | MAKE_DECODER("EC", ec, ec, SubjectPublicKeyInfo); |
828 | | MAKE_DECODER("EC", ec, ec, type_specific_no_pub); |
829 | | MAKE_DECODER("EC", ec, ec, EC); |
830 | | # ifndef OPENSSL_NO_ECX |
831 | | MAKE_DECODER("X25519", x25519, ecx, PrivateKeyInfo); |
832 | | MAKE_DECODER("X25519", x25519, ecx, SubjectPublicKeyInfo); |
833 | | MAKE_DECODER("X448", x448, ecx, PrivateKeyInfo); |
834 | | MAKE_DECODER("X448", x448, ecx, SubjectPublicKeyInfo); |
835 | | MAKE_DECODER("ED25519", ed25519, ecx, PrivateKeyInfo); |
836 | | MAKE_DECODER("ED25519", ed25519, ecx, SubjectPublicKeyInfo); |
837 | | MAKE_DECODER("ED448", ed448, ecx, PrivateKeyInfo); |
838 | | MAKE_DECODER("ED448", ed448, ecx, SubjectPublicKeyInfo); |
839 | | # endif |
840 | | # ifndef OPENSSL_NO_SM2 |
841 | | MAKE_DECODER("SM2", sm2, ec, PrivateKeyInfo); |
842 | | MAKE_DECODER("SM2", sm2, ec, SubjectPublicKeyInfo); |
843 | | MAKE_DECODER("SM2", sm2, sm2, type_specific_no_pub); |
844 | | # endif |
845 | | #endif |
846 | | MAKE_DECODER("RSA", rsa, rsa, PrivateKeyInfo); |
847 | | MAKE_DECODER("RSA", rsa, rsa, SubjectPublicKeyInfo); |
848 | | MAKE_DECODER("RSA", rsa, rsa, type_specific_keypair); |
849 | | MAKE_DECODER("RSA", rsa, rsa, RSA); |
850 | | MAKE_DECODER("RSA-PSS", rsapss, rsapss, PrivateKeyInfo); |
851 | | MAKE_DECODER("RSA-PSS", rsapss, rsapss, SubjectPublicKeyInfo); |