Coverage Report

Created: 2023-09-25 06:45

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