Coverage Report

Created: 2026-07-16 06:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl/providers/implementations/encode_decode/decode_der2key.c
Line
Count
Source
1
/*
2
 * Copyright 2020-2026 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/byteorder.h>
17
#include <openssl/core_dispatch.h>
18
#include <openssl/core_names.h>
19
#include <openssl/core_object.h>
20
#include <openssl/crypto.h>
21
#include <openssl/err.h>
22
#include <openssl/params.h>
23
#include <openssl/pem.h> /* PEM_BUFSIZE and public PEM functions */
24
#include <openssl/pkcs12.h>
25
#include <openssl/provider.h>
26
#include <openssl/x509.h>
27
#include <openssl/proverr.h>
28
#include <openssl/asn1t.h>
29
#include "internal/cryptlib.h" /* ossl_assert() */
30
#include "crypto/dh.h"
31
#include "crypto/dsa.h"
32
#include "crypto/ec.h"
33
#include "crypto/evp.h"
34
#include "crypto/ecx.h"
35
#include "crypto/rsa.h"
36
#include "crypto/ml_dsa.h"
37
#include "crypto/slh_dsa.h"
38
#include "crypto/x509.h"
39
#include "crypto/ml_kem.h"
40
#include "openssl/obj_mac.h"
41
#include "prov/bio.h"
42
#include "prov/implementations.h"
43
#include "prov/endecoder_local.h"
44
#include "internal/nelem.h"
45
#include "prov/ml_dsa_codecs.h"
46
#include "prov/ml_kem_codecs.h"
47
#include "prov/lms_codecs.h"
48
#include "providers/implementations/encode_decode/decode_der2key.inc"
49
50
#ifndef OPENSSL_NO_SLH_DSA
51
typedef struct {
52
    ASN1_OBJECT *oid;
53
} BARE_ALGOR;
54
55
typedef struct {
56
    BARE_ALGOR algor;
57
    ASN1_BIT_STRING *pubkey;
58
} BARE_PUBKEY;
59
60
ASN1_SEQUENCE(BARE_ALGOR) = {
61
    ASN1_SIMPLE(BARE_ALGOR, oid, ASN1_OBJECT),
62
0
} static_ASN1_SEQUENCE_END(BARE_ALGOR)
63
0
64
0
ASN1_SEQUENCE(BARE_PUBKEY) = {
65
0
    ASN1_EMBED(BARE_PUBKEY, algor, BARE_ALGOR),
66
0
    ASN1_SIMPLE(BARE_PUBKEY, pubkey, ASN1_BIT_STRING)
67
0
} static_ASN1_SEQUENCE_END(BARE_PUBKEY)
68
0
#endif /* OPENSSL_NO_SLH_DSA */
69
0
70
0
struct der2key_ctx_st; /* Forward declaration */
71
0
typedef int check_key_fn(void *, struct der2key_ctx_st *ctx);
72
0
typedef void adjust_key_fn(void *, struct der2key_ctx_st *ctx);
73
0
typedef void free_key_fn(void *);
74
0
typedef void *d2i_PKCS8_fn(const unsigned char **, long,
75
0
    struct der2key_ctx_st *);
76
0
typedef void *d2i_PUBKEY_fn(const unsigned char **, long,
77
0
    struct der2key_ctx_st *);
78
0
struct keytype_desc_st {
79
0
    const char *keytype_name;
80
0
    const OSSL_DISPATCH *fns; /* Keymgmt (to pilfer functions from) */
81
0
82
0
    /* The input structure name */
83
0
    const char *structure_name;
84
0
85
0
    /*
86
0
     * The EVP_PKEY_xxx type macro.  Should be zero for type specific
87
0
     * structures, non-zero when the outermost structure is PKCS#8 or
88
0
     * SubjectPublicKeyInfo.  This determines which of the function
89
0
     * pointers below will be used.
90
0
     */
91
0
    int evp_type;
92
0
93
0
    /* The selection mask for OSSL_FUNC_decoder_does_selection() */
94
0
    int selection_mask;
95
0
96
0
    /* For type specific decoders, we use the corresponding d2i */
97
0
    d2i_of_void *d2i_private_key; /* From type-specific DER */
98
0
    d2i_of_void *d2i_public_key; /* From type-specific DER */
99
0
    d2i_of_void *d2i_key_params; /* From type-specific DER */
100
0
    d2i_PKCS8_fn *d2i_PKCS8; /* Wrapped in a PrivateKeyInfo */
101
0
    d2i_PUBKEY_fn *d2i_PUBKEY; /* Wrapped in a SubjectPublicKeyInfo */
102
0
103
0
    /*
104
0
     * For any key, we may need to check that the key meets expectations.
105
0
     * This is useful when the same functions can decode several variants
106
0
     * of a key.
107
0
     */
108
0
    check_key_fn *check_key;
109
0
110
0
    /*
111
0
     * For any key, we may need to make provider specific adjustments, such
112
0
     * as ensure the key carries the correct library context.
113
0
     */
114
0
    adjust_key_fn *adjust_key;
115
0
    /* {type}_free() */
116
0
    free_key_fn *free_key;
117
0
};
118
0
119
0
/*
120
0
 * Context used for DER to key decoding.
121
0
 */
122
0
struct der2key_ctx_st {
123
0
    PROV_CTX *provctx;
124
0
    char propq[OSSL_MAX_PROPQUERY_SIZE];
125
0
    const struct keytype_desc_st *desc;
126
0
    /* The selection that is passed to der2key_decode() */
127
0
    int selection;
128
0
    /* Flag used to signal that a failure is fatal */
129
0
    unsigned int flag_fatal : 1;
130
0
};
131
0
132
0
typedef void *key_from_pkcs8_t(const PKCS8_PRIV_KEY_INFO *p8inf,
133
0
    OSSL_LIB_CTX *libctx, const char *propq);
134
0
static void *der2key_decode_p8(const unsigned char **input_der,
135
0
    long input_der_len, struct der2key_ctx_st *ctx,
136
0
    key_from_pkcs8_t *key_from_pkcs8)
137
0
{
138
0
    PKCS8_PRIV_KEY_INFO *p8inf = NULL;
139
0
    const X509_ALGOR *alg = NULL;
140
0
    void *key = NULL;
141
142
0
    if ((p8inf = d2i_PKCS8_PRIV_KEY_INFO(NULL, input_der, input_der_len)) != NULL
143
0
        && PKCS8_pkey_get0(NULL, NULL, NULL, &alg, p8inf)
144
0
        && (OBJ_obj2nid(alg->algorithm) == ctx->desc->evp_type
145
            /* Allow decoding sm2 private key with id_ecPublicKey */
146
0
            || (OBJ_obj2nid(alg->algorithm) == NID_X9_62_id_ecPublicKey
147
0
                && ctx->desc->evp_type == NID_sm2)))
148
0
        key = key_from_pkcs8(p8inf, PROV_LIBCTX_OF(ctx->provctx), ctx->propq);
149
0
    PKCS8_PRIV_KEY_INFO_free(p8inf);
150
151
0
    return key;
152
0
}
153
154
/* ---------------------------------------------------------------------- */
155
156
static OSSL_FUNC_decoder_freectx_fn der2key_freectx;
157
static OSSL_FUNC_decoder_decode_fn der2key_decode;
158
static OSSL_FUNC_decoder_export_object_fn der2key_export_object;
159
static OSSL_FUNC_decoder_settable_ctx_params_fn der2key_settable_ctx_params;
160
static OSSL_FUNC_decoder_set_ctx_params_fn der2key_set_ctx_params;
161
162
static struct der2key_ctx_st *
163
der2key_newctx(void *provctx, const struct keytype_desc_st *desc)
164
0
{
165
0
    struct der2key_ctx_st *ctx = OPENSSL_zalloc(sizeof(*ctx));
166
167
0
    if (ctx != NULL) {
168
0
        ctx->provctx = provctx;
169
0
        ctx->desc = desc;
170
0
    }
171
0
    return ctx;
172
0
}
173
174
static const OSSL_PARAM *der2key_settable_ctx_params(ossl_unused void *provctx)
175
0
{
176
0
    return der2key_set_ctx_params_list;
177
0
}
178
179
static int der2key_set_ctx_params(void *vctx, const OSSL_PARAM params[])
180
0
{
181
0
    struct der2key_ctx_st *ctx = vctx;
182
0
    struct der2key_set_ctx_params_st p;
183
0
    char *str;
184
185
0
    if (ctx == NULL || !der2key_set_ctx_params_decoder(params, &p))
186
0
        return 0;
187
188
0
    str = ctx->propq;
189
0
    if (p.propq != NULL
190
0
        && !OSSL_PARAM_get_utf8_string(p.propq, &str, sizeof(ctx->propq)))
191
0
        return 0;
192
193
0
    return 1;
194
0
}
195
196
static void der2key_freectx(void *vctx)
197
0
{
198
0
    struct der2key_ctx_st *ctx = vctx;
199
200
0
    OPENSSL_free(ctx);
201
0
}
202
203
static int der2key_check_selection(int selection,
204
    const struct keytype_desc_st *desc)
