Coverage Report

Created: 2026-01-09 07:00

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