/src/openssl/crypto/ml_dsa/ml_dsa_params.c
Line  | Count  | Source (jump to first uncovered line)  | 
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  |  | #include <stddef.h>  | 
10  |  | #include <string.h>  | 
11  |  | #include <openssl/evp.h>  | 
12  |  | #include "ml_dsa_local.h"  | 
13  |  |  | 
14  |  | /* See FIPS 204 Section 4 Table 1 & Table 2 */  | 
15  |  | #define ML_DSA_44_TAU 39  | 
16  |  | #define ML_DSA_44_LAMBDA 128  | 
17  |  | #define ML_DSA_44_K 4  | 
18  |  | #define ML_DSA_44_L 4  | 
19  |  | #define ML_DSA_44_ETA ML_DSA_ETA_2  | 
20  |  | #define ML_DSA_44_BETA 78  | 
21  |  | #define ML_DSA_44_OMEGA 80  | 
22  |  | #define ML_DSA_44_SECURITY_CATEGORY 2  | 
23  |  |  | 
24  |  | /* See FIPS 204 Section 4 Table 1 & Table 2 */  | 
25  |  | #define ML_DSA_65_TAU 49  | 
26  |  | #define ML_DSA_65_LAMBDA 192  | 
27  |  | #define ML_DSA_65_K 6  | 
28  |  | #define ML_DSA_65_L 5  | 
29  |  | #define ML_DSA_65_ETA ML_DSA_ETA_4  | 
30  |  | #define ML_DSA_65_BETA 196  | 
31  |  | #define ML_DSA_65_OMEGA 55  | 
32  |  | #define ML_DSA_65_SECURITY_CATEGORY 3  | 
33  |  |  | 
34  |  | /* See FIPS 204 Section 4 Table 1 & Table 2 */  | 
35  |  | #define ML_DSA_87_TAU 60  | 
36  |  | #define ML_DSA_87_LAMBDA 256  | 
37  |  | #define ML_DSA_87_K 8  | 
38  |  | #define ML_DSA_87_L 7  | 
39  |  | #define ML_DSA_87_ETA ML_DSA_ETA_2  | 
40  |  | #define ML_DSA_87_BETA 120  | 
41  |  | #define ML_DSA_87_OMEGA 75  | 
42  |  | #define ML_DSA_87_SECURITY_CATEGORY 5  | 
43  |  |  | 
44  |  | static const ML_DSA_PARAMS ml_dsa_params[] = { | 
45  |  |     { "ML-DSA-44", | 
46  |  |       EVP_PKEY_ML_DSA_44,  | 
47  |  |       ML_DSA_44_TAU,  | 
48  |  |       ML_DSA_44_LAMBDA,  | 
49  |  |       ML_DSA_GAMMA1_TWO_POWER_17,  | 
50  |  |       ML_DSA_GAMMA2_Q_MINUS1_DIV88,  | 
51  |  |       ML_DSA_44_K,  | 
52  |  |       ML_DSA_44_L,  | 
53  |  |       ML_DSA_44_ETA,  | 
54  |  |       ML_DSA_44_BETA,  | 
55  |  |       ML_DSA_44_OMEGA,  | 
56  |  |       ML_DSA_44_SECURITY_CATEGORY,  | 
57  |  |       ML_DSA_44_PRIV_LEN,  | 
58  |  |       ML_DSA_44_PUB_LEN,  | 
59  |  |       ML_DSA_44_SIG_LEN  | 
60  |  |     },  | 
61  |  |     { "ML-DSA-65", | 
62  |  |       EVP_PKEY_ML_DSA_65,  | 
63  |  |       ML_DSA_65_TAU,  | 
64  |  |       ML_DSA_65_LAMBDA,  | 
65  |  |       ML_DSA_GAMMA1_TWO_POWER_19,  | 
66  |  |       ML_DSA_GAMMA2_Q_MINUS1_DIV32,  | 
67  |  |       ML_DSA_65_K,  | 
68  |  |       ML_DSA_65_L,  | 
69  |  |       ML_DSA_65_ETA,  | 
70  |  |       ML_DSA_65_BETA,  | 
71  |  |       ML_DSA_65_OMEGA,  | 
72  |  |       ML_DSA_65_SECURITY_CATEGORY,  | 
73  |  |       ML_DSA_65_PRIV_LEN,  | 
74  |  |       ML_DSA_65_PUB_LEN,  | 
75  |  |       ML_DSA_65_SIG_LEN  | 
76  |  |     },  | 
77  |  |     { "ML-DSA-87", | 
78  |  |       EVP_PKEY_ML_DSA_87,  | 
79  |  |       ML_DSA_87_TAU,  | 
80  |  |       ML_DSA_87_LAMBDA,  | 
81  |  |       ML_DSA_GAMMA1_TWO_POWER_19,  | 
82  |  |       ML_DSA_GAMMA2_Q_MINUS1_DIV32,  | 
83  |  |       ML_DSA_87_K,  | 
84  |  |       ML_DSA_87_L,  | 
85  |  |       ML_DSA_87_ETA,  | 
86  |  |       ML_DSA_87_BETA,  | 
87  |  |       ML_DSA_87_OMEGA,  | 
88  |  |       ML_DSA_87_SECURITY_CATEGORY,  | 
89  |  |       ML_DSA_87_PRIV_LEN,  | 
90  |  |       ML_DSA_87_PUB_LEN,  | 
91  |  |       ML_DSA_87_SIG_LEN  | 
92  |  |     },  | 
93  |  |     {NULL}, | 
94  |  | };  | 
95  |  |  | 
96  |  | /**  | 
97  |  |  * @brief A getter to convert an algorithm name into a ML_DSA_PARAMS object  | 
98  |  |  */  | 
99  |  | const ML_DSA_PARAMS *ossl_ml_dsa_params_get(int evp_type)  | 
100  | 0  | { | 
101  | 0  |     const ML_DSA_PARAMS *p;  | 
102  |  | 
  | 
103  | 0  |     for (p = ml_dsa_params; p->alg != NULL; ++p) { | 
104  | 0  |         if (p->evp_type == evp_type)  | 
105  | 0  |             return p;  | 
106  | 0  |     }  | 
107  | 0  |     return NULL;  | 
108  | 0  | }  |