Coverage Report

Created: 2026-02-14 07:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl34/providers/implementations/encode_decode/decode_der2key.c
Line
Count
Source
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
1.05M
{
107
1.05M
    PKCS8_PRIV_KEY_INFO *p8inf = NULL;
108
1.05M
    const X509_ALGOR *alg = NULL;
109
1.05M
    void *key = NULL;
110
111
1.05M
    if ((p8inf = d2i_PKCS8_PRIV_KEY_INFO(NULL, input_der, input_der_len)) != NULL
112
126k
        && PKCS8_pkey_get0(NULL, NULL, NULL, &alg, p8inf)
113
126k
        && (OBJ_obj2nid(alg->algorithm) == ctx->desc->evp_type
114
            /* Allow decoding sm2 private key with id_ecPublicKey */
115
100k
            || (OBJ_obj2nid(alg->algorithm) == NID_X9_62_id_ecPublicKey
116
2.11k
                && ctx->desc->evp_type == NID_sm2)))
117
27.3k
        key = key_from_pkcs8(p8inf, PROV_LIBCTX_OF(ctx->provctx), ctx->propq);
118
1.05M
    PKCS8_PRIV_KEY_INFO_free(p8inf);
119
120
1.05M
    return key;
121
1.05M
}
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
9.96M
{
134
9.96M
    struct der2key_ctx_st *ctx = OPENSSL_zalloc(sizeof(*ctx));
135
136
9.96M
    if (ctx != NULL) {
137
9.96M
        ctx->provctx = provctx;
138
9.96M
        ctx->desc = desc;
139
9.96M
    }
140
9.96M
    return ctx;
141
9.96M
}
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
9.96M
{
167
9.96M
    struct der2key_ctx_st *ctx = vctx;
168
169
9.96M
    OPENSSL_free(ctx);
170
9.96M
}
171
172
static int der2key_check_selection(int selection,
173
    const struct keytype_desc_st *desc)
174
9.29M
{
175
    /*
176
     * The selections are kinda sorta "levels", i.e. each selection given
177
     * here is assumed to include those following.
178
     */
179
9.29M
    int checks[] = {
180
9.29M
        OSSL_KEYMGMT_SELECT_PRIVATE_KEY,
181
9.29M
        OSSL_KEYMGMT_SELECT_PUBLIC_KEY,
182
9.29M
        OSSL_KEYMGMT_SELECT_ALL_PARAMETERS
183
9.29M
    };
184
9.29M
    size_t i;
185
186
    /* The decoder implementations made here support guessing */
187
9.29M
    if (selection == 0)
188
273
        return 1;
189
190
17.0M
    for (i = 0; i < OSSL_NELEM(checks); i++) {
191
17.0M
        int check1 = (selection & checks[i]) != 0;
192
17.0M
        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
17.0M
        if (check1)
199
9.29M
            return check2;
200
17.0M
    }
201
202
    /* This should be dead code, but just to be safe... */
203
0
    return 0;
204
9.29M
}
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
4.84M
{
210
4.84M
    struct der2key_ctx_st *ctx = vctx;
211
4.84M
    unsigned char *der = NULL;
212
4.84M
    const unsigned char *derp;
213
4.84M
    long der_len = 0;
214
4.84M
    void *key = NULL;
215
4.84M
    int ok = 0;
216
217
4.84M
    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
4.84M
    if (selection == 0)
227
1.50M
        selection = ctx->desc->selection_mask;
228
4.84M
    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
4.84M
    ok = ossl_read_der(ctx->provctx, cin, &der, &der_len);
234
4.84M
    if (!ok)
235
697k
        goto next;
236
237
4.14M
    ok = 0; /* Assume that we fail */
238
239
4.14M
    ERR_set_mark();
240
4.14M
    if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0) {
241
2.44M
        derp = der;
242
2.44M
        if (ctx->desc->d2i_PKCS8 != NULL) {
243
1.78M
            key = ctx->desc->d2i_PKCS8(NULL, &derp, der_len, ctx);
244
1.78M
            if (ctx->flag_fatal) {
245
0
                ERR_clear_last_mark();
246
0
                goto end;
247
0
            }
248
1.78M
        } else if (ctx->desc->d2i_private_key != NULL) {
249
661k
            key = ctx->desc->d2i_private_key(NULL, &derp, der_len);
250
661k
        }
251
2.44M
        if (key == NULL && ctx->selection != 0) {
252
1.64M
            ERR_clear_last_mark();
253
1.64M
            goto next;
254
1.64M
        }
255
2.44M
    }
256
2.50M
    if (key == NULL && (selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0) {
257
1.66M
        derp = der;
258
1.66M
        if (ctx->desc->d2i_PUBKEY != NULL)
259
1.59M
            key = ctx->desc->d2i_PUBKEY(NULL, &derp, der_len);
260
67.2k
        else if (ctx->desc->d2i_public_key != NULL)
261
67.2k
            key = ctx->desc->d2i_public_key(NULL, &derp, der_len);
262
1.66M
        if (key == NULL && ctx->selection != 0) {
263
496k
            ERR_clear_last_mark();
264
496k
            goto next;
265
496k
        }
266
1.66M
    }
267
2.00M
    if (key == NULL && (selection & OSSL_KEYMGMT_SELECT_ALL_PARAMETERS) != 0) {
268
177k
        derp = der;
269
177k
        if (ctx->desc->d2i_key_params != NULL)
270
177k
            key = ctx->desc->d2i_key_params(NULL, &derp, der_len);
271
177k
        if (key == NULL && ctx->selection != 0) {
272
0
            ERR_clear_last_mark();
273
0
            goto next;
274
0
        }
275
177k
    }
276
2.00M
    if (key == NULL)
277
1.27M
        ERR_clear_last_mark();
278
725k
    else
279
725k
        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
2.00M
    if (key != NULL
289
725k
        && ctx->desc->check_key != NULL
290
546k
        && !ctx->desc->check_key(key, ctx)) {
291
11.1k
        ctx->desc->free_key(key);
292
11.1k
        key = NULL;
293
11.1k
    }
294
295
2.00M
    if (key != NULL && ctx->desc->adjust_key != NULL)
296
714k
        ctx->desc->adjust_key(key, ctx);
297
298
4.84M
next:
299
    /*
300
     * Indicated that we successfully decoded something, or not at all.
301
     * Ending up "empty handed" is not an error.
302
     */
303
4.84M
    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
4.84M
    OPENSSL_free(der);
311
4.84M
    der = NULL;
312
313
4.84M
    if (key != NULL) {
314
714k
        OSSL_PARAM params[4];
315
714k
        int object_type = OSSL_OBJECT_PKEY;
316
317
714k
        params[0] = OSSL_PARAM_construct_int(OSSL_OBJECT_PARAM_TYPE, &object_type);
318
319
714k
#ifndef OPENSSL_NO_SM2
320
714k
        if (strcmp(ctx->desc->keytype_name, "EC") == 0
321
383k
            && (EC_KEY_get_flags(key) & EC_FLAG_SM2_RANGE) != 0)
322
9
            params[1] = OSSL_PARAM_construct_utf8_string(OSSL_OBJECT_PARAM_DATA_TYPE,
323
9
                "SM2", 0);
324
714k
        else
325
714k
#endif
326
714k
            params[1] = OSSL_PARAM_construct_utf8_string(OSSL_OBJECT_PARAM_DATA_TYPE,
327
714k
                (char *)ctx->desc->keytype_name,
328
714k
                0);
329
        /* The address of the key becomes the octet string */
330
714k
        params[2] = OSSL_PARAM_construct_octet_string(OSSL_OBJECT_PARAM_REFERENCE,
331
714k
            &key, sizeof(key));
332
714k
        params[3] = OSSL_PARAM_construct_end();
333
334
714k
        ok = data_cb(params, data_cbarg);
335
714k
    }
336
337
4.84M
end:
338
4.84M
    ctx->desc->free_key(key);
339
4.84M
    OPENSSL_free(der);
340
341
4.84M
    return ok;
342
4.84M
}
343
344
static int der2key_export_object(void *vctx,
345
    const void *reference, size_t reference_sz,
346
    OSSL_CALLBACK *export_cb, void *export_cbarg)
