Coverage Report

Created: 2026-09-12 06:55

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