Botan 3.6.1
Crypto and TLS for C&
Botan::Sphincs_Hash_Functions Class Referenceabstract

#include <sp_hash.h>

Inheritance diagram for Botan::Sphincs_Hash_Functions:
Botan::Sphincs_Hash_Functions_Sha2 Botan::Sphincs_Hash_Functions_Shake

Public Member Functions

std::tuple< SphincsHashedMessage, XmssTreeIndexInLayer, TreeNodeIndexH_msg (StrongSpan< const SphincsMessageRandomness > r, const SphincsTreeNode &root, const SphincsMessageInternal &message)
 
virtual std::string msg_hash_function_name () const =0
 
void PRF (StrongSpan< ForsLeafSecret > out, const SphincsSecretSeed &sk_seed, const Sphincs_Address &address)
 
void PRF (StrongSpan< WotsNode > out, const SphincsSecretSeed &sk_seed, const Sphincs_Address &address)
 
virtual void PRF_msg (StrongSpan< SphincsMessageRandomness > out, StrongSpan< const SphincsSecretPRF > sk_prf, StrongSpan< const SphincsOptionalRandomness > opt_rand, const SphincsMessageInternal &msg)=0
 
template<typename OutT = std::vector<uint8_t>, typename... BufferTs>
OutT T (const Sphincs_Address &address, BufferTs &&... in)
 
template<typename... BufferTs>
void T (std::span< uint8_t > out, const Sphincs_Address &address, BufferTs &&... in)
 
virtual ~Sphincs_Hash_Functions ()=default
 

Static Public Member Functions

static std::unique_ptr< Sphincs_Hash_Functionscreate (const Sphincs_Parameters &sphincs_params, const SphincsPublicSeed &pub_seed)
 

Protected Member Functions

virtual std::vector< uint8_t > H_msg_digest (StrongSpan< const SphincsMessageRandomness > r, const SphincsTreeNode &root, const SphincsMessageInternal &message)=0
 
 Sphincs_Hash_Functions (const Sphincs_Parameters &sphincs_params, const SphincsPublicSeed &pub_seed)
 
virtual HashFunctiontweak_hash (const Sphincs_Address &address, size_t input_length)=0
 

Protected Attributes

const SphincsPublicSeedm_pub_seed
 
const Sphincs_Parametersm_sphincs_params
 

Detailed Description

A collection of pseudorandom hash functions required for SLH-DSA computations. See FIPS 205, Section 11.2.1 and 11.2.2.

Definition at line 23 of file sp_hash.h.

Constructor & Destructor Documentation

◆ ~Sphincs_Hash_Functions()

virtual Botan::Sphincs_Hash_Functions::~Sphincs_Hash_Functions ( )
virtualdefault

◆ Sphincs_Hash_Functions()

Botan::Sphincs_Hash_Functions::Sphincs_Hash_Functions ( const Sphincs_Parameters & sphincs_params,
const SphincsPublicSeed & pub_seed )
protected

Definition at line 30 of file sp_hash.cpp.

31 :
32 m_sphincs_params(sphincs_params), m_pub_seed(pub_seed) {}
const SphincsPublicSeed & m_pub_seed
Definition sp_hash.h:103
const Sphincs_Parameters & m_sphincs_params
Definition sp_hash.h:102

Member Function Documentation

◆ create()

std::unique_ptr< Sphincs_Hash_Functions > Botan::Sphincs_Hash_Functions::create ( const Sphincs_Parameters & sphincs_params,
const SphincsPublicSeed & pub_seed )
static

Creates a Sphincs_Hash_Functions object instantiating the hash functions used for the specified sphincs_params. The pub_seed is used to seed the hash functions (possibly padded). This is pre-computed and the respective state is copied on the further calls on H(seed) with tweak_hash, i.e., T and PRF.

Definition at line 34 of file sp_hash.cpp.

35 {
36 switch(sphincs_params.hash_type()) {
38#if defined(BOTAN_HAS_SPHINCS_PLUS_SHA2_BASE)
39 return std::make_unique<Sphincs_Hash_Functions_Sha2>(sphincs_params, pub_seed);
40#else
41 throw Not_Implemented("SLH-DSA (or SPHINCS+) with SHA-256 is not available in this build");
42#endif
43
45#if defined(BOTAN_HAS_SPHINCS_PLUS_SHAKE_BASE)
46 return std::make_unique<Sphincs_Hash_Functions_Shake>(sphincs_params, pub_seed);
47#else
48 throw Not_Implemented("SLH-DSA (or SPHINCS+) with SHAKE is not available in this build");
49#endif
50
52 throw Not_Implemented("Haraka is not implemented");
53 }
55}
#define BOTAN_ASSERT_UNREACHABLE()
Definition assert.h:137
@ Haraka
Haraka is currently not supported.

References BOTAN_ASSERT_UNREACHABLE, Botan::Haraka, Botan::Sphincs_Parameters::hash_type(), Botan::Sha256, and Botan::Shake256.

Referenced by Botan::SphincsPlus_PrivateKey::SphincsPlus_PrivateKey().

◆ H_msg()

std::tuple< SphincsHashedMessage, XmssTreeIndexInLayer, TreeNodeIndex > Botan::Sphincs_Hash_Functions::H_msg ( StrongSpan< const SphincsMessageRandomness > r,
const SphincsTreeNode & root,
const SphincsMessageInternal & message )

Definition at line 78 of file sp_hash.cpp.