205
0
{
206
    /*
207
     * The selections are kinda sorta "levels", i.e. each selection given
208
     * here is assumed to include those following.
209
     */
210
0
    int checks[] = {
211
0
        OSSL_KEYMGMT_SELECT_PRIVATE_KEY,
212
0
        OSSL_KEYMGMT_SELECT_PUBLIC_KEY,
213
0
        OSSL_KEYMGMT_SELECT_ALL_PARAMETERS
214
0
    };
215
0
    size_t i;
216
217
    /* The decoder implementations made here support guessing */
218
0
    if (selection == 0)
219
0
        return 1;
220
221
0
    for (i = 0; i < OSSL_NELEM(checks); i++) {
222
0
        int check1 = (selection & checks[i]) != 0;
223
0
        int check2 = (desc->selection_mask & checks[i]) != 0;
224
225
        /*
226
         * If the caller asked for the currently checked bit(s), return
227
         * whether the decoder description says it's supported.
228
         */
229
0
        if (check1)
230
0
            return check2;
231
0
    }
232
233
    /* This should be dead code, but just to be safe... */
234
0
    return 0;
235
0
}
236
237
static int der2key_decode(void *vctx, OSSL_CORE_BIO *cin, int selection,
238
    OSSL_CALLBACK *data_cb, void *data_cbarg,
239
    OSSL_PASSPHRASE_CALLBACK *pw_cb, void *pw_cbarg)
240
0
{
241
0
    struct der2key_ctx_st *ctx = vctx;
242
0
    unsigned char *der = NULL;
243
0
    const unsigned char *derp;
244
0
    long der_len = 0;
245
0
    void *key = NULL;
246
0
    int ok = 0;
247
248
0
    ctx->selection = selection;
249
    /*
250
     * The caller is allowed to specify 0 as a selection mask, to have the
251
     * structure and key type guessed.  For type-specific structures, this
252
     * is not recommended, as some structures are very similar.
253
     * Note that 0 isn't the same as OSSL_KEYMGMT_SELECT_ALL, as the latter
254
     * signifies a private key structure, where everything else is assumed
255
     * to be present as well.
256
     */
257
0
    if (selection == 0)
258
0
        selection = ctx->desc->selection_mask;
259
0
    if ((selection & ctx->desc->selection_mask) == 0) {
260
0
        ERR_raise(ERR_LIB_PROV, ERR_R_PASSED_INVALID_ARGUMENT);
261
0
        return 0;
262
0
    }
263
264
0
    ok = ossl_read_der(ctx->provctx, cin, &der, &der_len);
265
0
    if (!ok)
266
0
        goto next;
267
268
0
    ok = 0; /* Assume that we fail */
269
270
0
    ERR_set_mark();
271
0
    if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0) {
272
0
        derp = der;
273
0
        if (ctx->desc->d2i_PKCS8 != NULL) {
274
0
            key = ctx->desc->d2i_PKCS8(&derp, der_len, ctx);
275
0
            if (ctx->flag_fatal) {
276
0
                ERR_clear_last_mark();
277
0
                goto end;
278
0
            }
279
0
        } else if (ctx->desc->d2i_private_key != NULL) {
280
0
            key = ctx->desc->d2i_private_key(NULL, &derp, der_len);
281
0
        }
282
0
        if (key == NULL && ctx->selection != 0) {
283
0
            ERR_clear_last_mark();
284
0
            goto next;
285
0
        }
286
0
    }
287
0
    if (key == NULL && (selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0) {
288
0
        derp = der;
289
0
        if (ctx->desc->d2i_PUBKEY != NULL)
290
0
            key = ctx->desc->d2i_PUBKEY(&derp, der_len, ctx);
291
0
        else if (ctx->desc->d2i_public_key != NULL)
292
0
            key = ctx->desc->d2i_public_key(NULL, &derp, der_len);
293
0
        if (key == NULL && ctx->selection != 0) {
294
0
            ERR_clear_last_mark();
295
0
            goto next;
296
0
        }
297
0
    }
298
0
    if (key == NULL && (selection & OSSL_KEYMGMT_SELECT_ALL_PARAMETERS) != 0) {
299
0
        derp = der;
300
0
        if (ctx->desc->d2i_key_params != NULL)
301
0
            key = ctx->desc->d2i_key_params(NULL, &derp, der_len);
302
0
        if (key == NULL && ctx->selection != 0) {
303
0
            ERR_clear_last_mark();
304
0
            goto next;
305
0
        }
306
0
    }
307
0
    if (key == NULL)
308
0
        ERR_clear_last_mark();
309
0
    else
310
0
        ERR_pop_to_mark();
311
312
    /*
313
     * Last minute check to see if this was the correct type of key.  This
314
     * should never lead to a fatal error, i.e. the decoding itself was
315
     * correct, it was just an unexpected key type.  This is generally for
316
     * classes of key types that have subtle variants, like RSA-PSS keys as
317
     * opposed to plain RSA keys.
318
     */
319
0
    if (key != NULL
320
0
        && ctx->desc->check_key != NULL
321
0
        && !ctx->desc->check_key(key, ctx)) {
322
0
        ctx->desc->free_key(key);
323
0
        key = NULL;
324
0
    }
325
326
0
    if (key != NULL && ctx->desc->adjust_key != NULL)
327
0
        ctx->desc->adjust_key(key, ctx);
328
329
0
next:
330
    /*
331
     * Indicated that we successfully decoded something, or not at all.
332
     * Ending up "empty handed" is not an error.
333
     */
334
0
    ok = 1;
335
336
    /*
337
     * We free memory here so it's not held up during the callback, because
338
     * we know the process is recursive and the allocated chunks of memory
339
     * add up.
340
     */
341
0
    OPENSSL_free(der);
342
0
    der = NULL;
343
344
0
    if (key != NULL) {
345
0
        OSSL_PARAM params[4];
346
0
        int object_type = OSSL_OBJECT_PKEY;
347
348
0
        params[0] = OSSL_PARAM_construct_int(OSSL_OBJECT_PARAM_TYPE, &object_type);
349
350
0
#ifndef OPENSSL_NO_SM2
351
0
        if (strcmp(ctx->desc->keytype_name, "EC") == 0
352
0
            && (EC_KEY_get_flags(key) & EC_FLAG_SM2_RANGE) != 0)
353
0
            params[1] = OSSL_PARAM_construct_utf8_string(OSSL_OBJECT_PARAM_DATA_TYPE,
354
0
                "SM2", 0);
355
0
        else
356
0
#endif
357
0
            params[1] = OSSL_PARAM_construct_utf8_string(OSSL_OBJECT_PARAM_DATA_TYPE,
358
0
                (char *)ctx->desc->keytype_name,
359
0
                0);
360
        /* The address of the key becomes the octet string */
361
0
        params[2] = OSSL_PARAM_construct_octet_string(OSSL_OBJECT_PARAM_REFERENCE,
362
0
            &key, sizeof(key));
363
0
        params[3] = OSSL_PARAM_construct_end();
364
365
0
        ok = data_cb(params, data_cbarg);
366
0
    }
367
368
0
end:
369
0
    ctx->desc->free_key(key);
370
0
    OPENSSL_free(der);
371
372
0
    return ok;
373
0
}
374
375
static int der2key_export_object(void *vctx,
376
    const void *reference, size_t reference_sz,
377
    OSSL_CALLBACK *export_cb, void *export_cbarg)
378
0
{
379
0
    struct der2key_ctx_st *ctx = vctx;
380
0
    OSSL_FUNC_keymgmt_export_fn *export = ossl_prov_get_keymgmt_export(ctx->desc->fns);
381
0
    void *keydata;
382
383
0
    if (reference_sz == sizeof(keydata) && export != NULL) {
384
0
        int selection = ctx->selection;
385
386
0
        if (selection == 0)
387
0
            selection = OSSL_KEYMGMT_SELECT_ALL;
388
        /* The contents of the reference is the address to our object */
389
0
        keydata = *(void **)reference;
390
391
0
        return export(keydata, selection, export_cb, export_cbarg);
392
0
    }
393
0
    return 0;
394
0
}
395
396
#define D2I_PUBKEY_NOCTX(n, f)                              \
397
    static void *                                           \
398
    n##_d2i_PUBKEY(const unsigned char **der, long der_len, \
399
        ossl_unused struct der2key_ctx_st *ctx)             \
400
0
    {                                                       \
401
0
        return f(NULL, der, der_len);                       \
402
0
    }
403
404
/* ---------------------------------------------------------------------- */
405
406
#ifndef OPENSSL_NO_DH
407
static void dh_free_key(void *key)
408
0
{
409
0
    DH_free(key);
410
0
}
411
412
#define dh_evp_type EVP_PKEY_DH
413
#define dh_d2i_private_key NULL
414
#define dh_d2i_public_key NULL
415
#define dh_d2i_key_params (d2i_of_void *)d2i_DHparams
416
#define dh_free dh_free_key
417
#define dh_check NULL
418
419
static void *dh_d2i_PKCS8(const unsigned char **der, long der_len,
420
    struct der2key_ctx_st *ctx)
421
0
{
422
0
    return der2key_decode_p8(der, der_len, ctx,
423
0
        (key_from_pkcs8_t *)ossl_dh_key_from_pkcs8);
424
0
}
425
426
0
D2I_PUBKEY_NOCTX(dh, ossl_d2i_DH_PUBKEY)
427
0
D2I_PUBKEY_NOCTX(dhx, ossl_d2i_DHx_PUBKEY)
428
429
static void dh_adjust(void *key, struct der2key_ctx_st *ctx)
430
0
{
431
0
    ossl_dh_set0_libctx(key, PROV_LIBCTX_OF(ctx->provctx));
432
0
}
433
434
#define dhx_evp_type EVP_PKEY_DHX
435
#define dhx_d2i_private_key NULL
436
#define dhx_d2i_public_key NULL
437
#define dhx_d2i_key_params (d2i_of_void *)d2i_DHxparams
438
#define dhx_d2i_PKCS8 dh_d2i_PKCS8
439
#define dhx_free dh_free_key
440
#define dhx_check NULL
441
#define dhx_adjust dh_adjust
442
#endif
443
444
/* ---------------------------------------------------------------------- */
445
446
#ifndef OPENSSL_NO_DSA
447
static void dsa_free_key(void *key)
448
0
{
449
0
    DSA_free(key);
450
0
}
451
452
#define dsa_evp_type EVP_PKEY_DSA
453
#define dsa_d2i_private_key (d2i_of_void *)d2i_DSAPrivateKey
454
#define dsa_d2i_public_key (d2i_of_void *)d2i_DSAPublicKey
455
#define dsa_d2i_key_params (d2i_of_void *)d2i_DSAparams
456
#define dsa_free dsa_free_key
457
#define dsa_check NULL
458
459
static void *dsa_d2i_PKCS8(const unsigned char **der, long der_len,
460
    struct der2key_ctx_st *ctx)
