Coverage Report

Created: 2025-12-10 06:24

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl/providers/implementations/keymgmt/ml_dsa_kmgmt.c
Line
Count
Source
1
/*
2
 * Copyright 2024-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
#include <openssl/core_dispatch.h>
11
#include <openssl/core_names.h>
12
#include <openssl/evp.h>
13
#include <openssl/param_build.h>
14
#include <openssl/proverr.h>
15
#include <openssl/self_test.h>
16
#include "crypto/ml_dsa.h"
17
#include "internal/fips.h"
18
#include "internal/param_build_set.h"
19
#include "prov/implementations.h"
20
#include "prov/providercommon.h"
21
#include "prov/provider_ctx.h"
22
#include "prov/ml_dsa.h"
23
#include "providers/implementations/keymgmt/ml_dsa_kmgmt.inc"
24
25
static OSSL_FUNC_keymgmt_free_fn ml_dsa_free_key;
26
static OSSL_FUNC_keymgmt_has_fn ml_dsa_has;
27
static OSSL_FUNC_keymgmt_match_fn ml_dsa_match;
28
static OSSL_FUNC_keymgmt_import_fn ml_dsa_import;
29
static OSSL_FUNC_keymgmt_export_fn ml_dsa_export;
30
static OSSL_FUNC_keymgmt_import_types_fn ml_dsa_imexport_types;
31
static OSSL_FUNC_keymgmt_export_types_fn ml_dsa_imexport_types;
32
static OSSL_FUNC_keymgmt_dup_fn ml_dsa_dup_key;
33
static OSSL_FUNC_keymgmt_gettable_params_fn ml_dsa_gettable_params;
34
static OSSL_FUNC_keymgmt_validate_fn ml_dsa_validate;
35
static OSSL_FUNC_keymgmt_gen_init_fn ml_dsa_gen_init;
36
static OSSL_FUNC_keymgmt_gen_cleanup_fn ml_dsa_gen_cleanup;
37
static OSSL_FUNC_keymgmt_gen_set_params_fn ml_dsa_gen_set_params;
38
static OSSL_FUNC_keymgmt_gen_settable_params_fn ml_dsa_gen_settable_params;
39
#ifndef FIPS_MODULE
40
static OSSL_FUNC_keymgmt_load_fn ml_dsa_load;
41
#endif
42
43
struct ml_dsa_gen_ctx {
44
    PROV_CTX *provctx;
45
    char *propq;
46
    uint8_t entropy[32];
47
    size_t entropy_len;
48
};
49
50
#ifdef FIPS_MODULE
51
static int ml_dsa_pairwise_test(const ML_DSA_KEY *key)
52
{
53
    OSSL_SELF_TEST *st = NULL;
54
    OSSL_CALLBACK *cb = NULL;
55
    OSSL_LIB_CTX *ctx;
56
    void *cbarg = NULL;
57
    static const uint8_t msg[] = { 80, 108, 117, 103, 104 };
58
    uint8_t rnd[ML_DSA_ENTROPY_LEN];
59
    uint8_t sig[ML_DSA_87_SIG_LEN];
60
    size_t sig_len = 0;
61
    int ret = 0;
62
63
    if (!ml_dsa_has(key, OSSL_KEYMGMT_SELECT_KEYPAIR)
64
        || ossl_fips_self_testing())
65
        return 1;
66
67
    /*
68
     * The functions `OSSL_SELF_TEST_*` will return directly if parameter `st`
69
     * is NULL.
70
     */
71
    ctx = ossl_ml_dsa_key_get0_libctx(key);
72
    OSSL_SELF_TEST_get_callback(ctx, &cb, &cbarg);
73
74
    if ((st = OSSL_SELF_TEST_new(cb, cbarg)) == NULL)
75
        return 0;
76
77
    OSSL_SELF_TEST_onbegin(st, OSSL_SELF_TEST_TYPE_PCT,
78
        OSSL_SELF_TEST_DESC_PCT_ML_DSA);
79
80
    memset(rnd, 0, sizeof(rnd));
