Coverage Report

Created: 2025-06-13 06:58

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