461
0
{
462
0
    return der2key_decode_p8(der, der_len, ctx,
463
0
        (key_from_pkcs8_t *)ossl_dsa_key_from_pkcs8);
464
0
}
465
466
0
D2I_PUBKEY_NOCTX(dsa, ossl_d2i_DSA_PUBKEY)
467
468
static void dsa_adjust(void *key, struct der2key_ctx_st *ctx)
469
0
{
470
0
    ossl_dsa_set0_libctx(key, PROV_LIBCTX_OF(ctx->provctx));
471
0
}
472
#endif
473
474
/* ---------------------------------------------------------------------- */
475
476
#ifndef OPENSSL_NO_EC
477
static void ec_free_key(void *key)
478
0
{
479
0
    EC_KEY_free(key);
480
0
}
481
482
#define ec_evp_type EVP_PKEY_EC
483
#define ec_d2i_private_key (d2i_of_void *)d2i_ECPrivateKey
484
#define ec_d2i_public_key NULL
485
#define ec_d2i_key_params (d2i_of_void *)d2i_ECParameters
486
#define ec_free ec_free_key
487
488
static void *ec_d2i_PKCS8(const unsigned char **der, long der_len,
489
    struct der2key_ctx_st *ctx)
490
0
{
491
0
    return der2key_decode_p8(der, der_len, ctx,
492
0
        (key_from_pkcs8_t *)ossl_ec_key_from_pkcs8);
493
0
}
494
495
0
D2I_PUBKEY_NOCTX(ec, d2i_EC_PUBKEY)
496
497
static int ec_check(void *key, struct der2key_ctx_st *ctx)
498
0
{
499
    /* We're trying to be clever by comparing two truths */
500
0
    int ret = 0;
501
0
    int sm2 = (EC_KEY_get_flags(key) & EC_FLAG_SM2_RANGE) != 0;
502
503
0
    if (sm2)
504
0
        ret = ctx->desc->evp_type == EVP_PKEY_SM2
505
0
            || ctx->desc->evp_type == NID_X9_62_id_ecPublicKey;
506
0
    else
507
0
        ret = ctx->desc->evp_type != EVP_PKEY_SM2;
508
509
0
    return ret;
510
0
}
511
512
static void ec_adjust(void *key, struct der2key_ctx_st *ctx)
513
0
{
514
0
    ossl_ec_key_set0_libctx(key, PROV_LIBCTX_OF(ctx->provctx));
515
0
}
516
517
#ifndef OPENSSL_NO_ECX
518
/*
519
 * ED25519, ED448, X25519, X448 only implement PKCS#8 and SubjectPublicKeyInfo,
520
 * so no d2i functions to be had.
521
 */
522
523
static void *ecx_d2i_PKCS8(const unsigned char **der, long der_len,
524
    struct der2key_ctx_st *ctx)
525
0
{
526
0
    return der2key_decode_p8(der, der_len, ctx,
527
0
        (key_from_pkcs8_t *)ossl_ecx_key_from_pkcs8);
528
0
}
529
530
0
D2I_PUBKEY_NOCTX(ed25519, ossl_d2i_ED25519_PUBKEY)
531
0
D2I_PUBKEY_NOCTX(ed448, ossl_d2i_ED448_PUBKEY)
532
0
D2I_PUBKEY_NOCTX(x25519, ossl_d2i_X25519_PUBKEY)
533
0
D2I_PUBKEY_NOCTX(x448, ossl_d2i_X448_PUBKEY)
534
535
static void ecx_key_adjust(void *key, struct der2key_ctx_st *ctx)
536
0
{
537
0
    ossl_ecx_key_set0_libctx(key, PROV_LIBCTX_OF(ctx->provctx));
538
0
}
539
540
static void ecx_free_key(void *key)
541
0
{
542
0
    ossl_ecx_key_free(key);
543
0
}
544
545
#define ed25519_evp_type EVP_PKEY_ED25519
546
#define ed25519_d2i_private_key NULL
547
#define ed25519_d2i_public_key NULL
548
#define ed25519_d2i_key_params NULL
549
#define ed25519_d2i_PKCS8 ecx_d2i_PKCS8
550
#define ed25519_free ecx_free_key
551
#define ed25519_check NULL
552
#define ed25519_adjust ecx_key_adjust
553
554
#define ed448_evp_type EVP_PKEY_ED448
555
#define ed448_d2i_private_key NULL
556
#define ed448_d2i_public_key NULL
557
#define ed448_d2i_key_params NULL
558
#define ed448_d2i_PKCS8 ecx_d2i_PKCS8
559
#define ed448_free ecx_free_key
560
#define ed448_check NULL
561
#define ed448_adjust ecx_key_adjust
562
563
#define x25519_evp_type EVP_PKEY_X25519
564
#define x25519_d2i_private_key NULL
565
#define x25519_d2i_public_key NULL
566
#define x25519_d2i_key_params NULL
567
#define x25519_d2i_PKCS8 ecx_d2i_PKCS8
568
#define x25519_free ecx_free_key
569
#define x25519_check NULL
570
#define x25519_adjust ecx_key_adjust
571
572
#define x448_evp_type EVP_PKEY_X448
573
#define x448_d2i_private_key NULL
574
#define x448_d2i_public_key NULL
575
#define x448_d2i_key_params NULL
576
#define x448_d2i_PKCS8 ecx_d2i_PKCS8
577
#define x448_free ecx_free_key
578
#define x448_check NULL
579
#define x448_adjust ecx_key_adjust
580
#endif /* OPENSSL_NO_ECX */
581
582
#ifndef OPENSSL_NO_SM2
583
#define sm2_evp_type EVP_PKEY_SM2
584
#define sm2_d2i_private_key (d2i_of_void *)d2i_ECPrivateKey
585
#define sm2_d2i_public_key NULL
586
#define sm2_d2i_key_params (d2i_of_void *)d2i_ECParameters
587
#define sm2_d2i_PUBKEY ec_d2i_PUBKEY
588
#define sm2_free ec_free_key
589
#define sm2_check ec_check
590
#define sm2_adjust ec_adjust
591
592
static void *sm2_d2i_PKCS8(const unsigned char **der, long der_len,
593
    struct der2key_ctx_st *ctx)
594
0
{
595
0
    return der2key_decode_p8(der, der_len, ctx,
596
0
        (key_from_pkcs8_t *)ossl_ec_key_from_pkcs8);
597
0
}
598
#endif
599
600
#endif
601
602
/* ---------------------------------------------------------------------- */
603
604
#ifndef OPENSSL_NO_ML_KEM
605
static void *
606
ml_kem_d2i_PKCS8(const uint8_t **der, long der_len, struct der2key_ctx_st *ctx)
607
0
{
608
0
    ML_KEM_KEY *key;
609
610
0
    key = ossl_ml_kem_d2i_PKCS8(*der, der_len, ctx->desc->evp_type,
611
0
        ctx->provctx, ctx->propq);
612
0
    if (key != NULL)
613
0
        *der += der_len;
614
0
    return key;
615
0
}
616
617
static ossl_inline void *
618
ml_kem_d2i_PUBKEY(const uint8_t **der, long der_len,
619
    struct der2key_ctx_st *ctx)