81
    memset(sig, 0, sizeof(sig));
82
83
    if (ossl_ml_dsa_sign(key, 0, msg, sizeof(msg), NULL, 0, rnd, sizeof(rnd), 0,
84
            sig, &sig_len, sizeof(sig))
85
        <= 0)
86
        goto err;
87
88
    OSSL_SELF_TEST_oncorrupt_byte(st, sig);
89
90
    if (ossl_ml_dsa_verify(key, 0, msg, sizeof(msg), NULL, 0, 0,
91
            sig, sig_len)
92
        <= 0)
93
        goto err;
94
95
    ret = 1;
96
err:
97
    OSSL_SELF_TEST_onend(st, ret);
98
    OSSL_SELF_TEST_free(st);
99
    return ret;
100
}
101
#endif
102
103
ML_DSA_KEY *ossl_prov_ml_dsa_new(PROV_CTX *ctx, const char *propq, int evp_type)
104
0
{
105
0
    ML_DSA_KEY *key;
106
107
0
    if (!ossl_prov_is_running())
108
0
        return 0;
109
110
0
    key = ossl_ml_dsa_key_new(PROV_LIBCTX_OF(ctx), propq, evp_type);
111
    /*
112
     * When decoding, if the key ends up "loaded" into the same provider, these
113
     * are the correct config settings, otherwise, new values will be assigned
114
     * on import into a different provider.  The "load" API does not pass along
115
     * the provider context.
116
     */
117
0
    if (key != NULL) {
118
0
        int flags_set = 0, flags_clr = 0;
119
120
0
        if (ossl_prov_ctx_get_bool_param(
121
0
                ctx, OSSL_PKEY_PARAM_ML_DSA_RETAIN_SEED, 1))
122
0
            flags_set |= ML_DSA_KEY_RETAIN_SEED;
123
0
        else
124
0
            flags_clr = ML_DSA_KEY_RETAIN_SEED;
125
126
0
        if (ossl_prov_ctx_get_bool_param(
127
0
                ctx, OSSL_PKEY_PARAM_ML_DSA_PREFER_SEED, 1))
128
0
            flags_set |= ML_DSA_KEY_PREFER_SEED;
129
0
        else
130
0
            flags_clr |= ML_DSA_KEY_PREFER_SEED;
131
132
0
        ossl_ml_dsa_set_prekey(key, flags_set, flags_clr, NULL, 0, NULL, 0);
133
0
    }
134
0
    return key;
135
0
}
136
137
static void ml_dsa_free_key(void *keydata)
138
0
{
139
0
    ossl_ml_dsa_key_free((ML_DSA_KEY *)keydata);
140
0
}
141
142
static void *ml_dsa_dup_key(const void *keydata_from, int selection)
143
0
{
144
0
    if (ossl_prov_is_running())
145
0
        return ossl_ml_dsa_key_dup(keydata_from, selection);
146
0
    return NULL;
147
0
}
148
149
static int ml_dsa_has(const void *keydata, int selection)
150
0
{
151
0
    const ML_DSA_KEY *key = keydata;
152
153
0
    if (!ossl_prov_is_running() || key == NULL)
154
0
        return 0;
155
0
    if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) == 0)
156
0
        return 1; /* the selection is not missing */
157
158
0
    return ossl_ml_dsa_key_has(key, selection);
159
0
}
160
161
static int ml_dsa_match(const void *keydata1, const void *keydata2, int selection)
162
0
{
163
0
    const ML_DSA_KEY *key1 = keydata1;
164
0
    const ML_DSA_KEY *key2 = keydata2;
165
166
0
    if (!ossl_prov_is_running())
167
0
        return 0;
168
0
    if (key1 == NULL || key2 == NULL)
169
0
        return 0;
170
0
    return ossl_ml_dsa_key_equal(key1, key2, selection);
171
0
}
172
173
static int ml_dsa_validate(const void *key_data, int selection, int check_type)
174
0
{
175
0
    const ML_DSA_KEY *key = key_data;
176
177
0
    if (!ml_dsa_has(key, selection))
178
0
        return 0;
179
180
0
    if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) == OSSL_KEYMGMT_SELECT_KEYPAIR)
