Botan 3.11.0
Crypto and TLS for C&
dilithium_symmetric_primitives.cpp
Go to the documentation of this file.
1/**
2 * Symmetric primitives for dilithium
3 *
4 * (C) 2022-2023 Jack Lloyd
5 * (C) 2022-2023 Michael Boric, René Meusel - Rohde & Schwarz Cybersecurity
6 * (C) 2022 Manuel Glaser - Rohde & Schwarz Cybersecurity
7 * (C) 2024 Fabian Albert, René Meusel - Rohde & Schwarz Cybersecurity
8 *
9 * Botan is released under the Simplified BSD License (see license.txt)
10 */
11
12#include <botan/internal/dilithium_symmetric_primitives.h>
13
14#include <botan/internal/fmt.h>
15
16#if defined(BOTAN_HAS_DILITHIUM)
17 #include <botan/internal/dilithium_round3.h>
18#endif
19
20#if defined(BOTAN_HAS_DILITHIUM_AES)
21 #include <botan/internal/dilithium_aes.h>
22#endif
23
24#if defined(BOTAN_HAS_ML_DSA)
25 #include <botan/internal/ml_dsa_impl.h>
26#endif
27
28namespace Botan {
29
31 m_tr(std::move(tr)), m_shake(XOF::create_or_throw("SHAKE-256")) {}
32
34
35std::string DilithiumMessageHash::name() const {
36 return Botan::fmt("{}({})", m_shake->name(), DilithiumConstants::MESSAGE_HASH_BYTES * 8);
37}
38
40 std::unique_ptr<DilithiumXOF> xof_adapter) :
41 m_commitment_hash_length_bytes(mode.commitment_hash_full_bytes()),
42 m_public_key_hash_bytes(mode.public_key_hash_bytes()),
43 m_mode(mode.mode()),
44 m_xof_adapter(std::move(xof_adapter)) {}
45
46std::unique_ptr<Dilithium_Symmetric_Primitives_Base> Dilithium_Symmetric_Primitives_Base::create(
47 const DilithiumConstants& mode) {
48#if defined(BOTAN_HAS_DILITHIUM)
49 if(mode.is_modern() && !mode.is_ml_dsa()) {
50 return std::make_unique<Dilithium_Symmetric_Primitives>(mode);
51 }
52#endif
53
54#if defined(BOTAN_HAS_DILITHIUM_AES)
55 if(mode.is_aes()) {
56 return std::make_unique<Dilithium_AES_Symmetric_Primitives>(mode);
57 }
58#endif
59
60#if defined(BOTAN_HAS_ML_DSA)
61 if(mode.is_ml_dsa()) {
62 return std::make_unique<ML_DSA_Symmetric_Primitives>(mode);
63 }
64#endif
65
66 throw Not_Implemented("requested ML-DSA/Dilithium mode is not implemented in this build");
67}
68
69} // namespace Botan
static constexpr size_t MESSAGE_HASH_BYTES
DilithiumMessageHash(DilithiumHashedPublicKey tr)
static std::unique_ptr< Dilithium_Symmetric_Primitives_Base > create(const DilithiumConstants &mode)
Dilithium_Symmetric_Primitives_Base(const DilithiumConstants &mode, std::unique_ptr< DilithiumXOF > xof_adapter)
std::string fmt(std::string_view format, const T &... args)
Definition fmt.h:53
Strong< std::vector< uint8_t >, struct DilithiumHashedPublicKey_ > DilithiumHashedPublicKey