620
0
{
621
0
    ML_KEM_KEY *key;
622
623
0
    key = ossl_ml_kem_d2i_PUBKEY(*der, der_len, ctx->desc->evp_type,
624
0
        ctx->provctx, ctx->propq);
625
0
    if (key != NULL)
626
0
        *der += der_len;
627
0
    return key;
628
0
}
629
630
static void ml_kem_free_key(void *key)
631
0
{
632
0
    ossl_ml_kem_key_free(key);
633
0
}
634
635
#define ml_kem_512_evp_type EVP_PKEY_ML_KEM_512
636
#define ml_kem_512_d2i_private_key NULL
637
#define ml_kem_512_d2i_public_key NULL
638
#define ml_kem_512_d2i_key_params NULL
639
#define ml_kem_512_d2i_PUBKEY ml_kem_d2i_PUBKEY
640
#define ml_kem_512_d2i_PKCS8 ml_kem_d2i_PKCS8
641
#define ml_kem_512_free ml_kem_free_key
642
#define ml_kem_512_check NULL
643
#define ml_kem_512_adjust NULL
644
645
#define ml_kem_768_evp_type EVP_PKEY_ML_KEM_768
646
#define ml_kem_768_d2i_private_key NULL
647
#define ml_kem_768_d2i_public_key NULL
648
#define ml_kem_768_d2i_key_params NULL
649
#define ml_kem_768_d2i_PUBKEY ml_kem_d2i_PUBKEY
650
#define ml_kem_768_d2i_PKCS8 ml_kem_d2i_PKCS8
651
#define ml_kem_768_free ml_kem_free_key
652
#define ml_kem_768_check NULL
653
#define ml_kem_768_adjust NULL
654
655
#define ml_kem_1024_evp_type EVP_PKEY_ML_KEM_1024
656
#define ml_kem_1024_d2i_private_key NULL
657
#define ml_kem_1024_d2i_public_key NULL
658
#define ml_kem_1024_d2i_PUBKEY ml_kem_d2i_PUBKEY
659
#define ml_kem_1024_d2i_PKCS8 ml_kem_d2i_PKCS8
660
#define ml_kem_1024_d2i_key_params NULL
661
#define ml_kem_1024_free ml_kem_free_key
662
#define ml_kem_1024_check NULL
663
#define ml_kem_1024_adjust NULL
664
665
#endif
666
667
#ifndef OPENSSL_NO_SLH_DSA
668
static void slh_dsa_free_key(void *key)
669
0
{
670
0
    ossl_slh_dsa_key_free(key);
671
0
}
672
673
static void *
674
slh_dsa_d2i_PKCS8(const uint8_t **der, long der_len, struct der2key_ctx_st *ctx)
675
0
{
676
0
    SLH_DSA_KEY *key = NULL, *ret = NULL;
677
0
    OSSL_LIB_CTX *libctx = PROV_LIBCTX_OF(ctx->provctx);
678
0
    PKCS8_PRIV_KEY_INFO *p8inf = NULL;
679
0
    const unsigned char *p;
680
0
    const X509_ALGOR *alg = NULL;
681
0
    int plen, ptype;
682
683
0
    if ((p8inf = d2i_PKCS8_PRIV_KEY_INFO(NULL, der, der_len)) == NULL
684
0
        || !PKCS8_pkey_get0(NULL, &p, &plen, &alg, p8inf))
685
0
        goto end;
686
687
    /* Algorithm parameters must be absent. */
688
0
    if ((X509_ALGOR_get0(NULL, &ptype, NULL, alg), ptype != V_ASN1_UNDEF)) {
689
0
        ERR_raise_data(ERR_LIB_PROV, PROV_R_UNEXPECTED_KEY_PARAMETERS,
690
0
            "unexpected parameters with a PKCS#8 %s private key",
691
0
            ctx->desc->keytype_name);
692
0
        goto end;
693
0
    }
694
0
    if (OBJ_obj2nid(alg->algorithm) != ctx->desc->evp_type)
695
0
        goto end;
696
0
    if ((key = ossl_slh_dsa_key_new(libctx, ctx->propq,
697
0
             ctx->desc->keytype_name))
698
0
        == NULL)
699
0
        goto end;
700
701
0
    if (!ossl_slh_dsa_set_priv(key, p, plen))
702
0
        goto end;
703
0
    ret = key;
704
0
end:
705
0
    PKCS8_PRIV_KEY_INFO_free(p8inf);
706
0
    if (ret == NULL)
707
0
        ossl_slh_dsa_key_free(key);
708
0
    return ret;
709
0
}
710
711
static ossl_inline void *slh_dsa_d2i_PUBKEY(const uint8_t **der, long der_len,
712
    struct der2key_ctx_st *ctx)
