9#include <botan/internal/sp_hash.h>
11#include <botan/internal/stl_util.h>
13#include <botan/assert.h>
14#include <botan/exceptn.h>
15#include <botan/hash.h>
16#include <botan/sp_parameters.h>
18#if defined(BOTAN_HAS_SPHINCS_PLUS_SHAKE_BASE)
19 #include <botan/internal/sp_hash_shake.h>
22#if defined(BOTAN_HAS_SPHINCS_PLUS_SHA2_BASE)
23 #include <botan/internal/sp_hash_sha2.h>
32 m_sphincs_params(sphincs_params), m_pub_seed(pub_seed) {}
38#if defined(BOTAN_HAS_SPHINCS_PLUS_SHA2_BASE)
39 return std::make_unique<Sphincs_Hash_Functions_Sha2>(sphincs_params, pub_seed);
41 throw Not_Implemented(
"SLH-DSA (or SPHINCS+) with SHA-256 is not available in this build");
45#if defined(BOTAN_HAS_SPHINCS_PLUS_SHAKE_BASE)
46 return std::make_unique<Sphincs_Hash_Functions_Shake>(sphincs_params, pub_seed);
48 throw Not_Implemented(
"SLH-DSA (or SPHINCS+) with SHAKE is not available in this build");
60T from_first_n_bits(
const uint32_t nbits, std::span<const uint8_t> bytes) {
61 using wrapped_type =
typename T::wrapped_type;
63 constexpr const auto outsize =
sizeof(wrapped_type);
69 std::array<uint8_t, outsize> normalized_bytes = {};
70 std::copy(bytes.rbegin(), bytes.rend(), normalized_bytes.rbegin());
73 return T(bits & (~wrapped_type(0) >> (8 * outsize - nbits)));
87 auto tree_index_bytes = s.
take(p.tree_digest_bytes());
88 auto leaf_index_bytes = s.
take(p.leaf_digest_bytes());
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};
#define BOTAN_ASSERT_NOMSG(expr)
#define BOTAN_ASSERT_UNREACHABLE()
auto copy(const size_t count)
std::span< const uint8_t > take(const size_t count)
const Sphincs_Parameters & m_sphincs_params
Sphincs_Hash_Functions(const Sphincs_Parameters &sphincs_params, const SphincsPublicSeed &pub_seed)
std::tuple< SphincsHashedMessage, XmssTreeIndexInLayer, TreeNodeIndex > H_msg(StrongSpan< const SphincsMessageRandomness > r, const SphincsTreeNode &root, const SphincsMessageInternal &message)
static std::unique_ptr< Sphincs_Hash_Functions > create(const Sphincs_Parameters &sphincs_params, const SphincsPublicSeed &pub_seed)
virtual std::vector< uint8_t > H_msg_digest(StrongSpan< const SphincsMessageRandomness > r, const SphincsTreeNode &root, const SphincsMessageInternal &message)=0
Sphincs_Hash_Type hash_type() const
Gf448Elem root(const Gf448Elem &elem)
Compute the root of elem in the field.
@ Haraka
Haraka is currently not supported.
constexpr auto load_be(ParamTs &&... params)
M' representation of FIPS 205 (the input to slh_sign_internal and slh_verify_internal)