Botan 3.4.0
Crypto and TLS for C&
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
Botan::Sphincs_Hash_Functions_Shake Class Reference

#include <sp_hash_shake.h>

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

Public Member Functions

std::tuple< SphincsHashedMessage, XmssTreeIndexInLayer, TreeNodeIndexH_msg (StrongSpan< const SphincsMessageRandomness > r, const SphincsTreeNode &root, std::span< const uint8_t > message)
 
std::string msg_hash_function_name () const override
 
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)
 
void PRF_msg (StrongSpan< SphincsMessageRandomness > out, const SphincsSecretPRF &sk_prf, const SphincsOptionalRandomness &opt_rand, std::span< const uint8_t > in) override
 
 Sphincs_Hash_Functions_Shake (const Sphincs_Parameters &sphincs_params, const SphincsPublicSeed &pub_seed)
 
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)
 

Static Public Member Functions

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

Protected Attributes

const SphincsPublicSeedm_pub_seed
 
const Sphincs_Parametersm_sphincs_params
 

Detailed Description

Implementation of SPHINCS+ hash function abstraction for SHAKE256

Definition at line 21 of file sp_hash_shake.h.

Constructor & Destructor Documentation

◆ Sphincs_Hash_Functions_Shake()

Botan::Sphincs_Hash_Functions_Shake::Sphincs_Hash_Functions_Shake ( const Sphincs_Parameters & sphincs_params,
const SphincsPublicSeed & pub_seed )
inline

Definition at line 42 of file sp_hash_shake.h.

42 :
43 Sphincs_Hash_Functions(sphincs_params, pub_seed),
44 m_seeded_hash(sphincs_params.n() * 8),
45 m_hash(sphincs_params.n() * 8),
46 m_h_msg_hash(8 * sphincs_params.h_msg_digest_bytes()) {
47 m_seeded_hash.update(m_pub_seed);
48 }
void update(const uint8_t in[], size_t length)
Definition buf_comp.h:35
const SphincsPublicSeed & m_pub_seed
Definition sp_hash.h:102
Sphincs_Hash_Functions(const Sphincs_Parameters &sphincs_params, const SphincsPublicSeed &pub_seed)
Definition sp_hash.cpp:30

References Botan::Sphincs_Hash_Functions::m_pub_seed, and Botan::Buffered_Computation::update().

Member Function Documentation

◆ create()

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

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_WITH_SHA2)
39 return std::make_unique<Sphincs_Hash_Functions_Sha2>(sphincs_params, pub_seed);
40#else
41 throw Not_Implemented("SPHINCS+ with SHA-256 is not available in this build");
42#endif
43
45#if defined(BOTAN_HAS_SPHINCS_PLUS_WITH_SHAKE)
46 return std::make_unique<Sphincs_Hash_Functions_Shake>(sphincs_params, pub_seed);
47#else
48 throw Not_Implemented("SPHINCS+ with SHAKE is not available in this build");
49#endif
50
52 throw Not_Implemented("Haraka is not yet 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,
std::span< const uint8_t > message )
inherited

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 Algorithm 20 (spx_sign) in SPHINCS+ 3.1
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, std::span< const uint8_t > message)=0
const Sphincs_Parameters & m_sphincs_params
Definition sp_hash.h:101
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:45

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

◆ msg_hash_function_name()

std::string Botan::Sphincs_Hash_Functions_Shake::msg_hash_function_name ( ) const
inlineoverridevirtual

Implements Botan::Sphincs_Hash_Functions.

Definition at line 60 of file sp_hash_shake.h.

60{ return m_h_msg_hash.name(); }
std::string name() const override
Definition shake.cpp:49

References Botan::SHAKE_256::name().

◆ PRF() [1/2]

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

Definition at line 69 of file sp_hash.h.

69 {
70 T(out, address, sk_seed);
71 }
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 )
inlineinherited

Definition at line 73 of file sp_hash.h.

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

References T.

◆ PRF_msg()

void Botan::Sphincs_Hash_Functions_Shake::PRF_msg ( StrongSpan< SphincsMessageRandomness > out,
const SphincsSecretPRF & sk_prf,
const SphincsOptionalRandomness & opt_rand,
std::span< const uint8_t > msg )
inlineoverridevirtual

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

Implements Botan::Sphincs_Hash_Functions.

Definition at line 50 of file sp_hash_shake.h.

53 {
54 m_hash.update(sk_prf);
55 m_hash.update(opt_rand);
56 m_hash.update(in);
57 m_hash.final(out);
58 }
void final(uint8_t out[])
Definition buf_comp.h:70

References Botan::Buffered_Computation::final(), and Botan::Buffered_Computation::update().

◆ T() [1/2]

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

Definition at line 63 of file sp_hash.h.

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

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 )
inlineinherited

Definition at line 56 of file sp_hash.h.

56 {
57 auto& hash = tweak_hash(address, (std::forward<BufferTs>(in).size() + ...));
58 (hash.update(std::forward<BufferTs>(in)), ...);
59 hash.final(out);
60 }
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().

Member Data Documentation

◆ m_pub_seed

const SphincsPublicSeed& Botan::Sphincs_Hash_Functions::m_pub_seed
protectedinherited

Definition at line 102 of file sp_hash.h.

Referenced by Sphincs_Hash_Functions_Shake().

◆ m_sphincs_params

const Sphincs_Parameters& Botan::Sphincs_Hash_Functions::m_sphincs_params
protectedinherited

Definition at line 101 of file sp_hash.h.

Referenced by Botan::Sphincs_Hash_Functions::H_msg().


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