713
0
{
714
0
    int ok = 0;
715
0
    OSSL_LIB_CTX *libctx = PROV_LIBCTX_OF(ctx->provctx);
716
0
    SLH_DSA_KEY *ret = NULL;
717
0
    BARE_PUBKEY *spki = NULL;
718
0
    const uint8_t *end = *der;
719
0
    size_t len;
720
721
0
    ret = ossl_slh_dsa_key_new(libctx, ctx->propq, ctx->desc->keytype_name);
722
0
    if (ret == NULL)
723
0
        return NULL;
724
0
    len = ossl_slh_dsa_key_get_pub_len(ret);
725
726
    /*-
727
     * The DER ASN.1 encoding of SLH-DSA public keys prepends 18 bytes to the
728
     * encoded public key (since the largest public key size is 64 bytes):
729
     *
730
     * - 2 byte outer sequence tag and length
731
     * -  2 byte algorithm sequence tag and length
732
     * -    2 byte algorithm OID tag and length
733
     * -      9 byte algorithm OID
734
     * -  2 byte bit string tag and length
735
     * -    1 bitstring lead byte
736
     *
737
     * Check that we have the right OID, the bit string has no "bits left" and
738
     * that we consume all the input exactly.
739
     */
740
0
    if (der_len != 18 + (long)len) {
741
0
        ERR_raise_data(ERR_LIB_PROV, PROV_R_BAD_ENCODING,
742
0
            "unexpected %s public key length: %ld != %ld",
743
0
            ctx->desc->keytype_name, der_len,
744
0
            18 + (long)len);
745
0
        goto err;
746
0
    }
747
748
0
    if ((spki = OPENSSL_zalloc(sizeof(*spki))) == NULL)
749
0
        goto err;
750
751
    /* The spki storage is freed on error */
752
0
    if (ASN1_item_d2i_ex((ASN1_VALUE **)&spki, &end, der_len,
753
0
            ASN1_ITEM_rptr(BARE_PUBKEY), NULL, NULL)
754
0
        == NULL) {
755
0
        ERR_raise_data(ERR_LIB_PROV, PROV_R_BAD_ENCODING,
756
0
            "malformed %s public key ASN.1 encoding",
757
0
            ossl_slh_dsa_key_get_name(ret));
758
0
        goto err;
759
0
    }
760
761
    /* The spki structure now owns some memory */
762
0
    if ((spki->pubkey->flags & 0x7) != 0 || end != *der + der_len) {
763
0
        ERR_raise_data(ERR_LIB_PROV, PROV_R_BAD_ENCODING,
764
0
            "malformed %s public key ASN.1 encoding",
765
0
            ossl_slh_dsa_key_get_name(ret));
766
0
        goto err;
767
0
    }
768
0
    if (OBJ_cmp(OBJ_nid2obj(ctx->desc->evp_type), spki->algor.oid) != 0) {
769
0
        ERR_raise_data(ERR_LIB_PROV, PROV_R_BAD_ENCODING,
770
0
            "unexpected algorithm OID for an %s public key",
771
0
            ossl_slh_dsa_key_get_name(ret));
772
0
        goto err;
773
0
    }
774
775
0
    if (!ossl_slh_dsa_set_pub(ret, spki->pubkey->data, spki->pubkey->length)) {
776
0
        ERR_raise_data(ERR_LIB_PROV, PROV_R_BAD_ENCODING,
777
0
            "failed to parse %s public key from the input data",
778
0
            ossl_slh_dsa_key_get_name(ret));
779
0
        goto err;
780
0
    }
781
0
    ok = 1;
782
0
err:
783
0
    if (spki != NULL) {
784
0
        ASN1_OBJECT_free(spki->algor.oid);
785
0
        ASN1_BIT_STRING_free(spki->pubkey);
786
0
        OPENSSL_free(spki);
787
0
    }
788
0
    if (!ok) {
789
0
        ossl_slh_dsa_key_free(ret);
790
0
        ret = NULL;
791
0
    }
792
0
    return ret;
793
0
}
794
795
#define slh_dsa_sha2_128s_evp_type EVP_PKEY_SLH_DSA_SHA2_128S
796
#define slh_dsa_sha2_128s_d2i_private_key NULL
797
#define slh_dsa_sha2_128s_d2i_public_key NULL
798
#define slh_dsa_sha2_128s_d2i_key_params NULL
799
#define slh_dsa_sha2_128s_d2i_PKCS8 slh_dsa_d2i_PKCS8
800
#define slh_dsa_sha2_128s_d2i_PUBKEY slh_dsa_d2i_PUBKEY
801
#define slh_dsa_sha2_128s_free slh_dsa_free_key
802
#define slh_dsa_sha2_128s_check NULL
803
#define slh_dsa_sha2_128s_adjust NULL
804
805
#define slh_dsa_sha2_128f_evp_type EVP_PKEY_SLH_DSA_SHA2_128F
806
#define slh_dsa_sha2_128f_d2i_private_key NULL
807
#define slh_dsa_sha2_128f_d2i_public_key NULL
808
#define slh_dsa_sha2_128f_d2i_key_params NULL
809
#define slh_dsa_sha2_128f_d2i_PKCS8 slh_dsa_d2i_PKCS8
810
#define slh_dsa_sha2_128f_d2i_PUBKEY slh_dsa_d2i_PUBKEY
811
#define slh_dsa_sha2_128f_free slh_dsa_free_key
812
#define slh_dsa_sha2_128f_check NULL
813
#define slh_dsa_sha2_128f_adjust NULL
814
815
#define slh_dsa_sha2_192s_evp_type EVP_PKEY_SLH_DSA_SHA2_192S
816
#define slh_dsa_sha2_192s_d2i_private_key NULL
817
#define slh_dsa_sha2_192s_d2i_public_key NULL
818
#define slh_dsa_sha2_192s_d2i_key_params NULL
819
#define slh_dsa_sha2_192s_d2i_PKCS8 slh_dsa_d2i_PKCS8
820
#define slh_dsa_sha2_192s_d2i_PUBKEY slh_dsa_d2i_PUBKEY
821
#define slh_dsa_sha2_192s_free slh_dsa_free_key
822
#define slh_dsa_sha2_192s_check NULL
823
#define slh_dsa_sha2_192s_adjust NULL
824
825
#define slh_dsa_sha2_192f_evp_type EVP_PKEY_SLH_DSA_SHA2_192F
826
#define slh_dsa_sha2_192f_d2i_private_key NULL
827
#define slh_dsa_sha2_192f_d2i_public_key NULL
828
#define slh_dsa_sha2_192f_d2i_key_params NULL
829
#define slh_dsa_sha2_192f_d2i_PKCS8 slh_dsa_d2i_PKCS8
830
#define slh_dsa_sha2_192f_d2i_PUBKEY slh_dsa_d2i_PUBKEY
831
#define slh_dsa_sha2_192f_free slh_dsa_free_key
832
#define slh_dsa_sha2_192f_check NULL
833
#define slh_dsa_sha2_192f_adjust NULL
834
835
#define slh_dsa_sha2_256s_evp_type EVP_PKEY_SLH_DSA_SHA2_256S
836
#define slh_dsa_sha2_256s_d2i_private_key NULL
837
#define slh_dsa_sha2_256s_d2i_public_key NULL
838
#define slh_dsa_sha2_256s_d2i_key_params NULL
839
#define slh_dsa_sha2_256s_d2i_PKCS8 slh_dsa_d2i_PKCS8
840
#define slh_dsa_sha2_256s_d2i_PUBKEY slh_dsa_d2i_PUBKEY
841
#define slh_dsa_sha2_256s_free slh_dsa_free_key
842
#define slh_dsa_sha2_256s_check NULL
843
#define slh_dsa_sha2_256s_adjust NULL
844
845
#define slh_dsa_sha2_256f_evp_type EVP_PKEY_SLH_DSA_SHA2_256F
846
#define slh_dsa_sha2_256f_d2i_private_key NULL
847
#define slh_dsa_sha2_256f_d2i_public_key NULL
848
#define slh_dsa_sha2_256f_d2i_key_params NULL
849
#define slh_dsa_sha2_256f_d2i_PKCS8 slh_dsa_d2i_PKCS8
850
#define slh_dsa_sha2_256f_d2i_PUBKEY slh_dsa_d2i_PUBKEY
851
#define slh_dsa_sha2_256f_free slh_dsa_free_key
852
#define slh_dsa_sha2_256f_check NULL
853
#define slh_dsa_sha2_256f_adjust NULL
854
855
#define slh_dsa_shake_128s_evp_type EVP_PKEY_SLH_DSA_SHAKE_128S
856
#define slh_dsa_shake_128s_d2i_private_key NULL
857
#define slh_dsa_shake_128s_d2i_public_key NULL
858
#define slh_dsa_shake_128s_d2i_key_params NULL
859
#define slh_dsa_shake_128s_d2i_PKCS8 slh_dsa_d2i_PKCS8
860
#define slh_dsa_shake_128s_d2i_PUBKEY slh_dsa_d2i_PUBKEY
861
#define slh_dsa_shake_128s_free slh_dsa_free_key
862
#define slh_dsa_shake_128s_check NULL
863
#define slh_dsa_shake_128s_adjust NULL
864
865
#define slh_dsa_shake_128f_evp_type EVP_PKEY_SLH_DSA_SHAKE_128F
866
#define slh_dsa_shake_128f_d2i_private_key NULL
867
#define slh_dsa_shake_128f_d2i_public_key NULL
868
#define slh_dsa_shake_128f_d2i_key_params NULL
869
#define slh_dsa_shake_128f_d2i_PKCS8 slh_dsa_d2i_PKCS8
870
#define slh_dsa_shake_128f_d2i_PUBKEY slh_dsa_d2i_PUBKEY
871
#define slh_dsa_shake_128f_free slh_dsa_free_key
872
#define slh_dsa_shake_128f_check NULL
873
#define slh_dsa_shake_128f_adjust NULL
874
875
#define slh_dsa_shake_192s_evp_type EVP_PKEY_SLH_DSA_SHAKE_192S
876
#define slh_dsa_shake_192s_d2i_private_key NULL
877
#define slh_dsa_shake_192s_d2i_public_key NULL
878
#define slh_dsa_shake_192s_d2i_key_params NULL
879
#define slh_dsa_shake_192s_d2i_PKCS8 slh_dsa_d2i_PKCS8
880
#define slh_dsa_shake_192s_d2i_PUBKEY slh_dsa_d2i_PUBKEY
881
#define slh_dsa_shake_192s_free slh_dsa_free_key
882
#define slh_dsa_shake_192s_check NULL
883
#define slh_dsa_shake_192s_adjust NULL
884
885
#define slh_dsa_shake_192f_evp_type EVP_PKEY_SLH_DSA_SHAKE_192F
886
#define slh_dsa_shake_192f_d2i_private_key NULL
887
#define slh_dsa_shake_192f_d2i_public_key NULL
888
#define slh_dsa_shake_192f_d2i_key_params NULL
889
#define slh_dsa_shake_192f_d2i_PKCS8 slh_dsa_d2i_PKCS8
890
#define slh_dsa_shake_192f_d2i_PUBKEY slh_dsa_d2i_PUBKEY
891
#define slh_dsa_shake_192f_free slh_dsa_free_key
892
#define slh_dsa_shake_192f_check NULL
893
#define slh_dsa_shake_192f_adjust NULL
894
895
#define slh_dsa_shake_256s_evp_type EVP_PKEY_SLH_DSA_SHAKE_256S
896
#define slh_dsa_shake_256s_d2i_private_key NULL
897
#define slh_dsa_shake_256s_d2i_public_key NULL
898
#define slh_dsa_shake_256s_d2i_key_params NULL
899
#define slh_dsa_shake_256s_d2i_PKCS8 slh_dsa_d2i_PKCS8
900
#define slh_dsa_shake_256s_d2i_PUBKEY slh_dsa_d2i_PUBKEY
901
#define slh_dsa_shake_256s_free slh_dsa_free_key
902
#define slh_dsa_shake_256s_check NULL
903
#define slh_dsa_shake_256s_adjust NULL
904
905
#define slh_dsa_shake_256f_evp_type EVP_PKEY_SLH_DSA_SHAKE_256F
906
#define slh_dsa_shake_256f_d2i_private_key NULL
907
#define slh_dsa_shake_256f_d2i_public_key NULL
908
#define slh_dsa_shake_256f_d2i_key_params NULL
909
#define slh_dsa_shake_256f_d2i_PKCS8 slh_dsa_d2i_PKCS8
910
#define slh_dsa_shake_256f_d2i_PUBKEY slh_dsa_d2i_PUBKEY
911
#define slh_dsa_shake_256f_free slh_dsa_free_key
912
#define slh_dsa_shake_256f_check NULL
913
#define slh_dsa_shake_256f_adjust NULL
914
#endif /* OPENSSL_NO_SLH_DSA */
915
916
/* ---------------------------------------------------------------------- */
917
918
static void rsa_free_key(void *key)
919
0
{
920
0
    RSA_free(key);
921
0
}
922
923
#define rsa_evp_type EVP_PKEY_RSA
924
#define rsa_d2i_private_key (d2i_of_void *)d2i_RSAPrivateKey
925
#define rsa_d2i_public_key (d2i_of_void *)d2i_RSAPublicKey
926
#define rsa_d2i_key_params NULL
927
#define rsa_free rsa_free_key
928
929
static void *rsa_d2i_PKCS8(const unsigned char **der, long der_len,
930
    struct der2key_ctx_st *ctx)
931
0
{
932
0
    return der2key_decode_p8(der, der_len, ctx,
933
0
        (key_from_pkcs8_t *)ossl_rsa_key_from_pkcs8);
934
0
}
935
936
static void *
937
rsa_d2i_PUBKEY(const unsigned char **der, long der_len,
938
    ossl_unused struct der2key_ctx_st *ctx)
939
0
{
940
0
    return d2i_RSA_PUBKEY(NULL, der, der_len);
941
0
}
942
943
static int rsa_check(void *key, struct der2key_ctx_st *ctx)
944
0
{
945
0
    int valid;
946
947
0
    switch (RSA_test_flags(key, RSA_FLAG_TYPE_MASK)) {
948
0
    case RSA_FLAG_TYPE_RSA:
949
0
        valid = (ctx->desc->evp_type == EVP_PKEY_RSA);
950
0
        break;
951
0
    case RSA_FLAG_TYPE_RSASSAPSS:
952
0
        valid = (ctx->desc->evp_type == EVP_PKEY_RSA_PSS);
953
0
        break;
954
0
    default:
955
        /* Currently unsupported RSA key type */
956
0
        valid = 0;
957
0
    }
958
959
0
    valid = (valid && ossl_rsa_check_factors(key));
960
961
0
    return valid;
962
0
}
963
964
static void rsa_adjust(void *key, struct der2key_ctx_st *ctx)
965
0
{
966
0
    ossl_rsa_set0_libctx(key, PROV_LIBCTX_OF(ctx->provctx));
967
0
}
968
969
#define rsapss_evp_type EVP_PKEY_RSA_PSS
970
#define rsapss_d2i_private_key (d2i_of_void *)d2i_RSAPrivateKey
971
#define rsapss_d2i_public_key (d2i_of_void *)d2i_RSAPublicKey
972
#define rsapss_d2i_key_params NULL
973
#define rsapss_d2i_PKCS8 rsa_d2i_PKCS8
974
#define rsapss_d2i_PUBKEY rsa_d2i_PUBKEY
975
#define rsapss_free rsa_free_key
976
#define rsapss_check rsa_check
977
#define rsapss_adjust rsa_adjust
978
979
/* ---------------------------------------------------------------------- */
980
981
#ifndef OPENSSL_NO_ML_DSA
982
static void ml_dsa_free_key(void *key)
983
0
{
984
0
    ossl_ml_dsa_key_free(key);
985
0
}
986
987
static void *
988
ml_dsa_d2i_PKCS8(const uint8_t **der, long der_len, struct der2key_ctx_st *ctx)
989
0
{
990
0
    ML_DSA_KEY *key;
991
992
0
    key = ossl_ml_dsa_d2i_PKCS8(*der, der_len, ctx->desc->evp_type,
993
0
        ctx->provctx, ctx->propq);
994
0
    if (key != NULL)
995
0
        *der += der_len;
996
0
    return key;
997
0
}
998
999
static ossl_inline void *ml_dsa_d2i_PUBKEY(const uint8_t **der, long der_len,
1000
    struct der2key_ctx_st *ctx)
