Coverage Report

Created: 2026-09-12 06:55

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl35/crypto/ml_dsa/ml_dsa_key.c
Line
Count
Source
1
/*
2
 * Copyright 2024-2026 The OpenSSL Project Authors. All Rights Reserved.
3
 *
4
 * Licensed under the Apache License 2.0 (the "License").  You may not use
5
 * this file except in compliance with the License.  You can obtain a copy
6
 * in the file LICENSE in the source distribution or at
7
 * https://www.openssl.org/source/license.html
8
 */
9
10
#include <openssl/core_dispatch.h>
11
#include <openssl/core_names.h>
12
#include <openssl/err.h>
13
#include <openssl/params.h>
14
#include <openssl/proverr.h>
15
#include <openssl/rand.h>
16
#include "ml_dsa_key.h"
17
#include "ml_dsa_matrix.h"
18
#include "ml_dsa_hash.h"
19
#include "internal/encoder.h"
20
21
const ML_DSA_PARAMS *ossl_ml_dsa_key_params(const ML_DSA_KEY *key)
22
677
{
23
677
    return key->params;
24
677
}
25
26
/* Returns the seed data or NULL if there is no seed */
27
const uint8_t *ossl_ml_dsa_key_get_seed(const ML_DSA_KEY *key)
28
1.56k
{
29
1.56k
    return key->seed;
30
1.56k
}
31
32
int ossl_ml_dsa_key_get_prov_flags(const ML_DSA_KEY *key)
33
47
{
34
47
    return key->prov_flags;
35
47
}
36
37
int ossl_ml_dsa_set_prekey(ML_DSA_KEY *key, int flags_set, int flags_clr,
38
    const uint8_t *seed, size_t seed_len,
39
    const uint8_t *sk, size_t sk_len)
40
747
{
41
747
    int ret = 0;
42
43
747
    if (key == NULL
44
747
        || key->pub_encoding != NULL
45
747
        || key->priv_encoding != NULL
46
747
        || (sk != NULL && sk_len != key->params->sk_len)
47
747
        || (seed != NULL && seed_len != ML_DSA_SEED_BYTES)
48
747
        || key->seed != NULL)
49
0
        return 0;
50
51
747
    if (sk != NULL
52
30
        && (key->priv_encoding = OPENSSL_memdup(sk, sk_len)) == NULL)
53
0
        goto end;
54
747
    if (seed != NULL
55
92
        && (key->seed = OPENSSL_memdup(seed, seed_len)) == NULL)
56
0
        goto end;
57
747
    key->prov_flags |= flags_set;
58
747
    key->prov_flags &= ~flags_clr;
59
747
    ret = 1;
60
61
747
end:
62
747
    if (!ret) {
63
0
        OPENSSL_free(key->priv_encoding);
64
0
        OPENSSL_free(key->seed);
65
0
        key->priv_encoding = key->seed = NULL;
66
0
    }
67
747
    return ret;
68
747
}
69
70
/**
71
 * @brief Create a new ML_DSA_KEY object
72
 *
73
 * @param libctx A OSSL_LIB_CTX object used for fetching algorithms.
74
 * @param propq The property query used for fetching algorithms
75
 * @param alg The algorithm name associated with the key type
76
 * @returns The new ML_DSA_KEY object on success, or NULL on malloc failure
77
 */
78
ML_DSA_KEY *ossl_ml_dsa_key_new(OSSL_LIB_CTX *libctx, const char *propq,
79
    int evp_type)