181
0
        return ossl_ml_dsa_key_pairwise_check(key);
182
0
    return 1;
183
0
}
184
185
/**
186
 * @brief Load a ML_DSA key from raw data.
187
 *
188
 * @param key An ML_DSA key to load into
189
 * @param params An array of parameters containing key data.
190
 * @param include_private Set to 1 to optionally include the private key data
191
 *                        if it exists.
192
 * @returns 1 on success, or 0 on failure.
193
 */
194
static int ml_dsa_key_fromdata(ML_DSA_KEY *key, const OSSL_PARAM params[],
195
    int include_private)
196
0
{
197
0
    const ML_DSA_PARAMS *key_params = ossl_ml_dsa_key_params(key);
198
0
    const uint8_t *pk = NULL, *sk = NULL, *seed = NULL;
199
0
    size_t pk_len = 0, sk_len = 0, seed_len = 0;
200
0
    struct ml_dsa_key_type_params_st p;
201
202
0
    if (!ml_dsa_key_type_params_decoder(params, &p))
203
0
        return 0;
204
205
0
    if (p.pubkey != NULL) {
206
0
        if (!OSSL_PARAM_get_octet_string_ptr(p.pubkey, (const void **)&pk, &pk_len))
207
0
            return 0;
208
0
        if (pk != NULL && pk_len != key_params->pk_len) {
209
0
            ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_KEY_LENGTH,
210
0
                "Invalid %s public key length", key_params->alg);
211
0
            return 0;
212
0
        }
213
0
    }
214
215
    /* Private key seed is optional */
216
0
    if (p.seed != NULL && include_private) {
217
0
        if (!OSSL_PARAM_get_octet_string_ptr(p.seed, (const void **)&seed,
218
0
                &seed_len))
219
0
            return 0;
220
0
        if (seed != NULL && seed_len != ML_DSA_SEED_BYTES) {
221
0
            ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_SEED_LENGTH);
222
0
            return 0;
223
0
        }
224
0
    }
225
226
    /* Private key is optional */
227
0
    if (p.privkey != NULL && include_private) {
228
0
        if (!OSSL_PARAM_get_octet_string_ptr(p.privkey, (const void **)&sk,
229
0
                &sk_len))
230
0
            return 0;
231
0
        if (sk != NULL && sk_len != key_params->sk_len) {
232
0
            ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_KEY_LENGTH,
233
0
                "Invalid %s private key length",
234
0
                key_params->alg);
235
0
            return 0;
236
0
        }
237
0
    }
238
239
    /* The caller MUST specify at least one of seed, private or public keys. */
240
0
    if (seed_len == 0 && pk_len == 0 && sk_len == 0) {
241
0
        ERR_raise(ERR_LIB_PROV, PROV_R_MISSING_KEY);
242
0
        return 0;
243
0
    }
244
245
0
    if (seed_len != 0
246
0
        && (sk_len == 0
247
0
            || (ossl_ml_dsa_key_get_prov_flags(key) & ML_DSA_KEY_PREFER_SEED))) {
248
0
        if (!ossl_ml_dsa_set_prekey(key, 0, 0, seed, seed_len, sk, sk_len))
249
0
            return 0;
250
0
        if (!ossl_ml_dsa_generate_key(key)) {
251
0
            ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GENERATE_KEY);
252
0
            return 0;
253
0
        }
254
0
    } else if (sk_len > 0) {
255
0
        if (!ossl_ml_dsa_sk_decode(key, sk, sk_len))
256
0
            return 0;
257
0
    } else if (pk_len > 0) {
258
0
        if (!ossl_ml_dsa_pk_decode(key, pk, pk_len))
259
0
            return 0;
260
0
    }
261
262
    /* Error if the supplied public key does not match the generated key */