1001
0
{
1002
0
    ML_DSA_KEY *key;
1003
1004
0
    key = ossl_ml_dsa_d2i_PUBKEY(*der, der_len, ctx->desc->evp_type,
1005
0
        ctx->provctx, ctx->propq);
1006
0
    if (key != NULL)
1007
0
        *der += der_len;
1008
0
    return key;
1009
0
}
1010
1011
#define ml_dsa_44_evp_type EVP_PKEY_ML_DSA_44
1012
#define ml_dsa_44_d2i_private_key NULL
1013
#define ml_dsa_44_d2i_public_key NULL
1014
#define ml_dsa_44_d2i_key_params NULL
1015
#define ml_dsa_44_d2i_PUBKEY ml_dsa_d2i_PUBKEY
1016
#define ml_dsa_44_d2i_PKCS8 ml_dsa_d2i_PKCS8
1017
#define ml_dsa_44_free ml_dsa_free_key
1018
#define ml_dsa_44_check NULL
1019
#define ml_dsa_44_adjust NULL
1020
1021
#define ml_dsa_65_evp_type EVP_PKEY_ML_DSA_65
1022
#define ml_dsa_65_d2i_private_key NULL
1023
#define ml_dsa_65_d2i_public_key NULL
1024
#define ml_dsa_65_d2i_key_params NULL
1025
#define ml_dsa_65_d2i_PUBKEY ml_dsa_d2i_PUBKEY
1026
#define ml_dsa_65_d2i_PKCS8 ml_dsa_d2i_PKCS8
1027
#define ml_dsa_65_free ml_dsa_free_key
1028
#define ml_dsa_65_check NULL
1029
#define ml_dsa_65_adjust NULL
1030
1031
#define ml_dsa_87_evp_type EVP_PKEY_ML_DSA_87
1032
#define ml_dsa_87_d2i_private_key NULL
1033
#define ml_dsa_87_d2i_public_key NULL
1034
#define ml_dsa_87_d2i_PUBKEY ml_dsa_d2i_PUBKEY
1035
#define ml_dsa_87_d2i_PKCS8 ml_dsa_d2i_PKCS8
1036
#define ml_dsa_87_d2i_key_params NULL
1037
#define ml_dsa_87_free ml_dsa_free_key
1038
#define ml_dsa_87_check NULL
1039
#define ml_dsa_87_adjust NULL
1040
1041
#endif
1042
1043
/* ---------------------------------------------------------------------- */
1044
1045
#ifndef OPENSSL_NO_LMS
1046
static void lms_free_key(void *key)
1047
{
1048
    ossl_lms_key_free(key);
1049
}
1050
1051
#define lms_evp_type EVP_PKEY_HSS_LMS
1052
#define lms_free lms_free_key
1053
#define lms_check NULL
1054
#define lms_adjust NULL
1055
1056
static ossl_inline void *lms_d2i_PUBKEY(const uint8_t **der, long der_len,
1057
    struct der2key_ctx_st *ctx)
1058
{
1059
    LMS_KEY *key;
1060
1061
    key = ossl_lms_d2i_PUBKEY(*der, der_len, ctx->provctx);
1062
    if (key != NULL)
1063
        *der += der_len;
1064
    return key;
1065
}
1066
#endif
1067
/* ---------------------------------------------------------------------- */
1068
1069
/*
1070
 * The DO_ macros help define the selection mask and the method functions
1071
 * for each kind of object we want to decode.
1072
 */
1073
#define DO_type_specific_keypair(keytype) \
1074
    "type-specific", keytype##_evp_type,  \
1075
        (OSSL_KEYMGMT_SELECT_KEYPAIR),    \
1076
        keytype##_d2i_private_key,        \
1077
        keytype##_d2i_public_key,         \
1078
        NULL,                             \
1079
        NULL,                             \
1080
        NULL,                             \
1081
        keytype##_check,                  \
1082
        keytype##_adjust,                 \
1083
        keytype##_free
1084
1085
#define DO_type_specific_pub(keytype)     \
1086
    "type-specific", keytype##_evp_type,  \
1087
        (OSSL_KEYMGMT_SELECT_PUBLIC_KEY), \
1088
        NULL,                             \
1089
        keytype##_d2i_public_key,         \
1090
        NULL,                             \
1091
        NULL,                             \
1092
        NULL,                             \
1093
        keytype##_check,                  \
1094
        keytype##_adjust,                 \
1095
        keytype##_free
1096
1097
#define DO_type_specific_priv(keytype)     \
1098
    "type-specific", keytype##_evp_type,   \
1099
        (OSSL_KEYMGMT_SELECT_PRIVATE_KEY), \
1100
        keytype##_d2i_private_key,         \
1101
        NULL,                              \
1102
        NULL,                              \
1103
        NULL,                              \
1104
        NULL,                              \
1105
        keytype##_check,                   \
1106
        keytype##_adjust,                  \
1107
        keytype##_free
1108
1109
#define DO_type_specific_params(keytype)      \
1110
    "type-specific", keytype##_evp_type,      \
1111
        (OSSL_KEYMGMT_SELECT_ALL_PARAMETERS), \
1112
        NULL,                                 \
1113
        NULL,                                 \
1114
        keytype##_d2i_key_params,             \
1115
        NULL,                                 \
1116
        NULL,                                 \
1117
        keytype##_check,                      \
1118
        keytype##_adjust,                     \
1119
        keytype##_free
1120
1121
#define DO_type_specific(keytype)        \
1122
    "type-specific", keytype##_evp_type, \
1123
        (OSSL_KEYMGMT_SELECT_ALL),       \
1124
        keytype##_d2i_private_key,       \
1125
        keytype##_d2i_public_key,        \
1126
        keytype##_d2i_key_params,        \
1127
        NULL,                            \
1128
        NULL,                            \
1129
        keytype##_check,                 \
1130
        keytype##_adjust,                \
1131
        keytype##_free
1132
1133
#define DO_type_specific_no_pub(keytype)           \
1134
    "type-specific", keytype##_evp_type,           \
1135
        (OSSL_KEYMGMT_SELECT_PRIVATE_KEY           \
1136
            | OSSL_KEYMGMT_SELECT_ALL_PARAMETERS), \
1137
        keytype##_d2i_private_key,                 \
1138
        NULL,                                      \
1139
        keytype##_d2i_key_params,                  \
1140
        NULL,                                      \
1141
        NULL,                                      \
1142
        keytype##_check,                           \
1143
        keytype##_adjust,                          \
1144
        keytype##_free
1145
1146
#define DO_PrivateKeyInfo(keytype)         \
1147
    "PrivateKeyInfo", keytype##_evp_type,  \
1148
        (OSSL_KEYMGMT_SELECT_PRIVATE_KEY), \
1149
        NULL,                              \
1150
        NULL,                              \
1151
        NULL,                              \
1152
        keytype##_d2i_PKCS8,               \
1153
        NULL,                              \
1154
        keytype##_check,                   \
1155
        keytype##_adjust,                  \
1156
        keytype##_free
1157
1158
#define DO_SubjectPublicKeyInfo(keytype)        \
1159
    "SubjectPublicKeyInfo", keytype##_evp_type, \
1160
        (OSSL_KEYMGMT_SELECT_PUBLIC_KEY),       \
1161
        NULL,                                   \
1162
        NULL,                                   \
1163
        NULL,                                   \
1164
        NULL,                                   \
1165
        keytype##_d2i_PUBKEY,                   \
1166
        keytype##_check,                        \
1167
        keytype##_adjust,                       \
1168
        keytype##_free
1169
1170
#define DO_DH(keytype)                        \
1171
    "DH", keytype##_evp_type,                 \
1172
        (OSSL_KEYMGMT_SELECT_ALL_PARAMETERS), \
1173
        NULL,                                 \
1174
        NULL,                                 \
1175
        keytype##_d2i_key_params,             \
1176
        NULL,                                 \
1177
        NULL,                                 \
1178
        keytype##_check,                      \
1179
        keytype##_adjust,                     \
1180
        keytype##_free
1181
1182
#define DO_DHX(keytype)                       \
1183
    "DHX", keytype##_evp_type,                \
1184
        (OSSL_KEYMGMT_SELECT_ALL_PARAMETERS), \
1185
        NULL,                                 \
1186
        NULL,                                 \
1187
        keytype##_d2i_key_params,             \
1188
        NULL,                                 \
1189
        NULL,                                 \
1190
        keytype##_check,                      \
1191
        keytype##_adjust,                     \
1192
        keytype##_free
1193
1194
#define DO_DSA(keytype)            \
1195
    "DSA", keytype##_evp_type,     \
1196
        (OSSL_KEYMGMT_SELECT_ALL), \
1197
        keytype##_d2i_private_key, \
1198
        keytype##_d2i_public_key,  \
1199
        keytype##_d2i_key_params,  \
1200
        NULL,                      \
1201
        NULL,                      \
1202
        keytype##_check,           \
1203
        keytype##_adjust,          \
1204
        keytype##_free
1205
1206
#define DO_EC(keytype)                             \
1207
    "EC", keytype##_evp_type,                      \
