Botan 3.14.1
Crypto and TLS for C&
dilithium.cpp
Go to the documentation of this file.
1/*
2* Crystals Dilithium Digital Signature Algorithms
3* Based on the public domain reference implementation by the
4* designers (https://github.com/pq-crystals/dilithium)
5*
6* Further changes
7* (C) 2021-2023 Jack Lloyd
8* (C) 2021-2022 Manuel Glaser - Rohde & Schwarz Cybersecurity
9* (C) 2021-2023 Michael Boric, René Meusel - Rohde & Schwarz Cybersecurity
10* (C) 2024 René Meusel - Rohde & Schwarz Cybersecurity
11* (C) 2026 Falko Strenzke – MTG AG
12*
13* Botan is released under the Simplified BSD License (see license.txt)
14*/
15
16#include <botan/dilithium.h>
17
18#include <botan/exceptn.h>
19#include <botan/pk_options_readers.h>
20#include <botan/rng.h>
21#include <botan/internal/dilithium_algos.h>
22#include <botan/internal/dilithium_keys.h>
23#include <botan/internal/dilithium_symmetric_primitives.h>
24#include <botan/internal/dilithium_types.h>
25#include <botan/internal/fmt.h>
26#include <botan/internal/keypair.h>
27#include <botan/internal/pk_ops_impl.h>
28#include <botan/internal/pk_options_impl.h>
29#include <botan/internal/stl_util.h>
30
31#include <string_view>
32
33namespace Botan {
34namespace {
35
36DilithiumMode::Mode dilithium_mode_from_string(std::string_view str) {
37 if(str == "Dilithium-4x4-r3") {
39 }
40 if(str == "Dilithium-4x4-AES-r3") {
42 }
43 if(str == "Dilithium-6x5-r3") {
45 }
46 if(str == "Dilithium-6x5-AES-r3") {
48 }
49 if(str == "Dilithium-8x7-r3") {
51 }
52 if(str == "Dilithium-8x7-AES-r3") {
54 }
55 if(str == "ML-DSA-4x4") {
57 }
58 if(str == "ML-DSA-6x5") {
60 }
61 if(str == "ML-DSA-8x7") {
63 }
64
65 throw Invalid_Argument(fmt("'{}' is not a valid Dilithium mode name", str));
66}
67
68DilithiumMode::Mode dilithium_mode_from_oid(const OID& oid) {
69 if(const auto name = oid.registered_name()) {
70 return dilithium_mode_from_string(*name);
71 }
72
73 throw Invalid_Argument(fmt("OID '{}' is not registered as a Dilithium/ML-DSA mode", oid));
74}
75
76} // namespace
77
78DilithiumMode::DilithiumMode(const OID& oid) : m_mode(dilithium_mode_from_oid(oid)) {}
79
80DilithiumMode::DilithiumMode(std::string_view str) : m_mode(dilithium_mode_from_string(str)) {}
81
85
86std::string DilithiumMode::to_string() const {
87 switch(m_mode) {
89 return "Dilithium-4x4-r3";
91 return "Dilithium-4x4-AES-r3";
93 return "Dilithium-6x5-r3";
95 return "Dilithium-6x5-AES-r3";
97 return "Dilithium-8x7-r3";
99 return "Dilithium-8x7-AES-r3";
101 return "ML-DSA-4x4";
103 return "ML-DSA-6x5";
105 return "ML-DSA-8x7";
106 }
107
109}
110
112 return m_mode == Dilithium4x4_AES || m_mode == Dilithium6x5_AES || m_mode == Dilithium8x7_AES;
113}
114
116 return !is_aes();
117}
118
120 return m_mode == ML_DSA_4x4 || m_mode == ML_DSA_6x5 || m_mode == ML_DSA_8x7;
121}
122
124#if defined(BOTAN_HAS_DILITHIUM_AES)
125 if(is_dilithium_round3() && is_aes()) {
126 return true;
127 }
128#endif
129#if defined(BOTAN_HAS_DILITHIUM)
130 if(is_dilithium_round3() && is_modern()) {
131 return true;
132 }
133#endif
134#if defined(BOTAN_HAS_ML_DSA)
135 if(is_ml_dsa()) {
136 return true;
137 }
138#endif
139 return false;
140}
141
142namespace {
143
144void validate_dilithium_options(const PK_Signature_Options_Reader& options, const DilithiumMode& mode) {
145 /*
146 * The "salt" is the randomness drawn during hedged signing. Its size is fixed
147 * by the scheme, so the option is accepted only if it names that size:
148 * ML-DSA hashes a 32 byte rnd (FIPS 204, Algorithm 2), while randomized
149 * Dilithium round 3 samples the entire 64 byte rho' (Figure 4, line 12).
150 */
151 if(options.using_salt_size()) {
153 "Dilithium cannot support a salt while also being deterministic");
154
155 const size_t randomness_bytes =
157
158 if(options.salt_size().value() != randomness_bytes) {
159 throw Invalid_Argument(fmt("{} can only be used with a {} byte salt", mode.to_string(), randomness_bytes));
160 }
161 }
162
163 /*
164 * FIPS 204 (Algorithm 2 line 10, Algorithm 3 line 5) binds an application
165 * context string of at most 255 bytes into the message representative.
166 * Dilithium round 3 has no such feature.
167 */
168 if(const auto& ctx = options.context()) {
169 BOTAN_ARG_CHECK(mode.is_ml_dsa(), "Dilithium round 3 does not support a signature context");
170 BOTAN_ARG_CHECK(ctx->size() <= 255, "ML-DSA context must not exceed 255 bytes");
171 }
172}
173
174} // namespace
175
176// The signature and verification operations should be in an anonymous namespace
177// as well, but cannot due to an apparent bug in MSVC
178
179class Dilithium_Signature_Operation final : public PK_Ops::Signature {
180 public:
181 Dilithium_Signature_Operation(DilithiumInternalKeypair keypair, const PK_Signature_Options_Reader& options) :
182 m_keypair(std::move(keypair)),
183
184 // FIPS 204, Section 3.4
185 // By default, this standard specifies the signing algorithm to use both
186 // types of randomness [fresh from the RNG and a value in the private key].
187 // This is referred to as the "hedged" variant of the signing procedure.
188 m_randomized(!options.using_deterministic_signature()),
189 m_h(m_keypair.second->mode().symmetric_primitives().get_message_hash(
190 m_keypair.first->tr(), options.context().value_or(std::vector<uint8_t>{}))),
191 m_s1(ntt(m_keypair.second->s1().clone())),
192 m_s2(ntt(m_keypair.second->s2().clone())),
193 m_t0(ntt(m_keypair.second->t0().clone())),
194 m_A(Dilithium_Algos::expand_A(m_keypair.first->rho(), m_keypair.second->mode())) {
195 validate_dilithium_options(options, m_keypair.second->mode().mode());
196 }
197
198 void update(std::span<const uint8_t> input) override { m_h->update(input); }
199
200 /**
201 * NIST FIPS 204, Algorithm 2 (ML-DSA.Sign) and Algorithm 7 (ML-DSA.Sign_internal)
202 *
203 * Note that the private key decoding is done ahead of time. Also, the
204 * matrix expansion of A from 'rho' along with the NTT-transforms of s1,
205 * s2 and t0 are done in the constructor of this class, as a 'signature
206 * operation' may be used to sign multiple messages.
207 *
208 * TODO: Implement support for the specified 'ctx' context string which is
209 * application defined and "empty" by default and <= 255 bytes long.
210 */
211 std::vector<uint8_t> sign(RandomNumberGenerator& rng) override {
212 const auto scope = CT::scoped_poison(*m_keypair.second);
213
214 const auto mu = m_h->final();
215 const auto& mode = m_keypair.second->mode();
216 const auto& sympri = mode.symmetric_primitives();
217
218 const auto rhoprime = sympri.H_maybe_randomized(m_keypair.second->signing_seed(), mu, maybe(rng));
219 CT::poison(rhoprime);
220
221 for(uint16_t nonce = 0, n = 0; n <= DilithiumConstants::SIGNING_LOOP_BOUND; ++n, nonce += mode.l()) {
222 const auto y = Dilithium_Algos::expand_mask(rhoprime, nonce, mode);
223
224 auto w_ntt = m_A * ntt(y.clone());
225 w_ntt.reduce();
226 auto w = inverse_ntt(std::move(w_ntt));
227 w.conditional_add_q();
228
229 auto [w1, w0] = Dilithium_Algos::decompose(w, mode);
230 const auto ch = CT::driveby_unpoison(sympri.H(mu, Dilithium_Algos::encode_commitment(w1, mode)));
231
232 const auto c = ntt(Dilithium_Algos::sample_in_ball(ch, mode));
233 const auto cs1 = inverse_ntt(c * m_s1);
234 auto z = y + cs1;
235 z.reduce();
236
237 // We validate the infinity norm of z before proceeding to calculate cs2
238 if(!Dilithium_Algos::infinity_norm_within_bound(z, to_underlying(mode.gamma1()) - mode.beta())) {
239 continue;
240 }
241 CT::unpoison(z); // part of the signature
242
243 const auto cs2 = inverse_ntt(c * m_s2);
244
245 // Note: w0 is used as a scratch space for calculation. We're aliasing
246 // the results to const&'s merely to communicate which value the
247 // intermediate results represent in the specification.
248 w0 -= cs2;
249 w0.reduce();
250 const auto& r0 = w0;
251 if(!Dilithium_Algos::infinity_norm_within_bound(r0, to_underlying(mode.gamma2()) - mode.beta())) {
252 continue;
253 }
254
255 auto ct0 = inverse_ntt(c * m_t0);
256 ct0.reduce();
257 // We validate the infinity norm of ct0 before proceeding to calculate the hint.
258 if(!Dilithium_Algos::infinity_norm_within_bound(ct0, mode.gamma2())) {
259 continue;
260 }
261
262 w0 += ct0;
263 w0.conditional_add_q();
264 const auto& w0cs2ct0 = w0;
265
266 const auto hint = Dilithium_Algos::make_hint(w0cs2ct0, w1, mode);
267 if(CT::driveby_unpoison(hint.hamming_weight()) > mode.omega()) {
268 continue;
269 }
270 CT::unpoison(hint); // part of the signature
271
272 return Dilithium_Algos::encode_signature(ch, z, hint, mode).get();
273 }
274
275 throw Internal_Error("ML-DSA/Dilithium signature loop did not terminate");
276 }
277
278 size_t signature_length() const override { return m_keypair.second->mode().signature_bytes(); }
279
280 AlgorithmIdentifier algorithm_identifier() const override {
281 return AlgorithmIdentifier(m_keypair.second->mode().mode().object_identifier(),
283 }
284
285 std::string hash_function() const override { return m_h->name(); }
286
287 private:
288 std::optional<std::reference_wrapper<RandomNumberGenerator>> maybe(RandomNumberGenerator& rng) const {
289 if(m_randomized) {
290 return rng;
291 } else {
292 return std::nullopt;
293 }
294 }
295
296 private:
297 DilithiumInternalKeypair m_keypair;
298 bool m_randomized;
299 std::unique_ptr<DilithiumMessageHash> m_h;
300
301 const DilithiumPolyVecNTT m_s1;
302 const DilithiumPolyVecNTT m_s2;
303 const DilithiumPolyVecNTT m_t0;
304 const DilithiumPolyMatNTT m_A;
305};
306
307class Dilithium_Verification_Operation final : public PK_Ops::Verification {
308 public:
309 Dilithium_Verification_Operation(std::shared_ptr<const Dilithium_PublicKeyInternal> pubkey,
310 const PK_Signature_Options_Reader& options) :
311 m_pub_key(std::move(pubkey)),
312 m_A(Dilithium_Algos::expand_A(m_pub_key->rho(), m_pub_key->mode())),
313 m_t1_ntt_shifted(ntt(m_pub_key->t1() << DilithiumConstants::D)),
314 m_h(m_pub_key->mode().symmetric_primitives().get_message_hash(
315 m_pub_key->tr(), options.context().value_or(std::vector<uint8_t>{}))) {}
316
317 void update(std::span<const uint8_t> input) override { m_h->update(input); }
318
319 /**
320 * NIST FIPS 204, Algorithm 3 (ML-DSA.Verify) and 8 (ML-DSA.Verify_internal)
321 *
322 * Note that the public key decoding is done ahead of time. Also, the
323 * matrix A is expanded from 'rho' in the constructor of this class, as
324 * a 'verification operation' may be used to verify multiple signatures.
325 *
326 * TODO: Implement support for the specified 'ctx' context string which is
327 * application defined and "empty" by default and <= 255 bytes long.
328 */
329 bool is_valid_signature(std::span<const uint8_t> sig) override {
330 const auto& mode = m_pub_key->mode();
331 const auto& sympri = mode.symmetric_primitives();
332 const StrongSpan<const DilithiumSerializedSignature> sig_bytes(sig);
333
334 const auto mu = m_h->final();
335
336 if(sig_bytes.size() != mode.signature_bytes()) {
337 return false;
338 }
339
340 auto signature = Dilithium_Algos::decode_signature(sig_bytes, mode);
341 if(!signature.has_value()) {
342 return false;
343 }
344 auto [ch, z, h] = std::move(signature.value());
345
346 // This check was removed from the final version of ML-DSA
347 if(!mode.is_ml_dsa() && h.hamming_weight() > mode.omega()) {
348 return false;
349 }
350
351 if(!Dilithium_Algos::infinity_norm_within_bound(z, to_underlying(mode.gamma1()) - mode.beta())) {
352 return false;
353 }
354
355 const auto c_hat = ntt(Dilithium_Algos::sample_in_ball(ch, mode));
356 auto w_approx = m_A * ntt(std::move(z));
357 w_approx -= c_hat * m_t1_ntt_shifted;
358 w_approx.reduce();
359 auto w1 = inverse_ntt(std::move(w_approx));
360 w1.conditional_add_q();
361 Dilithium_Algos::use_hint(w1, h, mode);
362
363 const auto chprime = sympri.H(mu, Dilithium_Algos::encode_commitment(w1, mode));
364
365 BOTAN_ASSERT_NOMSG(ch.size() == chprime.size());
366 return std::equal(ch.begin(), ch.end(), chprime.begin());
367 }
368
369 std::string hash_function() const override { return m_h->name(); }
370
371 private:
372 std::shared_ptr<const Dilithium_PublicKeyInternal> m_pub_key;
374 DilithiumPolyVecNTT m_t1_ntt_shifted;
375 std::unique_ptr<DilithiumMessageHash> m_h;
376};
377
378Dilithium_PublicKey::Dilithium_PublicKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> pk) :
379 Dilithium_PublicKey(pk, DilithiumMode(alg_id.oid())) {
380 // The parameter set is identified by the OID; no parameters are defined.
381 if(!alg_id.parameters_are_empty()) {
382 throw Decoding_Error("Unexpected parameters for ML-DSA/Dilithium public key");
383 }
384}
385
387 DilithiumConstants mode(m);
388 BOTAN_ARG_CHECK(mode.mode().is_available(), "Dilithium/ML-DSA mode is not available in this build");
389
391}
392
394 // Note: For Dilithium we made the blunder to return the OID's human readable
395 // name, e.g. "Dilithium-4x4-AES". This is inconsistent with the other
396 // public key algorithms which return the generic name only.
397 //
398 // TODO(Botan4): Fix the inconsistency described above, also considering that
399 // there might be other code locations that identify Dilithium
400 // by std::string::starts_with("Dilithium-").
401 // (Above assumes that Dilithium won't be removed entirely!)
402 return (m_public->mode().is_ml_dsa()) ? std::string("ML-DSA") : m_public->mode().mode().to_string();
403}
404
408
410 return m_public->mode().mode().object_identifier();
411}
412
414 return m_public->mode().canonical_parameter_set_identifier();
415}
416
418 return m_public->mode().lambda();
419}
420
421std::vector<uint8_t> Dilithium_PublicKey::raw_public_key_bits() const {
422 return m_public->raw_pk().get();
423}
424
425std::vector<uint8_t> Dilithium_PublicKey::public_key_bits() const {
426 // Currently, there isn't a finalized definition of an ASN.1 structure for
427 // Dilithium aka ML-DSA public keys. Therefore, we return the raw public key bits.
428 return raw_public_key_bits();
429}
430
431bool Dilithium_PublicKey::check_key(RandomNumberGenerator& /*rng*/, bool /*strong*/) const {
432 // The public key consists of (rho, t1). Length validation is performed in
433 // the constructor, and t1 coefficients are decoded via SimpleBitUnpack
434 // (FIPS 204 Algorithm 18) into a power-of-2 range that exactly covers all
435 // valid values, so no out-of-range coefficients are possible. For the
436 // private key, s1/s2 coefficient ranges are validated and t is recomputed
437 // from (A, s1, s2) and verified against the stored hash during decoding.
438 return true;
439}
440
441std::unique_ptr<Private_Key> Dilithium_PublicKey::generate_another(RandomNumberGenerator& rng) const {
442 return std::make_unique<Dilithium_PrivateKey>(rng, m_public->mode().mode());
443}
444
445std::unique_ptr<PK_Ops::Verification> Dilithium_PublicKey::_create_verification_op(
446 const PK_Signature_Options_Reader& options) const {
447 validate_dilithium_options(options, m_public->mode().mode());
448
450
451 return std::make_unique<Dilithium_Verification_Operation>(m_public, options);
452}
453
454std::unique_ptr<PK_Ops::Verification> Dilithium_PublicKey::create_x509_verification_op(
455 const AlgorithmIdentifier& alg_id, std::string_view provider) const {
456 if(provider.empty() || provider == "base") {
457 if(alg_id != this->algorithm_identifier()) {
458 throw Decoding_Error("Unexpected AlgorithmIdentifier for Dilithium X.509 signature");
459 }
460 return std::make_unique<Dilithium_Verification_Operation>(
462 }
463 throw Provider_Not_Found(algo_name(), provider);
464}
465
466/**
467 * NIST FIPS 204, Algorithm 1 (ML-DSA.KeyGen), and 6 (ML-DSA.KeyGen_internal)
468 *
469 * This integrates the seed generation and the actual key generation into one
470 * function. After generation, the relevant components of the key are kept in
471 * memory; the key encoding is deferred until explicitly requested.
472 *
473 * The calculation of (t1, t0) is done in a separate function, as it is also
474 * needed for the decoding of a private key.
475 */
477 DilithiumConstants mode(m);
478 BOTAN_ARG_CHECK(mode.mode().is_available(), "Dilithium/ML-DSA mode is not available in this build");
479 m_private_key_format = mode.is_ml_dsa() ? MlPrivateKeyFormat::Seed : MlPrivateKeyFormat::Expanded;
480 std::tie(m_public, m_private) = Dilithium_Algos::expand_keypair(
482}
483
484Dilithium_PrivateKey::Dilithium_PrivateKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> sk) :
485 Dilithium_PrivateKey(sk, DilithiumMode(alg_id.oid())) {
486 // The parameter set is identified by the OID; no parameters are defined.
487 if(!alg_id.parameters_are_empty()) {
488 throw Decoding_Error("Unexpected parameters for ML-DSA/Dilithium private key");
489 }
490}
491
493 DilithiumConstants mode(m);
494 const auto& codec = mode.keypair_codec();
495 auto decoded = codec.decode_keypair(sk, std::move(mode));
496 m_public = std::move(decoded.keypair.first);
497 m_private = std::move(decoded.keypair.second);
498 m_private_key_format = decoded.format;
499}
500
502 return m_private_key_format;
503}
504
506 switch(format) {
508 if(is_dilithium_round3()) {
509 throw Encoding_Error("Dilithium round 3 private keys only support the expanded format");
510 }
511 const auto& seed = m_private->seed();
512 if(!seed.has_value()) {
513 throw Encoding_Error("ML-DSA private key does not contain the seed, cannot encode it in the seed format");
514 }
515 return seed->get();
516 }
518 return Dilithium_Algos::encode_keypair({m_public, m_private}).get();
520 throw Encoding_Error(
521 "there is no raw encoding of an ML-DSA private key containing both seed and expanded key");
522 }
524}
525
527 return m_private->mode().keypair_codec().encode_keypair({m_public, m_private}, format);
528}
529
531 return m_private->mode().is_ml_dsa();
532}
533
535 return !m_private->mode().is_ml_dsa();
536}
537
538std::unique_ptr<PK_Ops::Signature> Dilithium_PrivateKey::_create_signature_op(
539 RandomNumberGenerator& rng, const PK_Signature_Options_Reader& options) const {
540 BOTAN_UNUSED(rng);
541
543
544 return std::make_unique<Dilithium_Signature_Operation>(DilithiumInternalKeypair{m_public, m_private}, options);
545}
546
548 if(!Dilithium_PublicKey::check_key(rng, strong)) {
549 return false;
550 }
551
552 if(strong) {
553 return KeyPair::signature_consistency_check(rng, *this, "");
554 }
555
556 return true;
557}
558
559std::unique_ptr<Public_Key> Dilithium_PrivateKey::public_key() const {
560 return std::make_unique<Dilithium_PublicKey>(*this);
561}
562} // namespace Botan
#define BOTAN_UNUSED
Definition assert.h:151
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:82
#define BOTAN_ARG_CHECK(expr, msg)
Definition assert.h:33
#define BOTAN_ASSERT_UNREACHABLE()
Definition assert.h:173
bool parameters_are_empty() const
Definition asn1_obj.h:715
static constexpr size_t SEED_RANDOMNESS_BYTES
static constexpr size_t OPTIONAL_RANDOMNESS_BYTES
Dilithium_Keypair_Codec & keypair_codec() const
static constexpr size_t SEED_RHOPRIME_BYTES
static constexpr uint16_t SIGNING_LOOP_BOUND
OID object_identifier() const
Definition dilithium.cpp:82
std::string to_string() const
Definition dilithium.cpp:86
Mode mode() const
Definition dilithium.h:54
DilithiumMode(Mode mode)
Definition dilithium.h:38
bool is_aes() const
bool is_modern() const
bool is_dilithium_round3() const
Definition dilithium.h:50
bool is_available() const
bool is_ml_dsa() const
virtual DilithiumDecodedKeypair decode_keypair(std::span< const uint8_t > private_key, DilithiumConstants mode) const =0
MlPrivateKeyFormat private_key_format() const override
Dilithium_PrivateKey(RandomNumberGenerator &rng, DilithiumMode mode)
secure_vector< uint8_t > formatted_raw_private_key_bits(MlPrivateKeyFormat format) const override
bool check_key(RandomNumberGenerator &rng, bool strong) const override
std::unique_ptr< Public_Key > public_key() const override
std::unique_ptr< PK_Ops::Signature > _create_signature_op(RandomNumberGenerator &rng, const PK_Signature_Options_Reader &options) const override
secure_vector< uint8_t > formatted_private_key_bits(MlPrivateKeyFormat format) const override
static std::shared_ptr< Dilithium_PublicKeyInternal > decode(DilithiumConstants mode, StrongSpan< const DilithiumSerializedPublicKey > raw_pk)
AlgorithmIdentifier algorithm_identifier() const override
std::vector< uint8_t > public_key_bits() const override
OID object_identifier() const override
std::unique_ptr< PK_Ops::Verification > _create_verification_op(const PK_Signature_Options_Reader &options) const override
Dilithium_PublicKey(const AlgorithmIdentifier &alg_id, std::span< const uint8_t > pk)
std::unique_ptr< Private_Key > generate_another(RandomNumberGenerator &rng) const final
std::unique_ptr< PK_Ops::Verification > create_x509_verification_op(const AlgorithmIdentifier &signature_algorithm, std::string_view provider) const override
size_t key_length() const override
std::string algo_name() const override
size_t estimated_strength() const override
std::shared_ptr< const Dilithium_PublicKeyInternal > m_public
Definition dilithium.h:107
std::vector< uint8_t > raw_public_key_bits() const override
bool check_key(RandomNumberGenerator &rng, bool strong) const override
static OID from_string(std::string_view str)
Definition asn1_oid.cpp:80
virtual AlgorithmIdentifier algorithm_identifier() const
Definition pk_ops.cpp:30
virtual size_t signature_length() const =0
virtual std::string hash_function() const =0
virtual std::string hash_function() const =0
static PK_Signature_Options_Reader for_verification(const PK_Signature_Options &options)
const std::optional< std::vector< uint8_t > > & context() const
const std::optional< size_t > & salt_size() const
void random_vec(std::span< uint8_t > v)
Definition rng.h:254
constexpr T & get() &
Definition strong_type.h:81
const char * name
Definition ffi_tls.h:59
constexpr decltype(auto) driveby_unpoison(T &&v)
Definition ct_utils.h:243
constexpr auto scoped_poison(const Ts &... xs)
Definition ct_utils.h:222
constexpr void unpoison(const T *p, size_t n)
Definition ct_utils.h:67
constexpr void poison(const T *p, size_t n)
Definition ct_utils.h:56
DilithiumInternalKeypair expand_keypair(DilithiumSeedRandomness xi, DilithiumConstants mode)
DilithiumSerializedSignature encode_signature(StrongSpan< const DilithiumCommitmentHash > c, const DilithiumPolyVec &response, const DilithiumPolyVec &hint, const DilithiumConstants &mode)
DilithiumSerializedPrivateKey encode_keypair(const DilithiumInternalKeypair &keypair)
DilithiumSerializedCommitment encode_commitment(const DilithiumPolyVec &w1, const DilithiumConstants &mode)
bool infinity_norm_within_bound(const DilithiumPolyVec &vec, size_t bound)
std::pair< DilithiumPolyVec, DilithiumPolyVec > decompose(const DilithiumPolyVec &vec, const DilithiumConstants &mode)
DilithiumPolyVec expand_mask(StrongSpan< const DilithiumSeedRhoPrime > rhoprime, uint16_t nonce, const DilithiumConstants &mode)
DilithiumPolyMatNTT expand_A(StrongSpan< const DilithiumSeedRho > rho, const DilithiumConstants &mode)
void use_hint(DilithiumPolyVec &vec, const DilithiumPolyVec &hints, const DilithiumConstants &mode)
std::optional< std::tuple< DilithiumCommitmentHash, DilithiumPolyVec, DilithiumPolyVec > > decode_signature(StrongSpan< const DilithiumSerializedSignature > sig, const DilithiumConstants &mode)
DilithiumPolyVec make_hint(const DilithiumPolyVec &z, const DilithiumPolyVec &r, const DilithiumConstants &mode)
DilithiumPoly sample_in_ball(StrongSpan< const DilithiumCommitmentHash > seed, const DilithiumConstants &mode)
bool signature_consistency_check(RandomNumberGenerator &rng, const Private_Key &private_key, const Public_Key &public_key, std::string_view padding)
Definition keypair.cpp:49
BOTAN_FN_ISA_AVX2 void inverse_ntt(std::span< int16_t, 256 > p)
BOTAN_FN_ISA_AVX2 void ntt(std::span< int16_t, 256 > p)
Botan::CRYSTALS::PolynomialVector< DilithiumPolyTraits, Botan::CRYSTALS::Domain::NTT > DilithiumPolyVecNTT
std::string fmt(std::string_view format, const T &... args)
Definition fmt.h:53
Strong< secure_vector< uint8_t >, struct DilithiumSeedRandomness_ > DilithiumSeedRandomness
Principal seed used to generate Dilithium key pairs.
auto to_underlying(T e) noexcept
Definition stl_util.h:158
BOTAN_FORCE_INLINE constexpr T rho(T x)
Definition rotate.h:53
void require_software_provider(const OptionsT &options, std::string_view algo_name)
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:128
Botan::CRYSTALS::PolynomialMatrix< DilithiumPolyTraits > DilithiumPolyMatNTT
std::pair< std::shared_ptr< const Dilithium_PublicKeyInternal >, std::shared_ptr< const Dilithium_PrivateKeyInternal > > DilithiumInternalKeypair
Internal representation of a Dilithium key pair.