Coverage Report

Created: 2025-12-31 06:58

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