1208
        (OSSL_KEYMGMT_SELECT_PRIVATE_KEY           \
1209
            | OSSL_KEYMGMT_SELECT_ALL_PARAMETERS), \
1210
        keytype##_d2i_private_key,                 \
1211
        NULL,                                      \
1212
        keytype##_d2i_key_params,                  \
1213
        NULL,                                      \
1214
        NULL,                                      \
1215
        keytype##_check,                           \
1216
        keytype##_adjust,                          \
1217
        keytype##_free
1218
1219
#define DO_RSA(keytype)                \
1220
    "RSA", keytype##_evp_type,         \
1221
        (OSSL_KEYMGMT_SELECT_KEYPAIR), \
1222
        keytype##_d2i_private_key,     \
1223
        keytype##_d2i_public_key,      \
1224
        NULL,                          \
1225
        NULL,                          \
1226
        NULL,                          \
1227
        keytype##_check,               \
1228
        keytype##_adjust,              \
1229
        keytype##_free
1230
1231
/*
1232
 * MAKE_DECODER is the single driver for creating OSSL_DISPATCH tables.
1233
 * It takes the following arguments:
1234
 *
1235
 * keytype_name The implementation key type as a string.
1236
 * keytype      The implementation key type.  This must correspond exactly
1237
 *              to our existing keymgmt keytype names...  in other words,
1238
 *              there must exist an ossl_##keytype##_keymgmt_functions.
1239
 * type         The type name for the set of functions that implement the
1240
 *              decoder for the key type.  This isn't necessarily the same
1241
 *              as keytype.  For example, the key types ed25519, ed448,
1242
 *              x25519 and x448 are all handled by the same functions with
1243
 *              the common type name ecx.
1244
 * kind         The kind of support to implement.  This translates into
1245
 *              the DO_##kind macros above, to populate the keytype_desc_st
1246
 *              structure.
1247
 */
1248
#define MAKE_DECODER(keytype_name, keytype, type, kind)                                                               \
1249
    static const struct keytype_desc_st kind##_##keytype##_desc = { keytype_name, ossl_##keytype##_keymgmt_functions, \
1250
        DO_##kind(keytype) };                                                                                         \
1251
                                                                                                                      \
1252
    static OSSL_FUNC_decoder_newctx_fn kind##_der2##keytype##_newctx;                                                 \
1253
                                                                                                                      \
1254
    static void *kind##_der2##keytype##_newctx(void *provctx)                                                         \
1255
0
    {                                                                                                                 \
1256
0
        return der2key_newctx(provctx, &kind##_##keytype##_desc);                                                     \
1257
0
    }                                                                                                                 \
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2dh_newctx
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2dh_newctx
Unexecuted instantiation: decode_der2key.c:type_specific_params_der2dh_newctx
Unexecuted instantiation: decode_der2key.c:DH_der2dh_newctx
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2dhx_newctx
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2dhx_newctx
Unexecuted instantiation: decode_der2key.c:type_specific_params_der2dhx_newctx
Unexecuted instantiation: decode_der2key.c:DHX_der2dhx_newctx
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2dsa_newctx
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2dsa_newctx
Unexecuted instantiation: decode_der2key.c:type_specific_der2dsa_newctx
Unexecuted instantiation: decode_der2key.c:DSA_der2dsa_newctx
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2ec_newctx
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2ec_newctx
Unexecuted instantiation: decode_der2key.c:type_specific_no_pub_der2ec_newctx
Unexecuted instantiation: decode_der2key.c:EC_der2ec_newctx
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2x25519_newctx
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2x25519_newctx
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2x448_newctx
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2x448_newctx
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2ed25519_newctx
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2ed25519_newctx
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2ed448_newctx
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2ed448_newctx
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2sm2_newctx
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2sm2_newctx
Unexecuted instantiation: decode_der2key.c:type_specific_no_pub_der2sm2_newctx
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2ml_kem_512_newctx
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2ml_kem_512_newctx
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2ml_kem_768_newctx
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2ml_kem_768_newctx
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2ml_kem_1024_newctx
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2ml_kem_1024_newctx
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_sha2_128s_newctx
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_sha2_128f_newctx
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_sha2_192s_newctx
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_sha2_192f_newctx
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_sha2_256s_newctx
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_sha2_256f_newctx
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_shake_128s_newctx
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_shake_128f_newctx
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_shake_192s_newctx
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_shake_192f_newctx
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_shake_256s_newctx
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_shake_256f_newctx
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_sha2_128s_newctx
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_sha2_128f_newctx
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_sha2_192s_newctx
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_sha2_192f_newctx
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_sha2_256s_newctx
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_sha2_256f_newctx
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_shake_128s_newctx
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_shake_128f_newctx
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_shake_192s_newctx
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_shake_192f_newctx
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_shake_256s_newctx
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_shake_256f_newctx
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2rsa_newctx
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2rsa_newctx
Unexecuted instantiation: decode_der2key.c:type_specific_keypair_der2rsa_newctx
Unexecuted instantiation: decode_der2key.c:RSA_der2rsa_newctx
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2rsapss_newctx
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2rsapss_newctx
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2ml_dsa_44_newctx
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2ml_dsa_44_newctx
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2ml_dsa_65_newctx
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2ml_dsa_65_newctx
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2ml_dsa_87_newctx
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2ml_dsa_87_newctx
1258
    static int kind##_der2##keytype##_does_selection(void *provctx,                                                   \
1259
        int selection)                                                                                                \