263
0
    if (pk_len == 0
264
0
        || seed_len + sk_len == 0
265
0
        || memcmp(ossl_ml_dsa_key_get_pub(key), pk, pk_len) == 0)
266
0
        return 1;
267
0
    ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_KEY,
268
0
        "explicit %s public key does not match private",
269
0
        key_params->alg);
270
0
    ossl_ml_dsa_key_reset(key);
271
0
    return 0;
272
0
}
273
274
static int ml_dsa_import(void *keydata, int selection, const OSSL_PARAM params[])
275
0
{
276
0
    ML_DSA_KEY *key = keydata;
277
0
    int include_priv;
278
0
    int res;
279
280
0
    if (!ossl_prov_is_running() || key == NULL)
281
0
        return 0;
282
283
0
    if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) == 0)
284
0
        return 0;
285
286
0
    include_priv = ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0);
287
0
    res = ml_dsa_key_fromdata(key, params, include_priv);
288
#ifdef FIPS_MODULE
289
    if (res > 0) {
290
        res = ml_dsa_pairwise_test(key);
291
        if (!res) {
292
            ossl_ml_dsa_key_reset(key);
293
            ossl_set_error_state(OSSL_SELF_TEST_TYPE_PCT_IMPORT);
294
        }
295
    }
296
#endif /* FIPS_MODULE */
297
0
    return res;
298
0
}
299
300
static const OSSL_PARAM *ml_dsa_imexport_types(int selection)
301
0
{
302
0
    if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) == 0)
303
0
        return NULL;
304
0
    return ml_dsa_key_type_params_list;
305
0
}
306
307
static const OSSL_PARAM *ml_dsa_gettable_params(void *provctx)
308
0
{
309
0
    return ml_dsa_get_params_list;
310
0
}
311
312
static int ml_dsa_get_params(void *keydata, OSSL_PARAM params[])
313
0
{
314
0
    ML_DSA_KEY *key = keydata;
315
0
    const uint8_t *d;
316
0
    size_t len;
317
0
    struct ml_dsa_get_params_st p;
318
319
0
    if (key == NULL || !ml_dsa_get_params_decoder(params, &p))
320
0
        return 0;
321
322
0
    if (p.bits != NULL
323
0
        && !OSSL_PARAM_set_size_t(p.bits, 8 * ossl_ml_dsa_key_get_pub_len(key)))
324
0
        return 0;
325
326
0
    if (p.secbits != NULL
327
0
        && !OSSL_PARAM_set_size_t(p.secbits, ossl_ml_dsa_key_get_collision_strength_bits(key)))
328
0
        return 0;
329
330
0
    if (p.maxsize != NULL
331
0
        && !OSSL_PARAM_set_size_t(p.maxsize, ossl_ml_dsa_key_get_sig_len(key)))
332
0
        return 0;
333
334
0
    if (p.seccat != NULL
335
0
        && !OSSL_PARAM_set_int(p.seccat, ossl_ml_dsa_key_get_security_category(key)))
336
0
        return 0;
337
338
0
    if (p.seed != NULL) {
339
0
        d = ossl_ml_dsa_key_get_seed(key);
340
0
        if (d != NULL && !OSSL_PARAM_set_octet_string(p.seed, d, ML_DSA_SEED_BYTES))
341
0
            return 0;
342
0
    }
343
344
0
    if (p.privkey != NULL) {
345
0
        d = ossl_ml_dsa_key_get_priv(key);
346
0
        if (d != NULL) {
347
0
            len = ossl_ml_dsa_key_get_priv_len(key);
348
0
            if (!OSSL_PARAM_set_octet_string(p.privkey, d, len))
349
0
                return 0;
350
0
        }
351
0
    }
352
353
0
    if (p.pubkey != NULL) {
354
0
        d = ossl_ml_dsa_key_get_pub(key);
355
0
        if (d != NULL) {
356
0
            len = ossl_ml_dsa_key_get_pub_len(key);
357
0
            if (!OSSL_PARAM_set_octet_string(p.pubkey, d, len))
358
0
                return 0;
359
0
        }
360
0
    }
361
362
    /*
363
     * This allows apps to use an empty digest, so that the old API
364
     * for digest signing can be used.
365
     */
366
0
    if (p.dgstp != NULL && !OSSL_PARAM_set_utf8_string(p.dgstp, ""))
367
0
        return 0;
368
0
    return 1;
369
0
}
370
371
static int ml_dsa_export(void *keydata, int selection,
372
    OSSL_CALLBACK *param_cb, void *cbarg)