347
0
{
348
0
    struct der2key_ctx_st *ctx = vctx;
349
0
    OSSL_FUNC_keymgmt_export_fn *export = ossl_prov_get_keymgmt_export(ctx->desc->fns);
350
0
    void *keydata;
351
352
0
    if (reference_sz == sizeof(keydata) && export != NULL) {
353
0
        int selection = ctx->selection;
354
355
0
        if (selection == 0)
356
0
            selection = OSSL_KEYMGMT_SELECT_ALL;
357
        /* The contents of the reference is the address to our object */
358
0
        keydata = *(void **)reference;
359
360
0
        return export(keydata, selection, export_cb, export_cbarg);
361
0
    }
362
0
    return 0;
363
0
}
364
365
/* ---------------------------------------------------------------------- */
366
367
#ifndef OPENSSL_NO_DH
368
#define dh_evp_type EVP_PKEY_DH
369
#define dh_d2i_private_key NULL
370
#define dh_d2i_public_key NULL
371
#define dh_d2i_key_params (d2i_of_void *)d2i_DHparams
372
373
static void *dh_d2i_PKCS8(void **key, const unsigned char **der, long der_len,
374
    struct der2key_ctx_st *ctx)
375
180k
{
376
180k
    return der2key_decode_p8(der, der_len, ctx,
377
180k
        (key_from_pkcs8_t *)ossl_dh_key_from_pkcs8);
378
180k
}
379
380
#define dh_d2i_PUBKEY (d2i_of_void *)ossl_d2i_DH_PUBKEY
381
#define dh_free (free_key_fn *)DH_free
382
#define dh_check NULL
383
384
static void dh_adjust(void *key, struct der2key_ctx_st *ctx)
385
50.8k
{
386
50.8k
    ossl_dh_set0_libctx(key, PROV_LIBCTX_OF(ctx->provctx));
387
50.8k
}
388
389
#define dhx_evp_type EVP_PKEY_DHX
390
#define dhx_d2i_private_key NULL
391
#define dhx_d2i_public_key NULL
392
#define dhx_d2i_key_params (d2i_of_void *)d2i_DHxparams
393
#define dhx_d2i_PKCS8 dh_d2i_PKCS8
394
#define dhx_d2i_PUBKEY (d2i_of_void *)ossl_d2i_DHx_PUBKEY
395
#define dhx_free (free_key_fn *)DH_free
396
#define dhx_check NULL
397
#define dhx_adjust dh_adjust
398
#endif
399
400
/* ---------------------------------------------------------------------- */
401
402
#ifndef OPENSSL_NO_DSA
403
#define dsa_evp_type EVP_PKEY_DSA
404
#define dsa_d2i_private_key (d2i_of_void *)d2i_DSAPrivateKey
405
#define dsa_d2i_public_key (d2i_of_void *)d2i_DSAPublicKey
406
#define dsa_d2i_key_params (d2i_of_void *)d2i_DSAparams
407
408
static void *dsa_d2i_PKCS8(void **key, const unsigned char **der, long der_len,
409
    struct der2key_ctx_st *ctx)
410
89.4k
{
411
89.4k
    return der2key_decode_p8(der, der_len, ctx,
412
89.4k
        (key_from_pkcs8_t *)ossl_dsa_key_from_pkcs8);
413
89.4k
}
414
415
#define dsa_d2i_PUBKEY (d2i_of_void *)ossl_d2i_DSA_PUBKEY
416
#define dsa_free (free_key_fn *)DSA_free
417
#define dsa_check NULL
418
419
static void dsa_adjust(void *key, struct der2key_ctx_st *ctx)
420
125k
{
421
125k
    ossl_dsa_set0_libctx(key, PROV_LIBCTX_OF(ctx->provctx));
422
125k
}
423
#endif
424
425
/* ---------------------------------------------------------------------- */
426
427
#ifndef OPENSSL_NO_EC
428
#define ec_evp_type EVP_PKEY_EC
429
#define ec_d2i_private_key (d2i_of_void *)d2i_ECPrivateKey
430
#define ec_d2i_public_key NULL
431
#define ec_d2i_key_params (d2i_of_void *)d2i_ECParameters
432
433
static void *ec_d2i_PKCS8(void **key, const unsigned char **der, long der_len,
434
    struct der2key_ctx_st *ctx)
435
88.4k
{
436
88.4k
    return der2key_decode_p8(der, der_len, ctx,
437
88.4k
        (key_from_pkcs8_t *)ossl_ec_key_from_pkcs8);
438
88.4k
}
439
440
#define ec_d2i_PUBKEY (d2i_of_void *)d2i_EC_PUBKEY
441
#define ec_free (free_key_fn *)EC_KEY_free
442
443
static int ec_check(void *key, struct der2key_ctx_st *ctx)
444
395k
{
445
    /* We're trying to be clever by comparing two truths */
446
395k
    int ret = 0;
447
395k
    int sm2 = (EC_KEY_get_flags(key) & EC_FLAG_SM2_RANGE) != 0;
448
449
395k
    if (sm2)
450
3.47k
        ret = ctx->desc->evp_type == EVP_PKEY_SM2
451
9
            || ctx->desc->evp_type == NID_X9_62_id_ecPublicKey;
452
392k
    else
453
392k
        ret = ctx->desc->evp_type != EVP_PKEY_SM2;
454
455
395k
    return ret;
456
395k
}
457
458
static void ec_adjust(void *key, struct der2key_ctx_st *ctx)
459
386k
{
460
386k
    ossl_ec_key_set0_libctx(key, PROV_LIBCTX_OF(ctx->provctx));
461
386k
}
462
463
#ifndef OPENSSL_NO_ECX
464
/*
465
 * ED25519, ED448, X25519, X448 only implement PKCS#8 and SubjectPublicKeyInfo,
466
 * so no d2i functions to be had.
467
 */
