Coverage Report

Created: 2026-07-23 06:28

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