80
1.66k
{
81
1.66k
    ML_DSA_KEY *ret;
82
1.66k
    const ML_DSA_PARAMS *params = ossl_ml_dsa_params_get(evp_type);
83
84
1.66k
    if (params == NULL)
85
0
        return NULL;
86
87
1.66k
    ret = OPENSSL_zalloc(sizeof(*ret));
88
1.66k
    if (ret != NULL) {
89
1.66k
        ret->libctx = libctx;
90
1.66k
        ret->params = params;
91
1.66k
        ret->prov_flags = ML_DSA_KEY_PROV_FLAGS_DEFAULT;
92
1.66k
        ret->shake128_md = EVP_MD_fetch(libctx, "SHAKE-128", propq);
93
1.66k
        ret->shake256_md = EVP_MD_fetch(libctx, "SHAKE-256", propq);
94
1.66k
        if (ret->shake128_md == NULL || ret->shake256_md == NULL)
95
0
            goto err;
96
1.66k
    }
97
1.66k
    return ret;
98
0
err:
99
0
    ossl_ml_dsa_key_free(ret);
100
0
    return NULL;
101
1.66k
}
102
103
int ossl_ml_dsa_key_pub_alloc(ML_DSA_KEY *key)
104
2.34k
{
105
2.34k
    if (key->t1.poly != NULL)
106
0
        return 0;
107
2.34k
    return vector_alloc(&key->t1, key->params->k);
108
2.34k
}
109
110
int ossl_ml_dsa_key_priv_alloc(ML_DSA_KEY *key)
111
2.34k
{
112
2.34k
    size_t k = key->params->k, l = key->params->l;
113
2.34k
    POLY *poly;
114
115
2.34k
    if (key->s1.poly != NULL)
116
0
        return 0;
117
2.34k
    if (!vector_alloc(&key->s1, l + 2 * k))
118
0
        return 0;
119
120
2.34k
    poly = key->s1.poly;
121
2.34k
    key->s1.num_poly = l;
122
2.34k
    vector_init(&key->s2, poly + l, k);
123
2.34k
    vector_init(&key->t0, poly + l + k, k);
124
2.34k
    return 1;
125
2.34k
}
126
127
/**
128
 * @brief Destroy an ML_DSA_KEY object
129
 */
130
void ossl_ml_dsa_key_free(ML_DSA_KEY *key)
131
210k
{
132
210k
    if (key == NULL)
133
207k
        return;
134
135
2.48k
    EVP_MD_free(key->shake128_md);
136
2.48k
    EVP_MD_free(key->shake256_md);
137
2.48k
    ossl_ml_dsa_key_reset(key);
138
2.48k
    OPENSSL_free(key);
139
2.48k
}
140
141
/**
142
 * @brief Factory reset an ML_DSA_KEY object
143
 */
144
void ossl_ml_dsa_key_reset(ML_DSA_KEY *key)
145
2.48k
{
146
    /*
147
     * The allocation for |s1.poly| subsumes those for |s2| and |t0|, which we
148
     * must not access after |s1|'s poly is freed.
149
     */
150
2.48k
    if (key->s1.poly != NULL) {
151
2.34k
        vector_zero(&key->s1);
152
2.34k
        vector_zero(&key->s2);
153
2.34k
        vector_zero(&key->t0);
154
2.34k
        vector_free(&key->s1);
155
2.34k
        key->s2.poly = NULL;
156
2.34k
        key->t0.poly = NULL;
157
2.34k
    }
158
    /* The |t1| vector is public and allocated separately */
159
2.48k
    vector_free(&key->t1);
160
2.48k
    OPENSSL_cleanse(key->K, sizeof(key->K));
161
2.48k
    OPENSSL_free(key->pub_encoding);
162
2.48k
    key->pub_encoding = NULL;
163
2.48k
    if (key->priv_encoding != NULL)
164
2.29k
        OPENSSL_clear_free(key->priv_encoding, key->params->sk_len);
165
2.48k
    key->priv_encoding = NULL;
166
2.48k
    if (key->seed != NULL)
167
2.26k
        OPENSSL_clear_free(key->seed, ML_DSA_SEED_BYTES);
168
2.48k
    key->seed = NULL;
169
2.48k
}
170
171
/**
172
 * @brief Duplicate a key
173
 *
174
 * @param src A ML_DSA_KEY object to copy
175
 * @param selection to select public and/or private components. Selecting the
176
 *                  private key will also select the public key
177
 * @returns The duplicated key, or NULL on failure.
178
 */