468
469
static void *ecx_d2i_PKCS8(void **key, const unsigned char **der, long der_len,
470
    struct der2key_ctx_st *ctx)
471
409k
{
472
409k
    return der2key_decode_p8(der, der_len, ctx,
473
409k
        (key_from_pkcs8_t *)ossl_ecx_key_from_pkcs8);
474
409k
}
475
476
static void ecx_key_adjust(void *key, struct der2key_ctx_st *ctx)
477
2.97k
{
478
2.97k
    ossl_ecx_key_set0_libctx(key, PROV_LIBCTX_OF(ctx->provctx));
479
2.97k
}
480
481
#define ed25519_evp_type EVP_PKEY_ED25519
482
#define ed25519_d2i_private_key NULL
483
#define ed25519_d2i_public_key NULL
484
#define ed25519_d2i_key_params NULL
485
#define ed25519_d2i_PKCS8 ecx_d2i_PKCS8
486
#define ed25519_d2i_PUBKEY (d2i_of_void *)ossl_d2i_ED25519_PUBKEY
487
#define ed25519_free (free_key_fn *)ossl_ecx_key_free
488
#define ed25519_check NULL
489
#define ed25519_adjust ecx_key_adjust
490
491
#define ed448_evp_type EVP_PKEY_ED448
492
#define ed448_d2i_private_key NULL
493
#define ed448_d2i_public_key NULL
494
#define ed448_d2i_key_params NULL
495
#define ed448_d2i_PKCS8 ecx_d2i_PKCS8
496
#define ed448_d2i_PUBKEY (d2i_of_void *)ossl_d2i_ED448_PUBKEY
497
#define ed448_free (free_key_fn *)ossl_ecx_key_free
498
#define ed448_check NULL
499
#define ed448_adjust ecx_key_adjust
500
501
#define x25519_evp_type EVP_PKEY_X25519
502
#define x25519_d2i_private_key NULL
503
#define x25519_d2i_public_key NULL
504
#define x25519_d2i_key_params NULL
505
#define x25519_d2i_PKCS8 ecx_d2i_PKCS8
506
#define x25519_d2i_PUBKEY (d2i_of_void *)ossl_d2i_X25519_PUBKEY
507
#define x25519_free (free_key_fn *)ossl_ecx_key_free
508
#define x25519_check NULL
509
#define x25519_adjust ecx_key_adjust
510
511
#define x448_evp_type EVP_PKEY_X448
512
#define x448_d2i_private_key NULL
513
#define x448_d2i_public_key NULL
514
#define x448_d2i_key_params NULL
515
#define x448_d2i_PKCS8 ecx_d2i_PKCS8
516
#define x448_d2i_PUBKEY (d2i_of_void *)ossl_d2i_X448_PUBKEY
517
#define x448_free (free_key_fn *)ossl_ecx_key_free
518
#define x448_check NULL
519
#define x448_adjust ecx_key_adjust
520
#endif /* OPENSSL_NO_ECX */
521
522
#ifndef OPENSSL_NO_SM2
523
#define sm2_evp_type EVP_PKEY_SM2
524
#define sm2_d2i_private_key (d2i_of_void *)d2i_ECPrivateKey
525
#define sm2_d2i_public_key NULL
526
#define sm2_d2i_key_params (d2i_of_void *)d2i_ECParameters
527
528
static void *sm2_d2i_PKCS8(void **key, const unsigned char **der, long der_len,
529
    struct der2key_ctx_st *ctx)
530
103k
{
531
103k
    return der2key_decode_p8(der, der_len, ctx,
532
103k
        (key_from_pkcs8_t *)ossl_ec_key_from_pkcs8);
533
103k
}
534
535
#define sm2_d2i_PUBKEY (d2i_of_void *)d2i_EC_PUBKEY
536
#define sm2_free (free_key_fn *)EC_KEY_free
537
#define sm2_check ec_check
538
#define sm2_adjust ec_adjust
539
#endif
540
#endif
541
542
/* ---------------------------------------------------------------------- */
543
544
#define rsa_evp_type EVP_PKEY_RSA
545
#define rsa_d2i_private_key (d2i_of_void *)d2i_RSAPrivateKey
546
#define rsa_d2i_public_key (d2i_of_void *)d2i_RSAPublicKey
547
#define rsa_d2i_key_params NULL
548
549
static void *rsa_d2i_PKCS8(void **key, const unsigned char **der, long der_len,
550
    struct der2key_ctx_st *ctx)
551
184k
{
552
184k
    return der2key_decode_p8(der, der_len, ctx,
553
184k
        (key_from_pkcs8_t *)ossl_rsa_key_from_pkcs8);
554
184k
}
555
556
#define rsa_d2i_PUBKEY (d2i_of_void *)d2i_RSA_PUBKEY
557
#define rsa_free (free_key_fn *)RSA_free
558
559
static int rsa_check(void *key, struct der2key_ctx_st *ctx)
560
100k
{
561
100k
    int valid;
562
563
100k
    switch (RSA_test_flags(key, RSA_FLAG_TYPE_MASK)) {
564
92.9k
    case RSA_FLAG_TYPE_RSA:
565
92.9k
        valid = (ctx->desc->evp_type == EVP_PKEY_RSA);
566
92.9k
        break;
567
7.33k
    case RSA_FLAG_TYPE_RSASSAPSS:
568
7.33k
        valid = (ctx->desc->evp_type == EVP_PKEY_RSA_PSS);
569
7.33k
        break;
570
0
    default:
571
        /* Currently unsupported RSA key type */
572
0
        valid = 0;
573
100k
    }
574
575
100k
    valid = (valid && ossl_rsa_check_factors(key));
576
577
100k
    return valid;
578
100k
}
579
580
static void rsa_adjust(void *key, struct der2key_ctx_st *ctx)
581
148k
{
582
148k
    ossl_rsa_set0_libctx(key, PROV_LIBCTX_OF(ctx->provctx));
583
148k
}
584
585
#define rsapss_evp_type EVP_PKEY_RSA_PSS
586
#define rsapss_d2i_private_key (d2i_of_void *)d2i_RSAPrivateKey
587
#define rsapss_d2i_public_key (d2i_of_void *)d2i_RSAPublicKey
588
#define rsapss_d2i_key_params NULL
589
#define rsapss_d2i_PKCS8 rsa_d2i_PKCS8
590
#define rsapss_d2i_PUBKEY (d2i_of_void *)d2i_RSA_PUBKEY
591
#define rsapss_free (free_key_fn *)RSA_free
592
#define rsapss_check rsa_check
593
#define rsapss_adjust rsa_adjust
594
595
/* ---------------------------------------------------------------------- */
596
597
/*
598
 * The DO_ macros help define the selection mask and the method functions
599
 * for each kind of object we want to decode.
600
 */