79 {
80 const auto digest = H_msg_digest(r, root, message);
81
82 // The following calculates the message digest and indices from the
83 // raw message digest. See FIPS 205, Algorithm 19, Line 5-10.
84 const auto& p = m_sphincs_params;
85 BufferSlicer s(digest);
86 auto msg_hash = s.copy<SphincsHashedMessage>(p.fors_message_bytes());
87 auto tree_index_bytes = s.take(p.tree_digest_bytes());
88 auto leaf_index_bytes = s.take(p.leaf_digest_bytes());
89 BOTAN_ASSERT_NOMSG(s.empty());
90
91 auto tree_index = from_first_n_bits<XmssTreeIndexInLayer>(p.h() - p.xmss_tree_height(), tree_index_bytes);
92 auto leaf_index = from_first_n_bits<TreeNodeIndex>(p.xmss_tree_height(), leaf_index_bytes);
93 return {std::move(msg_hash), tree_index, leaf_index};
94}
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:59
virtual std::vector< uint8_t > H_msg_digest(StrongSpan< const SphincsMessageRandomness > r, const SphincsTreeNode &root, const SphincsMessageInternal &message)=0
Gf448Elem root(const Gf448Elem &elem)
Compute the root of elem in the field.
Strong< std::vector< uint8_t >, struct SphincsHashedMessage_ > SphincsHashedMessage
Definition sp_types.h:59

References BOTAN_ASSERT_NOMSG, Botan::BufferSlicer::copy(), Botan::BufferSlicer::empty(), H_msg_digest(), m_sphincs_params, Botan::root(), and Botan::BufferSlicer::take().

◆ H_msg_digest()

virtual std::vector< uint8_t > Botan::Sphincs_Hash_Functions::H_msg_digest ( StrongSpan< const SphincsMessageRandomness > r,
const SphincsTreeNode & root,
const SphincsMessageInternal & message )
protectedpure virtual

Referenced by H_msg().

◆ msg_hash_function_name()

virtual std::string Botan::Sphincs_Hash_Functions::msg_hash_function_name ( ) const
pure virtual

◆ PRF() [1/2]

void Botan::Sphincs_Hash_Functions::PRF ( StrongSpan< ForsLeafSecret > out,
const SphincsSecretSeed & sk_seed,
const Sphincs_Address & address )
inline

Definition at line 70 of file sp_hash.h.

70 {
71 T(out, address, sk_seed);
72 }
FE_25519 T
Definition ge.cpp:34

References T.

Referenced by Botan::fors_sign_and_pkgen(), and Botan::wots_sign_and_pkgen().

◆ PRF() [2/2]

void Botan::Sphincs_Hash_Functions::PRF ( StrongSpan< WotsNode > out,
const SphincsSecretSeed & sk_seed,
const Sphincs_Address & address )
inline

Definition at line 74 of file sp_hash.h.

74 {
75 T(out, address, sk_seed);
76 }

References T.

◆ PRF_msg()

virtual void Botan::Sphincs_Hash_Functions::PRF_msg ( StrongSpan< SphincsMessageRandomness > out,
StrongSpan< const SphincsSecretPRF > sk_prf,
StrongSpan< const SphincsOptionalRandomness > opt_rand,
const SphincsMessageInternal & msg )
pure virtual

Using SK.PRF, the optional randomness, and a message, computes the message random R, and the tree and leaf indices.

Parameters
outoutput location for the message hash
sk_prfSK.PRF
opt_randoptional randomness
msgmessage

Implemented in Botan::Sphincs_Hash_Functions_Sha2, and Botan::Sphincs_Hash_Functions_Shake.

◆ T() [1/2]

template<typename OutT = std::vector<uint8_t>, typename... BufferTs>
OutT Botan::Sphincs_Hash_Functions::T ( const Sphincs_Address & address,
BufferTs &&... in )
inline

Definition at line 64 of file sp_hash.h.

64 {
65 OutT t(m_sphincs_params.n());
66 T(t, address, std::forward<BufferTs>(in)...);
67 return t;
68 }

References T.

◆ T() [2/2]

template<typename... BufferTs>
void Botan::Sphincs_Hash_Functions::T ( std::span< uint8_t > out,
const Sphincs_Address & address,
BufferTs &&... in )
inline

Definition at line 57 of file sp_hash.h.

57 {
58 auto& hash = tweak_hash(address, (std::forward<BufferTs>(in).size() + ...));
59 (hash.update(std::forward<BufferTs>(in)), ...);
60 hash.final(out);
61 }
virtual HashFunction & tweak_hash(const Sphincs_Address &address, size_t input_length)=0

Referenced by Botan::compute_root(), Botan::fors_public_key_from_signature(), Botan::fors_sign_and_pkgen(), Botan::ht_verify(), Botan::treehash(), and Botan::wots_sign_and_pkgen().

◆ tweak_hash()

virtual HashFunction & Botan::Sphincs_Hash_Functions::tweak_hash ( const Sphincs_Address & address,
size_t input_length )
protectedpure virtual

Prepare the underlying hash function for hashing any given input depending on the expected input length.

Parameters
addressthe SLH-DSA address of the hash to be tweaked
input_lengththe input buffer length that will be processed with the tweaked hash (typically N or 2*N)
Returns
a reference to a Botan::HashFunction that is preconditioned with the given tweaking parameters.
Note
Callers are expected to finalize (i.e. reset) the returned HashFunction after use.

Member Data Documentation

◆ m_pub_seed

const SphincsPublicSeed& Botan::Sphincs_Hash_Functions::m_pub_seed
protected

◆ m_sphincs_params

const Sphincs_Parameters& Botan::Sphincs_Hash_Functions::m_sphincs_params
protected

Definition at line 102 of file sp_hash.h.

Referenced by H_msg().


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