Coverage Report

Created: 2025-12-04 06:33

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