601
#define DO_type_specific_keypair(keytype) \
602
    "type-specific", keytype##_evp_type,  \
603
        (OSSL_KEYMGMT_SELECT_KEYPAIR),    \
604
        keytype##_d2i_private_key,        \
605
        keytype##_d2i_public_key,         \
606
        NULL,                             \
607
        NULL,                             \
608
        NULL,                             \
609
        keytype##_check,                  \
610
        keytype##_adjust,                 \
611
        keytype##_free
612
613
#define DO_type_specific_pub(keytype)     \
614
    "type-specific", keytype##_evp_type,  \
615
        (OSSL_KEYMGMT_SELECT_PUBLIC_KEY), \
616
        NULL,                             \
617
        keytype##_d2i_public_key,         \
618
        NULL,                             \
619
        NULL,                             \
620
        NULL,                             \
621
        keytype##_check,                  \
622
        keytype##_adjust,                 \
623
        keytype##_free
624
625
#define DO_type_specific_priv(keytype)     \
626
    "type-specific", keytype##_evp_type,   \
627
        (OSSL_KEYMGMT_SELECT_PRIVATE_KEY), \
628
        keytype##_d2i_private_key,         \
629
        NULL,                              \
630
        NULL,                              \
631
        NULL,                              \
632
        NULL,                              \
633
        keytype##_check,                   \
634
        keytype##_adjust,                  \
635
        keytype##_free
636
637
#define DO_type_specific_params(keytype)      \
638
    "type-specific", keytype##_evp_type,      \
639
        (OSSL_KEYMGMT_SELECT_ALL_PARAMETERS), \
640
        NULL,                                 \
641
        NULL,                                 \
642
        keytype##_d2i_key_params,             \
643
        NULL,                                 \
644
        NULL,                                 \
645
        keytype##_check,                      \
646
        keytype##_adjust,                     \
647
        keytype##_free
648
649
#define DO_type_specific(keytype)        \
650
    "type-specific", keytype##_evp_type, \
651
        (OSSL_KEYMGMT_SELECT_ALL),       \
652
        keytype##_d2i_private_key,       \
653
        keytype##_d2i_public_key,        \
654
        keytype##_d2i_key_params,        \
655
        NULL,                            \
656
        NULL,                            \
657
        keytype##_check,                 \
658
        keytype##_adjust,                \
659
        keytype##_free
660
661
#define DO_type_specific_no_pub(keytype)           \
662
    "type-specific", keytype##_evp_type,           \
663
        (OSSL_KEYMGMT_SELECT_PRIVATE_KEY           \
664
            | OSSL_KEYMGMT_SELECT_ALL_PARAMETERS), \
665
        keytype##_d2i_private_key,                 \
666
        NULL,                                      \
667
        keytype##_d2i_key_params,                  \
668
        NULL,                                      \
669
        NULL,                                      \
670
        keytype##_check,                           \
671
        keytype##_adjust,                          \
672
        keytype##_free
673
674
#define DO_PrivateKeyInfo(keytype)         \
675
    "PrivateKeyInfo", keytype##_evp_type,  \
676
        (OSSL_KEYMGMT_SELECT_PRIVATE_KEY), \
677
        NULL,                              \
678
        NULL,                              \
679
        NULL,                              \
680
        keytype##_d2i_PKCS8,               \
681
        NULL,                              \
682
        keytype##_check,                   \
683
        keytype##_adjust,                  \
684
        keytype##_free
685
686
#define DO_SubjectPublicKeyInfo(keytype)        \
687
    "SubjectPublicKeyInfo", keytype##_evp_type, \
688
        (OSSL_KEYMGMT_SELECT_PUBLIC_KEY),       \
689
        NULL,                                   \
690
        NULL,                                   \
691
        NULL,                                   \
692
        NULL,                                   \
693
        keytype##_d2i_PUBKEY,                   \
694
        keytype##_check,                        \
695
        keytype##_adjust,                       \
696
        keytype##_free
697
698
#define DO_DH(keytype)                        \
699
    "DH", keytype##_evp_type,                 \
700
        (OSSL_KEYMGMT_SELECT_ALL_PARAMETERS), \
701
        NULL,                                 \
702
        NULL,                                 \
703
        keytype##_d2i_key_params,             \
704
        NULL,                                 \
705
        NULL,                                 \
706
        keytype##_check,                      \
707
        keytype##_adjust,                     \
708
        keytype##_free
709
710
#define DO_DHX(keytype)                       \
711
    "DHX", keytype##_evp_type,                \
712
        (OSSL_KEYMGMT_SELECT_ALL_PARAMETERS), \
713
        NULL,                                 \
714
        NULL,                                 \
715
        keytype##_d2i_key_params,             \
716
        NULL,                                 \
717
        NULL,                                 \
718
        keytype##_check,                      \
719
        keytype##_adjust,                     \
720
        keytype##_free
721
722
#define DO_DSA(keytype)            \
723
    "DSA", keytype##_evp_type,     \
724
        (OSSL_KEYMGMT_SELECT_ALL), \
725
        keytype##_d2i_private_key, \
726
        keytype##_d2i_public_key,  \
727
        keytype##_d2i_key_params,  \
728
        NULL,                      \
729
        NULL,                      \
730
        keytype##_check,           \
731
        keytype##_adjust,          \
732
        keytype##_free
733
734
#define DO_EC(keytype)                             \
735
    "EC", keytype##_evp_type,                      \
736
        (OSSL_KEYMGMT_SELECT_PRIVATE_KEY           \
737
            | OSSL_KEYMGMT_SELECT_ALL_PARAMETERS), \
738
        keytype##_d2i_private_key,                 \
739
        NULL,                                      \
740
        keytype##_d2i_key_params,                  \
741
        NULL,                                      \
742
        NULL,                                      \
743
        keytype##_check,                           \
744
        keytype##_adjust,                          \
