11#ifndef BOTAN_DILITHIUM_ASYM_PRIMITIVES_H_
12#define BOTAN_DILITHIUM_ASYM_PRIMITIVES_H_
14#include <botan/dilithium.h>
16#include <botan/internal/dilithium_types.h>
17#include <botan/internal/fmt.h>
18#include <botan/internal/shake_xof.h>
19#include <botan/internal/stl_util.h>
23class RandomNumberGenerator;
43 return user_context.empty();
46 virtual void start(std::span<const uint8_t> user_context) {
53 void update(std::span<const uint8_t> data) {
67 m_was_started =
false;
70 void ensure_started() {
80 SHAKE_256_XOF m_shake;
104 m_commitment_hash_length_bytes(mode.commitment_hash_full_bytes()),
105 m_public_key_hash_bytes(mode.public_key_hash_bytes()),
107 m_xof_adapter(std::move(xof_adapter)) {}
119 return std::make_unique<DilithiumMessageHash>(std::move(tr));
127 std::optional<std::reference_wrapper<RandomNumberGenerator>> rng)
const = 0;
133 std::tuple<DilithiumSeedRho, DilithiumSeedRhoPrime, DilithiumSigningSeedK>
H(
137 m_xof.
update(domsep.value());
148 return {std::move(
rho), std::move(rhoprime), std::move(k)};
157 m_xof_external.
clear();
159 return m_xof_external;
165 return m_xof_adapter->XOF128(seed, nonce);
171 return m_xof_adapter->XOF256(seed, nonce);
191 OutT
H_256(
size_t outbytes, InTs&&... ins)
const {
194 return m_xof.
output<OutT>(outbytes);
198 size_t m_commitment_hash_length_bytes;
199 size_t m_public_key_hash_bytes;
202 std::unique_ptr<DilithiumXOF> m_xof_adapter;
#define BOTAN_STATE_CHECK(expr)
#define BOTAN_ARG_CHECK(expr, msg)
static constexpr size_t MESSAGE_HASH_BYTES
static constexpr size_t SEED_SIGNING_KEY_BYTES
static constexpr size_t SEED_RHOPRIME_BYTES
static constexpr size_t SEED_RHO_BYTES
virtual void start(std::span< const uint8_t > user_context)
DilithiumMessageHash(DilithiumHashedPublicKey tr)
void update(std::span< const uint8_t > data)
virtual ~DilithiumMessageHash()=default
virtual bool is_valid_user_context(std::span< const uint8_t > user_context) const
virtual ~DilithiumXOF()=default
virtual Botan::XOF & XOF256(std::span< const uint8_t > seed, uint16_t nonce) const =0
virtual Botan::XOF & XOF128(std::span< const uint8_t > seed, uint16_t nonce) const =0
Dilithium_Symmetric_Primitives_Base(Dilithium_Symmetric_Primitives_Base &&)=delete
SHAKE_256_XOF & H(StrongSpan< const DilithiumCommitmentHash > seed) const
Dilithium_Symmetric_Primitives_Base & operator=(const Dilithium_Symmetric_Primitives_Base &)=delete
static std::unique_ptr< Dilithium_Symmetric_Primitives_Base > create(const DilithiumConstants &mode)
Dilithium_Symmetric_Primitives_Base(const Dilithium_Symmetric_Primitives_Base &)=delete
Botan::XOF & H(StrongSpan< const DilithiumSeedRho > seed, uint16_t nonce) const
Botan::XOF & H(StrongSpan< const DilithiumSeedRhoPrime > seed, uint16_t nonce) const
DilithiumHashedPublicKey H(StrongSpan< const DilithiumSerializedPublicKey > pk) const
virtual ~Dilithium_Symmetric_Primitives_Base()=default
virtual std::optional< std::array< uint8_t, 2 > > seed_expansion_domain_separator() const =0
std::tuple< DilithiumSeedRho, DilithiumSeedRhoPrime, DilithiumSigningSeedK > H(StrongSpan< const DilithiumSeedRandomness > seed) const
OutT H_256(size_t outbytes, InTs &&... ins) const
virtual DilithiumSeedRhoPrime H_maybe_randomized(StrongSpan< const DilithiumSigningSeedK > k, StrongSpan< const DilithiumMessageRepresentative > mu, std::optional< std::reference_wrapper< RandomNumberGenerator > > rng) const =0
Dilithium_Symmetric_Primitives_Base(const DilithiumConstants &mode, std::unique_ptr< DilithiumXOF > xof_adapter)
virtual StrongSpan< const DilithiumCommitmentHash > truncate_commitment_hash(StrongSpan< const DilithiumCommitmentHash > seed) const =0
DilithiumCommitmentHash H(StrongSpan< const DilithiumMessageRepresentative > mu, StrongSpan< const DilithiumSerializedCommitment > w1) const
virtual std::unique_ptr< DilithiumMessageHash > get_message_hash(DilithiumHashedPublicKey tr) const
Dilithium_Symmetric_Primitives_Base & operator=(Dilithium_Symmetric_Primitives_Base &&)=delete
std::string name() const final
void update(std::span< const uint8_t > input)
Helper class to create a RAII-style cleanup callback.
int(* update)(CTX *, const void *, CC_LONG len)
std::string fmt(std::string_view format, const T &... args)
Strong< std::vector< uint8_t >, struct DilithiumHashedPublicKey_ > DilithiumHashedPublicKey