179
ML_DSA_KEY *ossl_ml_dsa_key_dup(const ML_DSA_KEY *src, int selection)
180
48
{
181
48
    ML_DSA_KEY *ret = NULL;
182
183
48
    if (src == NULL)
184
0
        return NULL;
185
186
    /* Prekeys with just a seed or private key are not dupable */
187
48
    if (src->pub_encoding == NULL
188
0
        && (src->priv_encoding != NULL || src->seed != NULL))
189
0
        return NULL;
190
191
48
    ret = OPENSSL_zalloc(sizeof(*ret));
192
48
    if (ret != NULL) {
193
48
        ret->libctx = src->libctx;
194
48
        ret->params = src->params;
195
48
        ret->prov_flags = src->prov_flags;
196
48
        if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0) {
197
48
            if (src->pub_encoding != NULL) {
198
                /* The public components are present if the private key is present */
199
48
                memcpy(ret->rho, src->rho, sizeof(src->rho));
200
48
                memcpy(ret->tr, src->tr, sizeof(src->tr));
201
48
                if (src->t1.poly != NULL) {
202
48
                    if (!ossl_ml_dsa_key_pub_alloc(ret))
203
0
                        goto err;
204
48
                    vector_copy(&ret->t1, &src->t1);
205
48
                }
206
48
                if ((ret->pub_encoding = OPENSSL_memdup(src->pub_encoding,
207
48
                         src->params->pk_len))
208
48
                    == NULL)
209
0
                    goto err;
210
48
            }
211
48
            if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0) {
212
48
                if (src->priv_encoding != NULL) {
213
45
                    memcpy(ret->K, src->K, sizeof(src->K));
214
45
                    if (src->s1.poly != NULL) {
215
45
                        if (!ossl_ml_dsa_key_priv_alloc(ret))
216
0
                            goto err;
217
45
                        vector_copy(&ret->s1, &src->s1);
218
45
                        vector_copy(&ret->s2, &src->s2);
219
45
                        vector_copy(&ret->t0, &src->t0);
220
45
                    }
221
45
                    if ((ret->priv_encoding = OPENSSL_memdup(src->priv_encoding,
222
45
                             src->params->sk_len))
223
45
                        == NULL)
224
0
                        goto err;
225
45
                }
226
48
                if (src->seed != NULL
227
45
                    && (ret->seed = OPENSSL_memdup(src->seed,
228
45
                            ML_DSA_SEED_BYTES))
229
45
                        == NULL)
230
0
                    goto err;
231
48
            }
232
48
        }
233
48
        EVP_MD_up_ref(src->shake128_md);
234
48
        EVP_MD_up_ref(src->shake256_md);
235
48
        ret->shake128_md = src->shake128_md;
236
48
        ret->shake256_md = src->shake256_md;
237
48
    }
238
48
    return ret;
239
0
err:
240
0
    ossl_ml_dsa_key_free(ret);
241
0
    return NULL;
242
48
}
243
244
/**
245
 * @brief Are 2 keys equal?
246
 *
247
 * To be equal the keys must have matching public or private key data and
248
 * contain the same parameters.
249
 * (Note that in OpenSSL that the private key always has a public key component).
250
 *
251
 * @param key1 A ML_DSA_KEY object
252
 * @param key2 A ML_DSA_KEY object
253
 * @param selection to select public and/or private component comparison.
254
 * @returns 1 if the keys are equal otherwise it returns 0.
255
 */
256
int ossl_ml_dsa_key_equal(const ML_DSA_KEY *key1, const ML_DSA_KEY *key2,
257
    int selection)
258
165
{
259
165
    int key_checked = 0;
260
261
165
    if (key1->params != key2->params)
262
0
        return 0;
263
264
165
    if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0) {
265
165
        if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0) {
266
165
            if (key1->pub_encoding != NULL && key2->pub_encoding != NULL) {
267
165
                if (memcmp(key1->pub_encoding, key2->pub_encoding,
268
165
                        key1->params->pk_len)
269
165
                    != 0)
270
62
                    return 0;
271
103
                key_checked = 1;
272
103
            }
273
165
        }
274
103
        if (!key_checked
275
0
            && (selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0) {
276
0
            if (key1->priv_encoding != NULL && key2->priv_encoding != NULL) {
277
0
                if (CRYPTO_memcmp(key1->priv_encoding, key2->priv_encoding,
278
0
                        key1->params->sk_len)
279
0
                    != 0)
280
0
                    return 0;
281
0
                key_checked = 1;
282
0
            }
283
0
        }
284
103
        return key_checked;
285
103
    }
286
0
    return 1;
287
165
}
288
289
int ossl_ml_dsa_key_has(const ML_DSA_KEY *key, int selection)
290
575
{
291
575
    if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0) {
292
        /* Note that the public key always exists if there is a private key */
293
575
        if (ossl_ml_dsa_key_get_pub(key) == NULL)
294
26
            return 0; /* No public key */
295
549
        if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0
296
94
            && ossl_ml_dsa_key_get_priv(key) == NULL)
297
0
            return 0; /* No private key */
298
549
        return 1;
299
549
    }
300
0
    return 0;
301
575
}
302
303
/*
304
 * @brief Given a key containing private key values for rho, s1 & s2
305
 * generate the public value t and return the compressed values t1, t0.
306
 *
307
 * @param key A private key containing params, rh0, s1 & s2.
308
 * @param md_ctx A EVP_MD_CTX used for sampling.
309
 * @param t1 The returned polynomial encoding of the 10 MSB of each coefficient
310
 *        of the uncompressed public key polynomial t.
311
 * @param t0 The returned polynomial encoding of the 13 LSB of each coefficient
312
 *        of the uncompressed public key polynomial t.
313
 * @returns 1 on success, or 0 on failure.
314
 */
315
static int public_from_private(const ML_DSA_KEY *key, EVP_MD_CTX *md_ctx,
316
    VECTOR *t1, VECTOR *t0)
317
2.17k
{
318
2.17k
    int ret = 0;
319
2.17k
    const ML_DSA_PARAMS *params = key->params;
320
2.17k
    uint32_t k = params->k, l = params->l;
321
2.17k
    POLY *polys;
322
2.17k
    MATRIX a_ntt;
323
2.17k
    VECTOR s1_ntt;
324
2.17k
    VECTOR t;
325
326
2.17k
    polys = OPENSSL_malloc(sizeof(*polys) * (k + l + k * l));
327
2.17k
    if (polys == NULL)
328
0
        return 0;
329
330
2.17k
    vector_init(&t, polys, k);
331
2.17k
    vector_init(&s1_ntt, t.poly + k, l);
332
2.17k
    matrix_init(&a_ntt, s1_ntt.poly + l, k, l);
333
334
    /* Using rho generate A' = A in NTT form */
335
2.17k
    if (!matrix_expand_A(md_ctx, key->shake128_md, key->rho, &a_ntt))
336
0
        goto err;
337
338
    /* t = NTT_inv(A' * NTT(s1)) + s2 */
339
2.17k
    vector_copy(&s1_ntt, &key->s1);
340
2.17k
    vector_ntt(&s1_ntt);
341
342
2.17k
    matrix_mult_vector(&a_ntt, &s1_ntt, &t);
343
2.17k
    vector_ntt_inverse(&t);
344
2.17k
    vector_add(&t, &key->s2, &t);
345
346
    /* Compress t */
347
2.17k
    vector_power2_round(&t, t1, t0);
348
349
2.17k
    ret = 1;
350
2.17k
err:
351
    /*
352
     * The low bits of |t| are private and |s1_ntt| is secret, wipe both.
353
     * The trailing |a_ntt| matrix is not wiped: per FIPS 204 section 3.6.3
354
     * the matrix A is easily computed from the public key and does not
355
     * require any special protections.
356
     */
357
2.17k
    OPENSSL_cleanse(polys, (k + l) * sizeof(*polys));
358
2.17k
    OPENSSL_free(polys);
359
2.17k
    return ret;
360
2.17k
}
361
362
int ossl_ml_dsa_key_public_from_private(ML_DSA_KEY *key)
363
2
{
364
2
    int ret = 0;
365
2
    VECTOR t0;
366
2
    EVP_MD_CTX *md_ctx = NULL;
367
368
2
    if (!vector_alloc(&t0, key->params->k)) /* t0 is already in the private key */
369
0
        return 0;
370
2
    ret = ((md_ctx = EVP_MD_CTX_new()) != NULL)
371
2
        && ossl_ml_dsa_key_pub_alloc(key) /* allocate space for t1 */
372
2
        && public_from_private(key, md_ctx, &key->t1, &t0)
373
2
        && vector_equal(&t0, &key->t0) /* compare the generated t0 to the expected */
374
0
        && ossl_ml_dsa_pk_encode(key)
375
0
        && shake_xof(md_ctx, key->shake256_md,
376
0
            key->pub_encoding, key->params->pk_len,
377
0
            key->tr, sizeof(key->tr));
378
2
    vector_zero(&t0);
379
2
    vector_free(&t0);
380
2
    EVP_MD_CTX_free(md_ctx);
381
2
    return ret;
382
2
}
383
384
int ossl_ml_dsa_key_pairwise_check(const ML_DSA_KEY *key)
385
0
{
386
0
    int ret = 0;
387
0
    VECTOR t1, t0;
388
0
    POLY *polys = NULL;
389
0
    uint32_t k = key->params->k;
390
0
    EVP_MD_CTX *md_ctx = NULL;
391
392
0
    if (key->pub_encoding == NULL || key->priv_encoding == 0)
393
0
        return 0;
394
395
0
    polys = OPENSSL_malloc(sizeof(*polys) * (2 * k));
396
0
    if (polys == NULL)
397
0
        return 0;
398
0
    md_ctx = EVP_MD_CTX_new();
399
0
    if (md_ctx == NULL)
400
0
        goto err;
401
402
0
    vector_init(&t1, polys, k);
403
0
    vector_init(&t0, polys + k, k);
404
0
    if (!public_from_private(key, md_ctx, &t1, &t0))
405
0
        goto err;
406
407
0
    ret = vector_equal(&t1, &key->t1) && vector_equal(&t0, &key->t0);
408
0
err:
409
0
    EVP_MD_CTX_free(md_ctx);
410
0
    OPENSSL_clear_free(polys, 2 * k * sizeof(*polys));
411
0
    return ret;
412
0
}
413
414
/*
415
 * @brief Generate a public-private key pair from a seed.
416
 * See FIPS 204, Algorithm 6 ML-DSA.KeyGen_internal().
417
 *
418
 * @param out The generated key (which contains params on input)
419
 *
420
 * @returns 1 on success or 0 on failure.
421
 */
422
static int keygen_internal(ML_DSA_KEY *out)
423
1.00k
{
424
1.00k
    int ret = 0;
425
1.00k
    uint8_t augmented_seed[ML_DSA_SEED_BYTES + 2];
426
1.00k
    uint8_t expanded_seed[ML_DSA_RHO_BYTES + ML_DSA_PRIV_SEED_BYTES + ML_DSA_K_BYTES];
427
1.00k
    const uint8_t *const rho = expanded_seed; /* p = Public Random Seed */
428
1.00k
    const uint8_t *const priv_seed = expanded_seed + ML_DSA_RHO_BYTES;
429
1.00k
    const uint8_t *const K = priv_seed + ML_DSA_PRIV_SEED_BYTES;
430
1.00k
    const ML_DSA_PARAMS *params = out->params;
431
1.00k
    EVP_MD_CTX *md_ctx = NULL;
432
433
1.00k
    if (out->seed == NULL
434
1.00k
        || (md_ctx = EVP_MD_CTX_new()) == NULL
435
1.00k
        || !ossl_ml_dsa_key_pub_alloc(out)
436
1.00k
        || !ossl_ml_dsa_key_priv_alloc(out))
437
0
        goto err;
438
439
    /* augmented_seed = seed || k || l */
440
1.00k
    memcpy(augmented_seed, out->seed, ML_DSA_SEED_BYTES);
441
1.00k
    augmented_seed[ML_DSA_SEED_BYTES] = (uint8_t)params->k;
442
1.00k
    augmented_seed[ML_DSA_SEED_BYTES + 1] = (uint8_t)params->l;
443
    /* Expand the seed into p[32], p'[64], K[32] */
444
1.00k
    if (!shake_xof(md_ctx, out->shake256_md, augmented_seed, sizeof(augmented_seed),
445
1.00k
            expanded_seed, sizeof(expanded_seed)))
446
0
        goto err;
447
448
1.00k
    memcpy(out->rho, rho, sizeof(out->rho));
449
1.00k
    memcpy(out->K, K, sizeof(out->K));
450
451
1.00k
    ret = vector_expand_S(md_ctx, out->shake256_md, params->eta, priv_seed, &out->s1, &out->s2)
452
1.00k
        && public_from_private(out, md_ctx, &out->t1, &out->t0)
453
1.00k
        && ossl_ml_dsa_pk_encode(out)
454
1.00k
        && shake_xof(md_ctx, out->shake256_md, out->pub_encoding, out->params->pk_len,
455
1.00k
            out->tr, sizeof(out->tr))
456
1.00k
        && ossl_ml_dsa_sk_encode(out);
457
458
1.00k
err:
459
1.00k
    if (out->seed != NULL && (out->prov_flags & ML_DSA_KEY_RETAIN_SEED) == 0) {
460
0
        OPENSSL_clear_free(out->seed, ML_DSA_SEED_BYTES);
461
0
        out->seed = NULL;
462
0
    }
463
1.00k
    EVP_MD_CTX_free(md_ctx);
464
1.00k
    OPENSSL_cleanse(augmented_seed, sizeof(augmented_seed));
465
1.00k
    OPENSSL_cleanse(expanded_seed, sizeof(expanded_seed));
466
1.00k
    return ret;
467
1.00k
}
468
469
int ossl_ml_dsa_generate_key(ML_DSA_KEY *out)
470
2.17k
{
471
2.17k
    size_t seed_len = ML_DSA_SEED_BYTES;
472
2.17k
    uint8_t *sk;
473
2.17k
    int ret;
474
475
2.17k
    if (out->seed == NULL) {
476
1.98k
        if ((out->seed = OPENSSL_malloc(seed_len)) == NULL)
477
0
            return 0;
478
1.98k
        if (RAND_priv_bytes_ex(out->libctx, out->seed, seed_len, 0) <= 0) {
479
0
            OPENSSL_free(out->seed);
480
0
            out->seed = NULL;
481
0
            return 0;
482
0
        }
483
1.98k
    }
484
    /* We're generating from a seed, drop private prekey encoding */
485
2.17k
    sk = out->priv_encoding;
486
2.17k
    out->priv_encoding = NULL;
487
2.17k
    if (sk == NULL) {
488
2.17k
        ret = keygen_internal(out);
489
2.17k
    } else {
490
0
        if ((ret = keygen_internal(out)) != 0
491
0
            && memcmp(out->priv_encoding, sk, out->params->sk_len) != 0) {
492
0
            ret = 0;
493
0
            ossl_ml_dsa_key_reset(out);
494
0
            ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_KEY,
495
0
                "explicit %s private key does not match seed",
496
0
                out->params->alg);
497
0
        }
498
0
        OPENSSL_clear_free(sk, out->params->sk_len);
499
0
    }
