Coverage Report

Created: 2025-12-10 06:24

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