745
        keytype##_free
746
747
#define DO_RSA(keytype)                \
748
    "RSA", keytype##_evp_type,         \
749
        (OSSL_KEYMGMT_SELECT_KEYPAIR), \
750
        keytype##_d2i_private_key,     \
751
        keytype##_d2i_public_key,      \
752
        NULL,                          \
753
        NULL,                          \
754
        NULL,                          \
755
        keytype##_check,               \
756
        keytype##_adjust,              \
757
        keytype##_free
758
759
/*
760
 * MAKE_DECODER is the single driver for creating OSSL_DISPATCH tables.
761
 * It takes the following arguments:
762
 *
763
 * keytype_name The implementation key type as a string.
764
 * keytype      The implementation key type.  This must correspond exactly
765
 *              to our existing keymgmt keytype names...  in other words,
766
 *              there must exist an ossl_##keytype##_keymgmt_functions.
767
 * type         The type name for the set of functions that implement the
768
 *              decoder for the key type.  This isn't necessarily the same
769
 *              as keytype.  For example, the key types ed25519, ed448,
770
 *              x25519 and x448 are all handled by the same functions with
771
 *              the common type name ecx.
772
 * kind         The kind of support to implement.  This translates into
773
 *              the DO_##kind macros above, to populate the keytype_desc_st
774
 *              structure.
775
 */
776
#define MAKE_DECODER(keytype_name, keytype, type, kind)                                                               \
777
    static const struct keytype_desc_st kind##_##keytype##_desc = { keytype_name, ossl_##keytype##_keymgmt_functions, \
778
        DO_##kind(keytype) };                                                                                         \
779
                                                                                                                      \
780
    static OSSL_FUNC_decoder_newctx_fn kind##_der2##keytype##_newctx;                                                 \
781
                                                                                                                      \
782
    static void *kind##_der2##keytype##_newctx(void *provctx)                                                         \