500
2.17k
    return ret;
501
2.17k
}
502
503
/**
504
 * @brief This is used when a ML DSA key is used for an operation.
505
 * This checks that the algorithm is the same (i.e. uses the same parameters)
506
 *
507
 * @param key A ML_DSA key to use for an operation.
508
 * @param evp_type The algorithm nid associated with an operation
509
 *
510
 * @returns 1 if the algorithm matches, or 0 otherwise.
511
 */
512
513
int ossl_ml_dsa_key_matches(const ML_DSA_KEY *key, int evp_type)
514
1.78k
{
515
1.78k
    return (key->params->evp_type == evp_type);
516
1.78k
}
517
518
/* Returns the public key data or NULL if there is no public key */
519
const uint8_t *ossl_ml_dsa_key_get_pub(const ML_DSA_KEY *key)
520
2.98k
{
521
2.98k
    return key->pub_encoding;
522
2.98k
}
523
524
/* Returns the encoded public key size */
525
size_t ossl_ml_dsa_key_get_pub_len(const ML_DSA_KEY *key)
526
2.35k
{
527
2.35k
    return key->params->pk_len;
528
2.35k
}
529
530
size_t ossl_ml_dsa_key_get_collision_strength_bits(const ML_DSA_KEY *key)
531
2.33k
{
532
2.33k
    return key->params->bit_strength;
533
2.33k
}
534
535
/* Returns the private key data or NULL if there is no private key */
536
const uint8_t *ossl_ml_dsa_key_get_priv(const ML_DSA_KEY *key)
537
3.44k
{
538
3.44k
    return key->priv_encoding;
539
3.44k
}
540
541
size_t ossl_ml_dsa_key_get_priv_len(const ML_DSA_KEY *key)
542
49
{
543
49
    return key->params->sk_len;
544
49
}
545
546
size_t ossl_ml_dsa_key_get_sig_len(const ML_DSA_KEY *key)
547
2.33k
{
548
2.33k
    return key->params->sig_len;
549
2.33k
}
550
551
OSSL_LIB_CTX *ossl_ml_dsa_key_get0_libctx(const ML_DSA_KEY *key)
552
0
{
553
0
    return key != NULL ? key->libctx : NULL;
554
0
}
555
556
const char *ossl_ml_dsa_key_get_name(const ML_DSA_KEY *key)
557
1.78k
{
558
1.78k
    return key->params->alg;
559
1.78k
}