373
0
{
374
0
    ML_DSA_KEY *key = keydata;
375
0
    OSSL_PARAM params[4];
376
0
    const uint8_t *buf;
377
0
    int include_private, pnum = 0;
378
379
0
    if (!ossl_prov_is_running() || key == NULL)
380
0
        return 0;
381
382
0
    if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) == 0)
383
0
        return 0;
384
385
0
    include_private = ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0);
386
387
    /*
388
     * Note that if the seed is present, both the seed and the private key are
389
     * exported.  The recipient will have a choice.
390
     */
391
0
    if (include_private) {
392
0
        if ((buf = ossl_ml_dsa_key_get_seed(key)) != NULL) {
393
0
            params[pnum++] = OSSL_PARAM_construct_octet_string(OSSL_PKEY_PARAM_ML_DSA_SEED, (void *)buf, ML_DSA_SEED_BYTES);
394
0
        }
395
0
        if ((buf = ossl_ml_dsa_key_get_priv(key)) != NULL) {
396
0
            params[pnum++] = OSSL_PARAM_construct_octet_string(OSSL_PKEY_PARAM_PRIV_KEY, (void *)buf,
397
0
                ossl_ml_dsa_key_get_priv_len(key));
398
0
        }
399
0
    }
400
0
    if (((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0)
401
0
        && ((buf = ossl_ml_dsa_key_get_pub(key)) != NULL)) {
402
0
        params[pnum++] = OSSL_PARAM_construct_octet_string(OSSL_PKEY_PARAM_PUB_KEY, (void *)buf,
403
0
            ossl_ml_dsa_key_get_pub_len(key));
404
0
    }
405
0
    if (pnum == 0)
406
0
        return 0;
407
0
    params[pnum] = OSSL_PARAM_construct_end();
408
0
    return param_cb(params, cbarg);
409
0
}
410
411
#ifndef FIPS_MODULE
412
static void *ml_dsa_load(const void *reference, size_t reference_sz)
413
0
{
414
0
    ML_DSA_KEY *key = NULL;
415
0
    const ML_DSA_PARAMS *key_params;
416
0
    const uint8_t *sk, *seed;
417
418
0
    if (ossl_prov_is_running() && reference_sz == sizeof(key)) {
419
        /* The contents of the reference is the address to our object */
420
0
        key = *(ML_DSA_KEY **)reference;
421
        /* We grabbed, so we detach it */
422
0
        *(ML_DSA_KEY **)reference = NULL;
423
        /* All done, if the pubkey is present. */
424
0
        if (key == NULL || ossl_ml_dsa_key_get_pub(key) != NULL)
425
0
            return key;
426
        /* Handle private prekey inputs. */
427
0
        sk = ossl_ml_dsa_key_get_priv(key);
428
0
        seed = ossl_ml_dsa_key_get_seed(key);
429
0
        if (seed != NULL
430
0
            && (sk == NULL || (ossl_ml_dsa_key_get_prov_flags(key) & ML_DSA_KEY_PREFER_SEED))) {
431
0
            if (ossl_ml_dsa_generate_key(key))
432
0
                return key;
433
0
        } else if (sk != NULL) {
434
0
            if (ossl_ml_dsa_sk_decode(key, sk,
435
0
                    ossl_ml_dsa_key_get_priv_len(key)))
436
0
                return key;
437
0
            key_params = ossl_ml_dsa_key_params(key);
438
0
            ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_KEY,
439
0
                "error parsing %s private key",
440
0
                key_params->alg);
441
0
        } else {
442
0
            return key;
443
0
        }
444
0
    }
