Botan 3.14.1
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
30DilithiumMessageHash::DilithiumMessageHash(DilithiumHashedPublicKey tr, std::span<const uint8_t> user_context) :
31 m_tr(std::move(tr)),
32 m_user_context(user_context.begin(), user_context.end()),
33 m_shake(XOF::create_or_throw("SHAKE-256")) {}
34
36
37std::string DilithiumMessageHash::name() const {
38 return Botan::fmt("{}({})", m_shake->name(), DilithiumConstants::MESSAGE_HASH_BYTES * 8);
39}
40
42 std::unique_ptr<DilithiumXOF> xof_adapter) :
43 m_commitment_hash_length_bytes(mode.commitment_hash_full_bytes()),
44 m_public_key_hash_bytes(mode.public_key_hash_bytes()),
45 m_mode(mode.mode()),
46 m_xof_adapter(std::move(xof_adapter)) {}
47
48std::unique_ptr<Dilithium_Symmetric_Primitives_Base> Dilithium_Symmetric_Primitives_Base::create(
49 const DilithiumConstants& mode) {
50#if defined(BOTAN_HAS_DILITHIUM)
51 if(mode.is_modern() && !mode.is_ml_dsa()) {
52 return std::make_unique<Dilithium_Symmetric_Primitives>(mode);
53 }
54#endif
55
56#if defined(BOTAN_HAS_DILITHIUM_AES)
57 if(mode.is_aes()) {
58 return std::make_unique<Dilithium_AES_Symmetric_Primitives>(mode);
59 }
60#endif
61
62#if defined(BOTAN_HAS_ML_DSA)
63 if(mode.is_ml_dsa()) {
64 return std::make_unique<ML_DSA_Symmetric_Primitives>(mode);
65 }
66#endif
67
68 throw Not_Implemented("requested ML-DSA/Dilithium mode is not implemented in this build");
69}
70
71} // namespace Botan
static constexpr size_t MESSAGE_HASH_BYTES
DilithiumMessageHash(DilithiumHashedPublicKey tr, std::span< const uint8_t > user_context={})
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