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