Coverage Report

Created: 2025-08-28 06:41

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