445
446
0
    ossl_ml_dsa_key_free(key);
447
0
    return NULL;
448
0
}
449
#endif
450
451
static void *ml_dsa_gen_init(void *provctx, int selection,
452
    const OSSL_PARAM params[])
453
0
{
454
0
    struct ml_dsa_gen_ctx *gctx = NULL;
455
456
0
    if (!ossl_prov_is_running())
457
0
        return NULL;
458
459
0
    if ((gctx = OPENSSL_zalloc(sizeof(*gctx))) != NULL) {
460
0
        gctx->provctx = provctx;
461
0
        if (!ml_dsa_gen_set_params(gctx, params)) {
462
0
            OPENSSL_free(gctx);
463
0
            gctx = NULL;
464
0
        }
465
0
    }
466
0
    return gctx;
467
0
}
468
469
static void *ml_dsa_gen(void *genctx, int evp_type)
470
0
{
471
0
    struct ml_dsa_gen_ctx *gctx = genctx;
472
0
    ML_DSA_KEY *key = NULL;
473
474
0
    if (!ossl_prov_is_running())
475
0
        return NULL;
476
0
    key = ossl_prov_ml_dsa_new(gctx->provctx, gctx->propq, evp_type);
477
0
    if (key == NULL)
478
0
        return NULL;
479
0
    if (gctx->entropy_len != 0
480
0
        && !ossl_ml_dsa_set_prekey(key, 0, 0,
481
0
            gctx->entropy, gctx->entropy_len, NULL, 0))
482
0
        goto err;
483
0
    if (!ossl_ml_dsa_generate_key(key)) {
484
0
        ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GENERATE_KEY);
485
0
        goto err;
486
0
    }
487
#ifdef FIPS_MODULE
488
    if (!ml_dsa_pairwise_test(key)) {
489
        ossl_set_error_state(OSSL_SELF_TEST_TYPE_PCT);
490
        goto err;
491
    }
492
#endif
493
0
    return key;
494
0
err:
495
0
    ossl_ml_dsa_key_free(key);
496
0
    return NULL;
497
0
}
498
499
static int ml_dsa_gen_set_params(void *genctx, const OSSL_PARAM params[])
500
0
{
501
0
    struct ml_dsa_gen_ctx *gctx = genctx;
502
0
    struct ml_dsa_gen_set_params_st p;
503
504
0
    if (gctx == NULL || !ml_dsa_gen_set_params_decoder(params, &p))
505
0
        return 0;
506
507
0
    if (p.seed != NULL) {
508
0
        void *vp = gctx->entropy;
509
0
        size_t len = sizeof(gctx->entropy);
510
511
0
        if (!OSSL_PARAM_get_octet_string(p.seed, &vp, len, &(gctx->entropy_len))) {
512
0
            gctx->entropy_len = 0;
513
0
            return 0;
514
0
        }
515
0
    }
516
517
0
    if (p.propq != NULL) {
518
0
        OPENSSL_free(gctx->propq);
519
0
        gctx->propq = NULL;
520
0
        if (!OSSL_PARAM_get_utf8_string(p.propq, &gctx->propq, 0))
521
0
            return 0;
522
0
    }
523
0
    return 1;
524
0
}
525
526
static const OSSL_PARAM *ml_dsa_gen_settable_params(ossl_unused void *genctx,
527
    ossl_unused void *provctx)
528
0
{
529
0
    return ml_dsa_gen_set_params_list;
530
0
}
531
532
static void ml_dsa_gen_cleanup(void *genctx)
533
0
{
534
0
    struct ml_dsa_gen_ctx *gctx = genctx;
535
536
0
    if (gctx == NULL)
537
0
        return;
538
539
0
    OPENSSL_cleanse(gctx->entropy, gctx->entropy_len);
540
0
    OPENSSL_free(gctx->propq);
541
0
    OPENSSL_free(gctx);
542
0
}
543
544
#ifndef FIPS_MODULE
545
#define DISPATCH_LOAD_FN \
546
    { OSSL_FUNC_KEYMGMT_LOAD, (OSSL_FUNC)ml_dsa_load },
