Botan 3.14.1
Crypto and TLS for C&
Botan::ML_DSA_MessageHash Class Referencefinal

#include <ml_dsa_impl.h>

Inheritance diagram for Botan::ML_DSA_MessageHash:
Botan::DilithiumMessageHash

Public Member Functions

 DilithiumMessageHash (DilithiumHashedPublicKey tr, std::span< const uint8_t > user_context={})
DilithiumMessageRepresentative final ()
bool is_valid_user_context (std::span< const uint8_t > user_context) const final
std::string name () const
void start (std::span< const uint8_t > user_context) final
void update (std::span< const uint8_t > data)

Detailed Description

Definition at line 39 of file ml_dsa_impl.h.

Member Function Documentation

◆ DilithiumMessageHash()

Botan::DilithiumMessageHash::DilithiumMessageHash ( DilithiumHashedPublicKey tr,
std::span< const uint8_t > user_context = {} )
explicit

Definition at line 30 of file dilithium_symmetric_primitives.cpp.

30 :
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")) {}
static std::unique_ptr< XOF > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition xof.cpp:52

◆ final()

DilithiumMessageRepresentative Botan::DilithiumMessageHash::final ( )
inlineinherited

Definition at line 53 of file dilithium_symmetric_primitives.h.

53 {
54 ensure_started();
55 const scoped_cleanup clean([this]() { clear(); });
57 }
static constexpr size_t MESSAGE_HASH_BYTES
Strong< std::vector< uint8_t >, struct DilithiumMessageRepresentative_ > DilithiumMessageRepresentative
Representation of the message to be signed.

References Botan::DilithiumConstants::MESSAGE_HASH_BYTES.

◆ is_valid_user_context()

bool Botan::ML_DSA_MessageHash::is_valid_user_context ( std::span< const uint8_t > user_context) const
inlinefinalvirtual

Reimplemented from Botan::DilithiumMessageHash.

Definition at line 43 of file ml_dsa_impl.h.

43 {
44 return user_context.size() <= 255;
45 }

◆ name()

std::string Botan::DilithiumMessageHash::name ( ) const
inherited

Definition at line 37 of file dilithium_symmetric_primitives.cpp.

37 {
38 return Botan::fmt("{}({})", m_shake->name(), DilithiumConstants::MESSAGE_HASH_BYTES * 8);
39}
std::string fmt(std::string_view format, const T &... args)
Definition fmt.h:53

References Botan::fmt(), and Botan::DilithiumConstants::MESSAGE_HASH_BYTES.

◆ start()

void Botan::ML_DSA_MessageHash::start ( std::span< const uint8_t > user_context)
inlinefinalvirtual

Reimplemented from Botan::DilithiumMessageHash.

Definition at line 47 of file ml_dsa_impl.h.

47 {
48 // ML-DSA introduced an application-specific context string that is
49 // empty by default and can be set by the application.
50 //
51 // In HashML-DSA, there's an additional domain information, namely
52 // the serialized OID of the hash function used to hash the message.
53 //
54 // See FIPS 204, Algorithm 2, line 10 and Algorithm 7, line 6, and
55 // FIPS 204, Section 5.4
56
57 DilithiumMessageHash::start(user_context);
58 constexpr uint8_t domain_separator = 0x00; // HashML-DSA would use 0x01
59 const uint8_t context_length = checked_cast_to<uint8_t>(user_context.size());
60 update(std::array{domain_separator, context_length});
61 update(user_context);
62 }
virtual void start(std::span< const uint8_t > user_context)
void update(std::span< const uint8_t > data)
constexpr RT checked_cast_to(AT i)
Definition int_utils.h:104

References Botan::checked_cast_to(), Botan::DilithiumMessageHash::start(), and Botan::DilithiumMessageHash::update().

◆ update()

void Botan::DilithiumMessageHash::update ( std::span< const uint8_t > data)
inlineinherited

Definition at line 48 of file dilithium_symmetric_primitives.h.

48 {
49 ensure_started();
50 m_shake->update(data);
51 }

Referenced by start(), and Botan::ML_DSA_MessageHash::start().


The documentation for this class was generated from the following file: