Botan 3.10.0
Crypto and TLS for C&
dilithium_constants.h
Go to the documentation of this file.
1/*
2 * Crystals Dilithium Constants
3 *
4 * (C) 2022-2023 Jack Lloyd
5 * (C) 2022 Manuel Glaser - Rohde & Schwarz Cybersecurity
6 * (C) 2022-2023 Michael Boric, René Meusel - Rohde & Schwarz Cybersecurity
7 * (C) 2024 René Meusel, Rohde & Schwarz Cybersecurity
8 *
9 * Botan is released under the Simplified BSD License (see license.txt)
10 */
11
12#ifndef BOTAN_DILITHIUM_CONSTANTS_H_
13#define BOTAN_DILITHIUM_CONSTANTS_H_
14
15#include <botan/dilithium.h>
16
17namespace Botan {
18
21
22/**
23 * Algorithm constants and parameter-set dependent values
24 */
25class DilithiumConstants final {
26 public:
27 /// base data type for most calculations
28 using T = int32_t;
29
30 /// number of coefficients in a polynomial
31 static constexpr T N = 256;
32
33 /// modulus
34 static constexpr T Q = 8380417;
35
36 /// number of dropped bits from t (see FIPS 204 Section 5)
37 static constexpr T D = 13;
38
39 /// as specified in FIPS 204 (see Algorithm 36 (NTT^-1), f = 256^-1 mod Q)
40 static constexpr T F = 8347681;
41
42 /// the 512-th root of unity modulo Q (see FIPS 204 Section 8.5)
43 static constexpr T ROOT_OF_UNITY = 1753;
44
45 /// degree of the NTT polynomials
46 static constexpr size_t NTT_Degree = 256;
47
48 public:
49 /// \name Byte length's of various hash outputs and seeds
50 /// @{
51
52 static constexpr size_t SEED_RANDOMNESS_BYTES = 32;
53 static constexpr size_t SEED_RHO_BYTES = 32;
54 static constexpr size_t SEED_RHOPRIME_BYTES = 64;
55 static constexpr size_t OPTIONAL_RANDOMNESS_BYTES = 32;
56 static constexpr size_t SEED_SIGNING_KEY_BYTES = 32;
57 static constexpr size_t MESSAGE_HASH_BYTES = 64;
58 static constexpr size_t COMMITMENT_HASH_C1_BYTES = 32;
59
60 /// @}
61
62 /// \name Loop bounds for various rejection sampling loops (FIPS 204, Apx C)
63 /// @{
64
65 static constexpr uint16_t SIGNING_LOOP_BOUND = 814;
66 static constexpr uint16_t SAMPLE_POLY_FROM_XOF_BOUND = 481;
67 static constexpr uint16_t SAMPLE_NTT_POLY_FROM_XOF_BOUND = 894;
68 static constexpr uint16_t SAMPLE_IN_BALL_XOF_BOUND = 221;
69
70 /// @}
71
72 public:
73 // NOLINTBEGIN(*-use-enum-class)
74
75 enum DilithiumTau : uint8_t { _39 = 39, _49 = 49, _60 = 60 };
76
77 enum DilithiumLambda : uint16_t { _128 = 128, _192 = 192, _256 = 256 };
78
79 enum DilithiumGamma1 : uint32_t { ToThe17th = (1 << 17), ToThe19th = (1 << 19) };
80
81 enum DilithiumGamma2 : uint32_t { Qminus1DividedBy88 = (Q - 1) / 88, Qminus1DividedBy32 = (Q - 1) / 32 };
82
83 enum DilithiumEta : uint8_t { _2 = 2, _4 = 4 };
84
85 enum DilithiumBeta : uint8_t { _78 = 78, _196 = 196, _120 = 120 };
86
87 enum DilithiumOmega : uint8_t { _80 = 80, _55 = 55, _75 = 75 };
88
89 // NOLINTEND(*-use-enum-class)
90
91 explicit DilithiumConstants(DilithiumMode dimension);
93
95
99
100 bool is_modern() const { return m_mode.is_modern(); }
101
102 bool is_aes() const { return m_mode.is_aes(); }
103
104 bool is_ml_dsa() const { return m_mode.is_ml_dsa(); }
105
106 public:
107 /// \name Foundational constants
108 /// @{
109
110 /// hamming weight of the polynomial 'c' sampled from the commitment's hash
111 DilithiumTau tau() const { return m_tau; }
112
113 /// collision strength of the commitment hash function
114 DilithiumLambda lambda() const { return m_lambda; }
115
116 /// coefficient range of the randomly sampled mask 'y'
117 DilithiumGamma1 gamma1() const { return m_gamma1; }
118
119 /// low-order rounding range for decomposing the commitment from polynomial vector 'w'
120 DilithiumGamma2 gamma2() const { return m_gamma2; }
121
122 /// dimensions of the expanded matrix A
123 uint8_t k() const { return m_k; }
124
125 /// dimensions of the expanded matrix A
126 uint8_t l() const { return m_l; }
127
128 /// coefficient range of the private key's polynomial vectors 's1' and 's2'
129 DilithiumEta eta() const { return m_eta; }
130
131 /// tau * eta
132 DilithiumBeta beta() const { return m_beta; }
133
134 /// maximal hamming weight of the hint polynomial vector 'h'
135 DilithiumOmega omega() const { return m_omega; }
136
137 /// length of the public key hash 'tr' in bytes (differs between R3 and ML-DSA)
138 size_t public_key_hash_bytes() const { return m_public_key_hash_bytes; }
139
140 /// length of the entire commitment hash 'c~' in bytes (differs between R3 and ML-DSA)
141 size_t commitment_hash_full_bytes() const { return m_commitment_hash_full_bytes; }
142
143 /// @}
144
145 /// \name Sizes of encoded data structures
146 /// @{
147
148 /// byte length of the encoded signature
149 size_t signature_bytes() const { return m_signature_bytes; }
150
151 /// byte length of the encoded public key
152 size_t public_key_bytes() const { return m_public_key_bytes; }
153
154 /// byte length of the encoded private key
155 size_t private_key_bytes() const { return m_private_key_bytes; }
156
157 /// byte length of the packed commitment polynomial vector 'w1'
158 size_t serialized_commitment_bytes() const { return m_serialized_commitment_bytes; }
159
160 /// @}
161
162 DilithiumMode mode() const { return m_mode; }
163
164 /// @returns one of {44, 65, 87}
165 size_t canonical_parameter_set_identifier() const { return k() * 10 + l(); }
166
167 Dilithium_Symmetric_Primitives_Base& symmetric_primitives() const { return *m_symmetric_primitives; }
168
169 Dilithium_Keypair_Codec& keypair_codec() const { return *m_keypair_codec; }
170
171 private:
172 DilithiumMode m_mode;
173
174 DilithiumTau m_tau;
175 DilithiumLambda m_lambda;
176 DilithiumGamma1 m_gamma1;
177 DilithiumGamma2 m_gamma2;
178 uint8_t m_k;
179 uint8_t m_l;
180 DilithiumEta m_eta;
181 DilithiumBeta m_beta;
182 DilithiumOmega m_omega;
183 uint32_t m_public_key_hash_bytes;
184 uint32_t m_commitment_hash_full_bytes;
185
186 uint32_t m_private_key_bytes;
187 uint32_t m_public_key_bytes;
188 uint32_t m_signature_bytes;
189 uint32_t m_serialized_commitment_bytes;
190
191 // Mode dependent primitives
192 std::unique_ptr<Dilithium_Symmetric_Primitives_Base> m_symmetric_primitives;
193 std::unique_ptr<Dilithium_Keypair_Codec> m_keypair_codec;
194};
195
196} // namespace Botan
197
198#endif
size_t public_key_bytes() const
byte length of the encoded public key
static constexpr T F
as specified in FIPS 204 (see Algorithm 36 (NTT^-1), f = 256^-1 mod Q)
size_t commitment_hash_full_bytes() const
length of the entire commitment hash 'c~' in bytes (differs between R3 and ML-DSA)
static constexpr T Q
modulus
size_t signature_bytes() const
byte length of the encoded signature
static constexpr uint16_t SAMPLE_NTT_POLY_FROM_XOF_BOUND
DilithiumConstants & operator=(DilithiumConstants &&other)=default
DilithiumGamma1 gamma1() const
coefficient range of the randomly sampled mask 'y'
DilithiumEta eta() const
coefficient range of the private key's polynomial vectors 's1' and 's2'
DilithiumConstants(DilithiumConstants &&other)=default
static constexpr size_t COMMITMENT_HASH_C1_BYTES
static constexpr size_t MESSAGE_HASH_BYTES
uint8_t l() const
dimensions of the expanded matrix A
Dilithium_Symmetric_Primitives_Base & symmetric_primitives() const
static constexpr T D
number of dropped bits from t (see FIPS 204 Section 5)
DilithiumConstants(const DilithiumConstants &other)
static constexpr size_t SEED_RANDOMNESS_BYTES
DilithiumTau tau() const
hamming weight of the polynomial 'c' sampled from the commitment's hash
DilithiumConstants(DilithiumMode dimension)
DilithiumConstants & operator=(const DilithiumConstants &other)=delete
static constexpr uint16_t SAMPLE_IN_BALL_XOF_BOUND
static constexpr size_t SEED_SIGNING_KEY_BYTES
static constexpr size_t OPTIONAL_RANDOMNESS_BYTES
int32_t T
base data type for most calculations
Dilithium_Keypair_Codec & keypair_codec() const
static constexpr T N
number of coefficients in a polynomial
DilithiumBeta beta() const
tau * eta
static constexpr size_t SEED_RHOPRIME_BYTES
DilithiumLambda lambda() const
collision strength of the commitment hash function
size_t canonical_parameter_set_identifier() const
size_t public_key_hash_bytes() const
length of the public key hash 'tr' in bytes (differs between R3 and ML-DSA)
size_t private_key_bytes() const
byte length of the encoded private key
size_t serialized_commitment_bytes() const
byte length of the packed commitment polynomial vector 'w1'
DilithiumOmega omega() const
maximal hamming weight of the hint polynomial vector 'h'
static constexpr size_t NTT_Degree
degree of the NTT polynomials
static constexpr T ROOT_OF_UNITY
the 512-th root of unity modulo Q (see FIPS 204 Section 8.5)
static constexpr uint16_t SIGNING_LOOP_BOUND
uint8_t k() const
dimensions of the expanded matrix A
static constexpr uint16_t SAMPLE_POLY_FROM_XOF_BOUND
DilithiumGamma2 gamma2() const
low-order rounding range for decomposing the commitment from polynomial vector 'w'
static constexpr size_t SEED_RHO_BYTES