547
#else
548
#define DISPATCH_LOAD_FN /* Non-FIPS only */
549
#endif
550
551
#define MAKE_KEYMGMT_FUNCTIONS(alg)                                                           \
552
    static OSSL_FUNC_keymgmt_new_fn ml_dsa_##alg##_new_key;                                   \
553
    static OSSL_FUNC_keymgmt_gen_fn ml_dsa_##alg##_gen;                                       \
554
    static void *ml_dsa_##alg##_new_key(void *provctx)                                        \
555
0
    {                                                                                         \
556
0
        return ossl_prov_ml_dsa_new(provctx, NULL, EVP_PKEY_ML_DSA_##alg);                    \
557
0
    }                                                                                         \
558
    static void *ml_dsa_##alg##_gen(void *genctx, OSSL_CALLBACK *osslcb, void *cbarg)         \
559
0
    {                                                                                         \
560
0
        return ml_dsa_gen(genctx, EVP_PKEY_ML_DSA_##alg);                                     \
561
0
    }                                                                                         \
Unexecuted instantiation: ml_dsa_kmgmt.c:ml_dsa_44_gen
Unexecuted instantiation: ml_dsa_kmgmt.c:ml_dsa_65_gen
Unexecuted instantiation: ml_dsa_kmgmt.c:ml_dsa_87_gen
562
    const OSSL_DISPATCH ossl_ml_dsa_##alg##_keymgmt_functions[] = {                           \
563
        { OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))ml_dsa_##alg##_new_key },                    \
564
        { OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))ml_dsa_free_key },                          \
565
        { OSSL_FUNC_KEYMGMT_HAS, (void (*)(void))ml_dsa_has },                                \
566
        { OSSL_FUNC_KEYMGMT_MATCH, (void (*)(void))ml_dsa_match },                            \
567
        { OSSL_FUNC_KEYMGMT_IMPORT, (void (*)(void))ml_dsa_import },                          \
568
        { OSSL_FUNC_KEYMGMT_IMPORT_TYPES, (void (*)(void))ml_dsa_imexport_types },            \
569
        { OSSL_FUNC_KEYMGMT_EXPORT, (void (*)(void))ml_dsa_export },                          \
570
        { OSSL_FUNC_KEYMGMT_EXPORT_TYPES, (void (*)(void))ml_dsa_imexport_types },            \
571
        DISPATCH_LOAD_FN { OSSL_FUNC_KEYMGMT_GET_PARAMS, (void (*)(void))ml_dsa_get_params }, \
572
        { OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS, (void (*)(void))ml_dsa_gettable_params },        \
573
        { OSSL_FUNC_KEYMGMT_VALIDATE, (void (*)(void))ml_dsa_validate },                      \
574
        { OSSL_FUNC_KEYMGMT_GEN_INIT, (void (*)(void))ml_dsa_gen_init },                      \
575
        { OSSL_FUNC_KEYMGMT_GEN, (void (*)(void))ml_dsa_##alg##_gen },                        \
576
        { OSSL_FUNC_KEYMGMT_GEN_CLEANUP, (void (*)(void))ml_dsa_gen_cleanup },                \
577
        { OSSL_FUNC_KEYMGMT_GEN_SET_PARAMS,                                                   \
578
            (void (*)(void))ml_dsa_gen_set_params },                                          \
579
        { OSSL_FUNC_KEYMGMT_GEN_SETTABLE_PARAMS,                                              \
580
            (void (*)(void))ml_dsa_gen_settable_params },                                     \
581
        { OSSL_FUNC_KEYMGMT_DUP, (void (*)(void))ml_dsa_dup_key },                            \
582
        OSSL_DISPATCH_END                                                                     \
583
    }
584
585
0
MAKE_KEYMGMT_FUNCTIONS(44);
586
0
MAKE_KEYMGMT_FUNCTIONS(65);
587
MAKE_KEYMGMT_FUNCTIONS(87);