783
7.35M
    {                                                                                                                 \
784
7.35M
        return der2key_newctx(provctx, &kind##_##keytype##_desc);                                                     \
785
7.35M
    }                                                                                                                 \
decode_der2key.c:PrivateKeyInfo_der2dh_newctx
Line
Count
Source
783
252k
    {                                                                                                                 \
784
252k
        return der2key_newctx(provctx, &kind##_##keytype##_desc);                                                     \
785
252k
    }                                                                                                                 \
decode_der2key.c:SubjectPublicKeyInfo_der2dh_newctx
Line
Count
Source
783
50.4k
    {                                                                                                                 \
784
50.4k
        return der2key_newctx(provctx, &kind##_##keytype##_desc);                                                     \
785
50.4k
    }                                                                                                                 \
decode_der2key.c:type_specific_params_der2dh_newctx
Line
Count
Source
783
39.7k
    {                                                                                                                 \
784
39.7k
        return der2key_newctx(provctx, &kind##_##keytype##_desc);                                                     \
785
39.7k
    }                                                                                                                 \
decode_der2key.c:DH_der2dh_newctx
Line
Count
Source
783
39.7k
    {                                                                                                                 \
784
39.7k
        return der2key_newctx(provctx, &kind##_##keytype##_desc);                                                     \
785
39.7k
    }                                                                                                                 \
decode_der2key.c:PrivateKeyInfo_der2dhx_newctx
Line
Count
Source
783
252k
    {                                                                                                                 \
784
252k
        return der2key_newctx(provctx, &kind##_##keytype##_desc);                                                     \
785
252k
    }                                                                                                                 \
decode_der2key.c:SubjectPublicKeyInfo_der2dhx_newctx
Line
Count
Source
783
102k
    {                                                                                                                 \
784
102k
        return der2key_newctx(provctx, &kind##_##keytype##_desc);                                                     \
785
102k
    }                                                                                                                 \
decode_der2key.c:type_specific_params_der2dhx_newctx
Line
Count
Source
783
39.7k
    {                                                                                                                 \
784
39.7k
        return der2key_newctx(provctx, &kind##_##keytype##_desc);                                                     \
785
39.7k
    }                                                                                                                 \
decode_der2key.c:DHX_der2dhx_newctx
Line
Count
Source
783
39.7k
    {                                                                                                                 \
784
39.7k
        return der2key_newctx(provctx, &kind##_##keytype##_desc);                                                     \
785
39.7k
    }                                                                                                                 \
decode_der2key.c:PrivateKeyInfo_der2dsa_newctx
Line
Count
Source
783
255k
    {                                                                                                                 \
784
255k
        return der2key_newctx(provctx, &kind##_##keytype##_desc);                                                     \
785
255k
    }                                                                                                                 \
decode_der2key.c:SubjectPublicKeyInfo_der2dsa_newctx
Line
Count
Source
783
161k
    {                                                                                                                 \
784
161k
        return der2key_newctx(provctx, &kind##_##keytype##_desc);                                                     \
785
161k
    }                                                                                                                 \
decode_der2key.c:type_specific_der2dsa_newctx
Line
Count
Source
783
376k
    {                                                                                                                 \
784
376k
        return der2key_newctx(provctx, &kind##_##keytype##_desc);                                                     \
785
376k
    }                                                                                                                 \
decode_der2key.c:DSA_der2dsa_newctx
Line
Count
Source
783
376k
    {                                                                                                                 \
784
376k
        return der2key_newctx(provctx, &kind##_##keytype##_desc);                                                     \
785
376k
    }                                                                                                                 \
decode_der2key.c:PrivateKeyInfo_der2ec_newctx
Line
Count
Source
783
253k
    {                                                                                                                 \
784
253k
        return der2key_newctx(provctx, &kind##_##keytype##_desc);                                                     \
785
253k
    }                                                                                                                 \
decode_der2key.c:SubjectPublicKeyInfo_der2ec_newctx
Line
Count
Source
783
725k
    {                                                                                                                 \
784
725k
        return der2key_newctx(provctx, &kind##_##keytype##_desc);                                                     \
785
725k
    }                                                                                                                 \
decode_der2key.c:type_specific_no_pub_der2ec_newctx
Line
Count
Source
783
253k
    {                                                                                                                 \
784
253k
        return der2key_newctx(provctx, &kind##_##keytype##_desc);                                                     \
785
253k
    }                                                                                                                 \
decode_der2key.c:EC_der2ec_newctx
Line
Count
Source
783
253k
    {                                                                                                                 \
784
253k
        return der2key_newctx(provctx, &kind##_##keytype##_desc);                                                     \
785
253k
    }                                                                                                                 \
decode_der2key.c:PrivateKeyInfo_der2x25519_newctx
Line
Count
Source
783
252k
    {                                                                                                                 \
784
252k
        return der2key_newctx(provctx, &kind##_##keytype##_desc);                                                     \
785
252k
    }                                                                                                                 \
decode_der2key.c:SubjectPublicKeyInfo_der2x25519_newctx
Line
Count
Source
783
43.1k
    {                                                                                                                 \
784
43.1k
        return der2key_newctx(provctx, &kind##_##keytype##_desc);                                                     \
785
43.1k
    }                                                                                                                 \
decode_der2key.c:PrivateKeyInfo_der2x448_newctx
Line
Count
Source
783
252k
    {                                                                                                                 \
784
252k
        return der2key_newctx(provctx, &kind##_##keytype##_desc);                                                     \
785
252k
    }                                                                                                                 \
decode_der2key.c:SubjectPublicKeyInfo_der2x448_newctx
Line
Count
Source
783
43.2k
    {                                                                                                                 \
784
43.2k
        return der2key_newctx(provctx, &kind##_##keytype##_desc);                                                     \
785
43.2k
    }                                                                                                                 \
decode_der2key.c:PrivateKeyInfo_der2ed25519_newctx
Line
Count
Source
783
252k
    {                                                                                                                 \
784
252k
        return der2key_newctx(provctx, &kind##_##keytype##_desc);                                                     \
785
252k
    }                                                                                                                 \
decode_der2key.c:SubjectPublicKeyInfo_der2ed25519_newctx
Line
Count
Source
783
46.3k
    {                                                                                                                 \
784
46.3k
        return der2key_newctx(provctx, &kind##_##keytype##_desc);                                                     \
785
46.3k
    }                                                                                                                 \
decode_der2key.c:PrivateKeyInfo_der2ed448_newctx
Line
Count
Source
783
252k
    {                                                                                                                 \
784
252k
        return der2key_newctx(provctx, &kind##_##keytype##_desc);                                                     \
785
252k
    }                                                                                                                 \
decode_der2key.c:SubjectPublicKeyInfo_der2ed448_newctx
Line
Count
Source
783
40.8k
    {                                                                                                                 \
784
40.8k
        return der2key_newctx(provctx, &kind##_##keytype##_desc);                                                     \
785
40.8k
    }                                                                                                                 \
decode_der2key.c:PrivateKeyInfo_der2sm2_newctx
Line
Count
Source
783
253k
    {                                                                                                                 \
784
253k
        return der2key_newctx(provctx, &kind##_##keytype##_desc);                                                     \
785
253k
    }                                                                                                                 \
decode_der2key.c:SubjectPublicKeyInfo_der2sm2_newctx
Line
Count
Source
783
725k
    {                                                                                                                 \
784
725k
        return der2key_newctx(provctx, &kind##_##keytype##_desc);                                                     \
785
725k
    }                                                                                                                 \
decode_der2key.c:type_specific_no_pub_der2sm2_newctx
Line
Count
Source
783
253k
    {                                                                                                                 \
784
253k
        return der2key_newctx(provctx, &kind##_##keytype##_desc);                                                     \
785
253k
    }                                                                                                                 \
decode_der2key.c:PrivateKeyInfo_der2rsa_newctx
Line
Count
Source
783
252k
    {                                                                                                                 \
784
252k
        return der2key_newctx(provctx, &kind##_##keytype##_desc);                                                     \
785
252k
    }                                                                                                                 \
decode_der2key.c:SubjectPublicKeyInfo_der2rsa_newctx
Line
Count
Source
783
156k
    {                                                                                                                 \
784
156k
        return der2key_newctx(provctx, &kind##_##keytype##_desc);                                                     \
785
156k
    }                                                                                                                 \
decode_der2key.c:type_specific_keypair_der2rsa_newctx
Line
Count
Source
783
369k
    {                                                                                                                 \
784
369k
        return der2key_newctx(provctx, &kind##_##keytype##_desc);                                                     \
785
369k
    }                                                                                                                 \
decode_der2key.c:RSA_der2rsa_newctx
Line
Count
Source
783
369k
    {                                                                                                                 \
784
369k
        return der2key_newctx(provctx, &kind##_##keytype##_desc);                                                     \
785
369k
    }                                                                                                                 \
decode_der2key.c:PrivateKeyInfo_der2rsapss_newctx
Line
Count
Source
783
252k
    {                                                                                                                 \
784
252k
        return der2key_newctx(provctx, &kind##_##keytype##_desc);                                                     \
785
252k
    }                                                                                                                 \
decode_der2key.c:SubjectPublicKeyInfo_der2rsapss_newctx
Line
Count
Source
783
66.9k
    {                                                                                                                 \
784
66.9k
        return der2key_newctx(provctx, &kind##_##keytype##_desc);                                                     \
785
66.9k
    }                                                                                                                 \
786
    static int kind##_der2##keytype##_does_selection(void *provctx,                                                   \
787
        int selection)                                                                                                \
788
8.87M
    {                                                                                                                 \
789
8.87M
        return der2key_check_selection(selection,                                                                     \
790
8.87M
            &kind##_##keytype##_desc);                                                                                \
791
8.87M
    }                                                                                                                 \
decode_der2key.c:PrivateKeyInfo_der2dh_does_selection
Line
Count
Source
788
269k
    {                                                                                                                 \
789
269k
        return der2key_check_selection(selection,                                                                     \
790
269k
            &kind##_##keytype##_desc);                                                                                \
791
269k
    }                                                                                                                 \
decode_der2key.c:SubjectPublicKeyInfo_der2dh_does_selection
Line
Count
Source
788
269k
    {                                                                                                                 \
789
269k
        return der2key_check_selection(selection,                                                                     \
790
269k
            &kind##_##keytype##_desc);                                                                                \
791
269k
    }                                                                                                                 \
decode_der2key.c:type_specific_params_der2dh_does_selection
Line
Count
Source
788
269k
    {                                                                                                                 \
789
269k
        return der2key_check_selection(selection,                                                                     \
790
269k
            &kind##_##keytype##_desc);                                                                                \
791
269k
    }                                                                                                                 \
decode_der2key.c:DH_der2dh_does_selection
Line
Count
Source
788
269k
    {                                                                                                                 \
789
269k
        return der2key_check_selection(selection,                                                                     \
790
269k
            &kind##_##keytype##_desc);                                                                                \
791
269k
    }                                                                                                                 \
decode_der2key.c:PrivateKeyInfo_der2dhx_does_selection
Line
Count
Source
788
269k
    {                                                                                                                 \
789
269k
        return der2key_check_selection(selection,                                                                     \
790
269k
            &kind##_##keytype##_desc);                                                                                \
791
269k
    }                                                                                                                 \
decode_der2key.c:SubjectPublicKeyInfo_der2dhx_does_selection
Line
Count
Source
788
269k
    {                                                                                                                 \
789
269k
        return der2key_check_selection(selection,                                                                     \
790
269k
            &kind##_##keytype##_desc);                                                                                \
791
269k
    }                                                                                                                 \
decode_der2key.c:type_specific_params_der2dhx_does_selection
Line
Count
Source
788
269k
    {                                                                                                                 \
789
269k
        return der2key_check_selection(selection,                                                                     \
790
269k
            &kind##_##keytype##_desc);                                                                                \
791
269k
    }                                                                                                                 \
decode_der2key.c:DHX_der2dhx_does_selection
Line
Count
Source
788
269k
    {                                                                                                                 \
789
269k
        return der2key_check_selection(selection,                                                                     \
790
269k
            &kind##_##keytype##_desc);                                                                                \
791
269k
    }                                                                                                                 \
decode_der2key.c:PrivateKeyInfo_der2dsa_does_selection
Line
Count
Source
788
269k
    {                                                                                                                 \
789
269k
        return der2key_check_selection(selection,                                                                     \
790
269k
            &kind##_##keytype##_desc);                                                                                \
791
269k
    }                                                                                                                 \
decode_der2key.c:SubjectPublicKeyInfo_der2dsa_does_selection
Line
Count
Source
788
269k
    {                                                                                                                 \
789
269k
        return der2key_check_selection(selection,                                                                     \
790
269k
            &kind##_##keytype##_desc);                                                                                \
791
269k
    }                                                                                                                 \
decode_der2key.c:type_specific_der2dsa_does_selection
Line
Count
Source
788
269k
    {                                                                                                                 \
789
269k
        return der2key_check_selection(selection,                                                                     \
790
269k
            &kind##_##keytype##_desc);                                                                                \
791
269k
    }                                                                                                                 \
decode_der2key.c:DSA_der2dsa_does_selection
Line
Count
Source
788
269k
    {                                                                                                                 \
789
269k
        return der2key_check_selection(selection,                                                                     \
790
269k
            &kind##_##keytype##_desc);                                                                                \
791
269k
    }                                                                                                                 \
decode_der2key.c:PrivateKeyInfo_der2ec_does_selection
Line
Count
Source
788
269k
    {                                                                                                                 \
789
269k
        return der2key_check_selection(selection,                                                                     \
790
269k
            &kind##_##keytype##_desc);                                                                                \
791
269k
    }                                                                                                                 \
decode_der2key.c:SubjectPublicKeyInfo_der2ec_does_selection
Line
Count
Source
788
269k
    {                                                                                                                 \
789
269k
        return der2key_check_selection(selection,                                                                     \
790
269k
            &kind##_##keytype##_desc);                                                                                \
791
269k
    }                                                                                                                 \
decode_der2key.c:type_specific_no_pub_der2ec_does_selection
Line
Count
Source
788
269k
    {                                                                                                                 \
789
269k
        return der2key_check_selection(selection,                                                                     \
790
269k
            &kind##_##keytype##_desc);                                                                                \
791
269k
    }                                                                                                                 \
decode_der2key.c:EC_der2ec_does_selection
Line
Count
Source
788
269k
    {                                                                                                                 \
789
269k
        return der2key_check_selection(selection,                                                                     \
790
269k
            &kind##_##keytype##_desc);                                                                                \
791
269k
    }                                                                                                                 \
decode_der2key.c:PrivateKeyInfo_der2x25519_does_selection
Line
Count
Source
788
269k
    {                                                                                                                 \
789
269k
        return der2key_check_selection(selection,                                                                     \
790
269k
            &kind##_##keytype##_desc);                                                                                \
791
269k
    }                                                                                                                 \
decode_der2key.c:SubjectPublicKeyInfo_der2x25519_does_selection
Line
Count
Source
788
269k
    {                                                                                                                 \
789
269k
        return der2key_check_selection(selection,                                                                     \
790
269k
            &kind##_##keytype##_desc);                                                                                \
791
269k
    }                                                                                                                 \
decode_der2key.c:PrivateKeyInfo_der2x448_does_selection
Line
Count
Source
788
269k
    {                                                                                                                 \
789
269k
        return der2key_check_selection(selection,                                                                     \
790
269k
            &kind##_##keytype##_desc);                                                                                \
791
269k
    }                                                                                                                 \
decode_der2key.c:SubjectPublicKeyInfo_der2x448_does_selection
Line
Count
Source
788
269k
    {                                                                                                                 \
789
269k
        return der2key_check_selection(selection,                                                                     \
790
269k
            &kind##_##keytype##_desc);                                                                                \
791
269k
    }                                                                                                                 \
decode_der2key.c:PrivateKeyInfo_der2ed25519_does_selection
Line
Count
Source
788
269k
    {                                                                                                                 \
789
269k
        return der2key_check_selection(selection,                                                                     \
790
269k
            &kind##_##keytype##_desc);                                                                                \
791
269k
    }                                                                                                                 \
decode_der2key.c:SubjectPublicKeyInfo_der2ed25519_does_selection
Line
Count
Source
788
269k
    {                                                                                                                 \
789
269k
        return der2key_check_selection(selection,                                                                     \
790
269k
            &kind##_##keytype##_desc);                                                                                \
791
269k
    }                                                                                                                 \
decode_der2key.c:PrivateKeyInfo_der2ed448_does_selection
Line
Count
Source
788
269k
    {                                                                                                                 \
789
269k
        return der2key_check_selection(selection,                                                                     \
790
269k
            &kind##_##keytype##_desc);                                                                                \
791
269k
    }                                                                                                                 \
decode_der2key.c:SubjectPublicKeyInfo_der2ed448_does_selection
Line
Count
Source
788
269k
    {                                                                                                                 \
789
269k
        return der2key_check_selection(selection,                                                                     \
790
269k
            &kind##_##keytype##_desc);                                                                                \
791
269k
    }                                                                                                                 \
decode_der2key.c:PrivateKeyInfo_der2sm2_does_selection
Line
Count
Source
788
269k
    {                                                                                                                 \
789
269k
        return der2key_check_selection(selection,                                                                     \
790
269k
            &kind##_##keytype##_desc);                                                                                \
791
269k
    }                                                                                                                 \
decode_der2key.c:SubjectPublicKeyInfo_der2sm2_does_selection
Line
Count
Source
788
269k
    {                                                                                                                 \
789
269k
        return der2key_check_selection(selection,                                                                     \
790
269k
            &kind##_##keytype##_desc);                                                                                \
791
269k
    }                                                                                                                 \
decode_der2key.c:type_specific_no_pub_der2sm2_does_selection
Line
Count
Source
788
269k
    {                                                                                                                 \
789
269k
        return der2key_check_selection(selection,                                                                     \
790
269k
            &kind##_##keytype##_desc);                                                                                \
791
269k
    }                                                                                                                 \
decode_der2key.c:PrivateKeyInfo_der2rsa_does_selection
Line
Count
Source
788
269k
    {                                                                                                                 \
789
269k
        return der2key_check_selection(selection,                                                                     \
790
269k
            &kind##_##keytype##_desc);                                                                                \
791
269k
    }                                                                                                                 \
decode_der2key.c:SubjectPublicKeyInfo_der2rsa_does_selection
Line
Count
Source
788
269k
    {                                                                                                                 \
789
269k
        return der2key_check_selection(selection,                                                                     \
790
269k
            &kind##_##keytype##_desc);                                                                                \
791
269k
    }                                                                                                                 \
decode_der2key.c:type_specific_keypair_der2rsa_does_selection
Line
Count
Source
788
269k
    {                                                                                                                 \
789
269k
        return der2key_check_selection(selection,                                                                     \
790
269k
            &kind##_##keytype##_desc);                                                                                \
791
269k
    }                                                                                                                 \
decode_der2key.c:RSA_der2rsa_does_selection
Line
Count
Source
788
269k
    {                                                                                                                 \
789
269k
        return der2key_check_selection(selection,                                                                     \
790
269k
            &kind##_##keytype##_desc);                                                                                \
791
269k
    }                                                                                                                 \
decode_der2key.c:PrivateKeyInfo_der2rsapss_does_selection
Line
Count
Source
788
269k
    {                                                                                                                 \
789
269k
        return der2key_check_selection(selection,                                                                     \
790
269k
            &kind##_##keytype##_desc);                                                                                \
791
269k
    }                                                                                                                 \
decode_der2key.c:SubjectPublicKeyInfo_der2rsapss_does_selection
Line
Count
Source
788
269k
    {                                                                                                                 \
789
269k
        return der2key_check_selection(selection,                                                                     \
790
269k
            &kind##_##keytype##_desc);                                                                                \
791
269k
    }                                                                                                                 \
792
    const OSSL_DISPATCH                                                                                               \
793
        ossl_##kind##_der_to_##keytype##_decoder_functions[]                                                          \
794
        = {                                                                                                           \
795
              { OSSL_FUNC_DECODER_NEWCTX,                                                                             \
796
                  (void (*)(void))kind##_der2##keytype##_newctx },                                                    \
797
              { OSSL_FUNC_DECODER_FREECTX,                                                                            \
798
                  (void (*)(void))der2key_freectx },                                                                  \
799
              { OSSL_FUNC_DECODER_DOES_SELECTION,                                                                     \
800
                  (void (*)(void))kind##_der2##keytype##_does_selection },                                            \
801
              { OSSL_FUNC_DECODER_DECODE,                                                                             \
802
                  (void (*)(void))der2key_decode },                                                                   \
803
              { OSSL_FUNC_DECODER_EXPORT_OBJECT,                                                                      \
804
                  (void (*)(void))der2key_export_object },                                                            \
805
              { OSSL_FUNC_DECODER_SETTABLE_CTX_PARAMS,                                                                \
806
                  (void (*)(void))der2key_settable_ctx_params },                                                      \
807
              { OSSL_FUNC_DECODER_SET_CTX_PARAMS,                                                                     \
808
                  (void (*)(void))der2key_set_ctx_params },                                                           \
809
              OSSL_DISPATCH_END                                                                                       \
810
          }
811
812
#ifndef OPENSSL_NO_DH
813
MAKE_DECODER("DH", dh, dh, PrivateKeyInfo);
814
MAKE_DECODER("DH", dh, dh, SubjectPublicKeyInfo);
815
MAKE_DECODER("DH", dh, dh, type_specific_params);
816
MAKE_DECODER("DH", dh, dh, DH);
817
MAKE_DECODER("DHX", dhx, dhx, PrivateKeyInfo);
818
MAKE_DECODER("DHX", dhx, dhx, SubjectPublicKeyInfo);
819
MAKE_DECODER("DHX", dhx, dhx, type_specific_params);
820
MAKE_DECODER("DHX", dhx, dhx, DHX);
821
#endif
822
#ifndef OPENSSL_NO_DSA
823
MAKE_DECODER("DSA", dsa, dsa, PrivateKeyInfo);
824
MAKE_DECODER("DSA", dsa, dsa, SubjectPublicKeyInfo);
825
MAKE_DECODER("DSA", dsa, dsa, type_specific);
826
MAKE_DECODER("DSA", dsa, dsa, DSA);
827
#endif
828
#ifndef OPENSSL_NO_EC
829
MAKE_DECODER("EC", ec, ec, PrivateKeyInfo);
830
MAKE_DECODER("EC", ec, ec, SubjectPublicKeyInfo);
831
MAKE_DECODER("EC", ec, ec, type_specific_no_pub);
832
MAKE_DECODER("EC", ec, ec, EC);
833
#ifndef OPENSSL_NO_ECX
834
MAKE_DECODER("X25519", x25519, ecx, PrivateKeyInfo);
835
MAKE_DECODER("X25519", x25519, ecx, SubjectPublicKeyInfo);
836
MAKE_DECODER("X448", x448, ecx, PrivateKeyInfo);
837
MAKE_DECODER("X448", x448, ecx, SubjectPublicKeyInfo);
838
MAKE_DECODER("ED25519", ed25519, ecx, PrivateKeyInfo);
839
MAKE_DECODER("ED25519", ed25519, ecx, SubjectPublicKeyInfo);
840
MAKE_DECODER("ED448", ed448, ecx, PrivateKeyInfo);
841
MAKE_DECODER("ED448", ed448, ecx, SubjectPublicKeyInfo);
842
#endif
843
#ifndef OPENSSL_NO_SM2
844
MAKE_DECODER("SM2", sm2, ec, PrivateKeyInfo);
845
MAKE_DECODER("SM2", sm2, ec, SubjectPublicKeyInfo);
846
MAKE_DECODER("SM2", sm2, sm2, type_specific_no_pub);
847
#endif
848
#endif
849
MAKE_DECODER("RSA", rsa, rsa, PrivateKeyInfo);
850
MAKE_DECODER("RSA", rsa, rsa, SubjectPublicKeyInfo);
851
MAKE_DECODER("RSA", rsa, rsa, type_specific_keypair);
852
MAKE_DECODER("RSA", rsa, rsa, RSA);
853
MAKE_DECODER("RSA-PSS", rsapss, rsapss, PrivateKeyInfo);
854
MAKE_DECODER("RSA-PSS", rsapss, rsapss, SubjectPublicKeyInfo);