1260
0
    {                                                                                                                 \
1261
0
        return der2key_check_selection(selection,                                                                     \
1262
0
            &kind##_##keytype##_desc);                                                                                \
1263
0
    }                                                                                                                 \
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2dh_does_selection
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2dh_does_selection
Unexecuted instantiation: decode_der2key.c:type_specific_params_der2dh_does_selection
Unexecuted instantiation: decode_der2key.c:DH_der2dh_does_selection
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2dhx_does_selection
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2dhx_does_selection
Unexecuted instantiation: decode_der2key.c:type_specific_params_der2dhx_does_selection
Unexecuted instantiation: decode_der2key.c:DHX_der2dhx_does_selection
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2dsa_does_selection
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2dsa_does_selection
Unexecuted instantiation: decode_der2key.c:type_specific_der2dsa_does_selection
Unexecuted instantiation: decode_der2key.c:DSA_der2dsa_does_selection
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2ec_does_selection
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2ec_does_selection
Unexecuted instantiation: decode_der2key.c:type_specific_no_pub_der2ec_does_selection
Unexecuted instantiation: decode_der2key.c:EC_der2ec_does_selection
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2x25519_does_selection
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2x25519_does_selection
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2x448_does_selection
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2x448_does_selection
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2ed25519_does_selection
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2ed25519_does_selection
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2ed448_does_selection
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2ed448_does_selection
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2sm2_does_selection
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2sm2_does_selection
Unexecuted instantiation: decode_der2key.c:type_specific_no_pub_der2sm2_does_selection
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2ml_kem_512_does_selection
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2ml_kem_512_does_selection
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2ml_kem_768_does_selection
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2ml_kem_768_does_selection
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2ml_kem_1024_does_selection
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2ml_kem_1024_does_selection
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_sha2_128s_does_selection
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_sha2_128f_does_selection
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_sha2_192s_does_selection
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_sha2_192f_does_selection
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_sha2_256s_does_selection
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_sha2_256f_does_selection
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_shake_128s_does_selection
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_shake_128f_does_selection
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_shake_192s_does_selection
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_shake_192f_does_selection
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_shake_256s_does_selection
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2slh_dsa_shake_256f_does_selection
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_sha2_128s_does_selection
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_sha2_128f_does_selection
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_sha2_192s_does_selection
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_sha2_192f_does_selection
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_sha2_256s_does_selection
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_sha2_256f_does_selection
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_shake_128s_does_selection
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_shake_128f_does_selection
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_shake_192s_does_selection
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_shake_192f_does_selection
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_shake_256s_does_selection
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2slh_dsa_shake_256f_does_selection
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2rsa_does_selection
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2rsa_does_selection
Unexecuted instantiation: decode_der2key.c:type_specific_keypair_der2rsa_does_selection
Unexecuted instantiation: decode_der2key.c:RSA_der2rsa_does_selection
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2rsapss_does_selection
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2rsapss_does_selection
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2ml_dsa_44_does_selection
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2ml_dsa_44_does_selection
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2ml_dsa_65_does_selection
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2ml_dsa_65_does_selection
Unexecuted instantiation: decode_der2key.c:PrivateKeyInfo_der2ml_dsa_87_does_selection
Unexecuted instantiation: decode_der2key.c:SubjectPublicKeyInfo_der2ml_dsa_87_does_selection
1264
    const OSSL_DISPATCH                                                                                               \
1265
        ossl_##kind##_der_to_##keytype##_decoder_functions[]                                                          \
1266
        = {                                                                                                           \
1267
              { OSSL_FUNC_DECODER_NEWCTX,                                                                             \
1268
                  (void (*)(void))kind##_der2##keytype##_newctx },                                                    \
1269
              { OSSL_FUNC_DECODER_FREECTX,                                                                            \
1270
                  (void (*)(void))der2key_freectx },                                                                  \
1271
              { OSSL_FUNC_DECODER_DOES_SELECTION,                                                                     \
1272
                  (void (*)(void))kind##_der2##keytype##_does_selection },                                            \
1273
              { OSSL_FUNC_DECODER_DECODE,                                                                             \
1274
                  (void (*)(void))der2key_decode },                                                                   \
1275
              { OSSL_FUNC_DECODER_EXPORT_OBJECT,                                                                      \
1276
                  (void (*)(void))der2key_export_object },                                                            \
1277
              { OSSL_FUNC_DECODER_SETTABLE_CTX_PARAMS,                                                                \
1278
                  (void (*)(void))der2key_settable_ctx_params },                                                      \
1279
              { OSSL_FUNC_DECODER_SET_CTX_PARAMS,                                                                     \
1280
                  (void (*)(void))der2key_set_ctx_params },                                                           \
1281
              OSSL_DISPATCH_END                                                                                       \
1282
          }
1283
1284
#ifndef OPENSSL_NO_DH
1285
MAKE_DECODER("DH", dh, dh, PrivateKeyInfo);
1286
MAKE_DECODER("DH", dh, dh, SubjectPublicKeyInfo);
1287
MAKE_DECODER("DH", dh, dh, type_specific_params);
1288
MAKE_DECODER("DH", dh, dh, DH);
1289
MAKE_DECODER("DHX", dhx, dhx, PrivateKeyInfo);
1290
MAKE_DECODER("DHX", dhx, dhx, SubjectPublicKeyInfo);
1291
MAKE_DECODER("DHX", dhx, dhx, type_specific_params);
1292
MAKE_DECODER("DHX", dhx, dhx, DHX);
1293
#endif
1294
#ifndef OPENSSL_NO_DSA
1295
MAKE_DECODER("DSA", dsa, dsa, PrivateKeyInfo);
1296
MAKE_DECODER("DSA", dsa, dsa, SubjectPublicKeyInfo);
1297
MAKE_DECODER("DSA", dsa, dsa, type_specific);
1298
MAKE_DECODER("DSA", dsa, dsa, DSA);
1299
#endif
1300
#ifndef OPENSSL_NO_EC
1301
MAKE_DECODER("EC", ec, ec, PrivateKeyInfo);
1302
MAKE_DECODER("EC", ec, ec, SubjectPublicKeyInfo);
1303
MAKE_DECODER("EC", ec, ec, type_specific_no_pub);
1304
MAKE_DECODER("EC", ec, ec, EC);
1305
#ifndef OPENSSL_NO_ECX
1306
MAKE_DECODER("X25519", x25519, ecx, PrivateKeyInfo);
1307
MAKE_DECODER("X25519", x25519, ecx, SubjectPublicKeyInfo);
1308
MAKE_DECODER("X448", x448, ecx, PrivateKeyInfo);
1309
MAKE_DECODER("X448", x448, ecx, SubjectPublicKeyInfo);
1310
MAKE_DECODER("ED25519", ed25519, ecx, PrivateKeyInfo);
1311
MAKE_DECODER("ED25519", ed25519, ecx, SubjectPublicKeyInfo);
1312
MAKE_DECODER("ED448", ed448, ecx, PrivateKeyInfo);
1313
MAKE_DECODER("ED448", ed448, ecx, SubjectPublicKeyInfo);
1314
#endif
1315
#ifndef OPENSSL_NO_SM2
1316
MAKE_DECODER("SM2", sm2, ec, PrivateKeyInfo);
1317
MAKE_DECODER("SM2", sm2, ec, SubjectPublicKeyInfo);
1318
MAKE_DECODER("SM2", sm2, sm2, type_specific_no_pub);
1319
#endif
1320
#endif
1321
#ifndef OPENSSL_NO_ML_KEM
1322
MAKE_DECODER("ML-KEM-512", ml_kem_512, ml_kem_512, PrivateKeyInfo);
1323
MAKE_DECODER("ML-KEM-512", ml_kem_512, ml_kem_512, SubjectPublicKeyInfo);
1324
MAKE_DECODER("ML-KEM-768", ml_kem_768, ml_kem_768, PrivateKeyInfo);
1325
MAKE_DECODER("ML-KEM-768", ml_kem_768, ml_kem_768, SubjectPublicKeyInfo);
1326
MAKE_DECODER("ML-KEM-1024", ml_kem_1024, ml_kem_1024, PrivateKeyInfo);
1327
MAKE_DECODER("ML-KEM-1024", ml_kem_1024, ml_kem_1024, SubjectPublicKeyInfo);
1328
#endif
1329
#ifndef OPENSSL_NO_SLH_DSA
1330
MAKE_DECODER("SLH-DSA-SHA2-128s", slh_dsa_sha2_128s, slh_dsa, PrivateKeyInfo);
1331
MAKE_DECODER("SLH-DSA-SHA2-128f", slh_dsa_sha2_128f, slh_dsa, PrivateKeyInfo);
1332
MAKE_DECODER("SLH-DSA-SHA2-192s", slh_dsa_sha2_192s, slh_dsa, PrivateKeyInfo);
1333
MAKE_DECODER("SLH-DSA-SHA2-192f", slh_dsa_sha2_192f, slh_dsa, PrivateKeyInfo);
1334
MAKE_DECODER("SLH-DSA-SHA2-256s", slh_dsa_sha2_256s, slh_dsa, PrivateKeyInfo);
1335
MAKE_DECODER("SLH-DSA-SHA2-256f", slh_dsa_sha2_256f, slh_dsa, PrivateKeyInfo);
1336
MAKE_DECODER("SLH-DSA-SHAKE-128s", slh_dsa_shake_128s, slh_dsa, PrivateKeyInfo);
1337
MAKE_DECODER("SLH-DSA-SHAKE-128f", slh_dsa_shake_128f, slh_dsa, PrivateKeyInfo);
1338
MAKE_DECODER("SLH-DSA-SHAKE-192s", slh_dsa_shake_192s, slh_dsa, PrivateKeyInfo);
1339
MAKE_DECODER("SLH-DSA-SHAKE-192f", slh_dsa_shake_192f, slh_dsa, PrivateKeyInfo);
1340
MAKE_DECODER("SLH-DSA-SHAKE-256s", slh_dsa_shake_256s, slh_dsa, PrivateKeyInfo);
1341
MAKE_DECODER("SLH-DSA-SHAKE-256f", slh_dsa_shake_256f, slh_dsa, PrivateKeyInfo);
1342
1343
MAKE_DECODER("SLH-DSA-SHA2-128s", slh_dsa_sha2_128s, slh_dsa, SubjectPublicKeyInfo);
1344
MAKE_DECODER("SLH-DSA-SHA2-128f", slh_dsa_sha2_128f, slh_dsa, SubjectPublicKeyInfo);
1345
MAKE_DECODER("SLH-DSA-SHA2-192s", slh_dsa_sha2_192s, slh_dsa, SubjectPublicKeyInfo);
1346
MAKE_DECODER("SLH-DSA-SHA2-192f", slh_dsa_sha2_192f, slh_dsa, SubjectPublicKeyInfo);
1347
MAKE_DECODER("SLH-DSA-SHA2-256s", slh_dsa_sha2_256s, slh_dsa, SubjectPublicKeyInfo);
1348
MAKE_DECODER("SLH-DSA-SHA2-256f", slh_dsa_sha2_256f, slh_dsa, SubjectPublicKeyInfo);
1349
MAKE_DECODER("SLH-DSA-SHAKE-128s", slh_dsa_shake_128s, slh_dsa, SubjectPublicKeyInfo);
1350
MAKE_DECODER("SLH-DSA-SHAKE-128f", slh_dsa_shake_128f, slh_dsa, SubjectPublicKeyInfo);
1351
MAKE_DECODER("SLH-DSA-SHAKE-192s", slh_dsa_shake_192s, slh_dsa, SubjectPublicKeyInfo);
1352
MAKE_DECODER("SLH-DSA-SHAKE-192f", slh_dsa_shake_192f, slh_dsa, SubjectPublicKeyInfo);
1353
MAKE_DECODER("SLH-DSA-SHAKE-256s", slh_dsa_shake_256s, slh_dsa, SubjectPublicKeyInfo);
1354
MAKE_DECODER("SLH-DSA-SHAKE-256f", slh_dsa_shake_256f, slh_dsa, SubjectPublicKeyInfo);
1355
#endif /* OPENSSL_NO_SLH_DSA */
1356
MAKE_DECODER("RSA", rsa, rsa, PrivateKeyInfo);
1357
MAKE_DECODER("RSA", rsa, rsa, SubjectPublicKeyInfo);
1358
MAKE_DECODER("RSA", rsa, rsa, type_specific_keypair);
1359
MAKE_DECODER("RSA", rsa, rsa, RSA);
1360
MAKE_DECODER("RSA-PSS", rsapss, rsapss, PrivateKeyInfo);
1361
MAKE_DECODER("RSA-PSS", rsapss, rsapss, SubjectPublicKeyInfo);
1362
1363
#ifndef OPENSSL_NO_ML_DSA
1364
MAKE_DECODER("ML-DSA-44", ml_dsa_44, ml_dsa_44, PrivateKeyInfo);
1365
MAKE_DECODER("ML-DSA-44", ml_dsa_44, ml_dsa_44, SubjectPublicKeyInfo);
1366
MAKE_DECODER("ML-DSA-65", ml_dsa_65, ml_dsa_65, PrivateKeyInfo);
1367
MAKE_DECODER("ML-DSA-65", ml_dsa_65, ml_dsa_65, SubjectPublicKeyInfo);
1368
MAKE_DECODER("ML-DSA-87", ml_dsa_87, ml_dsa_87, PrivateKeyInfo);
1369
MAKE_DECODER("ML-DSA-87", ml_dsa_87, ml_dsa_87, SubjectPublicKeyInfo);
1370
#endif
1371
1372
#ifndef OPENSSL_NO_LMS
1373
MAKE_DECODER("LMS", lms, lms, SubjectPublicKeyInfo);
1374
#endif