9#include <botan/internal/sp_treehash.h>
11#include <botan/internal/sp_address.h>
12#include <botan/internal/sp_hash.h>
13#include <botan/internal/stl_util.h>
21 std::optional<TreeNodeIndex> leaf_idx,
23 uint32_t total_tree_height,
29 const TreeNodeIndex max_idx(uint32_t((1 << total_tree_height) - 1));
31 std::vector<uint8_t> stack(total_tree_height * params.
n());
46 gen_leaf(current_node, idx + idx_offset);
50 uint32_t internal_idx_offset = idx_offset;
52 auto internal_leaf = leaf_idx;
56 if(h.get() == total_tree_height) {
64 if(internal_leaf.has_value() && (internal_idx ^ internal_leaf.value()) == 0x01U) {
65 auto auth_path_location = out_auth_path.
get().subspan(h.get() * params.
n(), params.
n());
66 copy_mem(auth_path_location, current_node);
71 auto stack_location = std::span(stack).subspan(h.get() * params.
n(), params.
n());
77 if((internal_idx & 1) == 0U && idx < max_idx) {
80 copy_mem(stack_location, current_node);
88 internal_idx_offset /= 2;
90 tree_address.
set_tree_index(internal_idx / 2 + internal_idx_offset);
92 hashes.
T(current_node, tree_address, stack_location, current_node);
95 if(internal_leaf.has_value()) {
96 internal_leaf.value() /= 2;
109 uint32_t total_tree_height,
136 if((leaf_idx & 1) == 1U) {
137 std::swap(left, right);
144 hashes.
T(out, tree_address, left, right);
#define BOTAN_ASSERT_NOMSG(expr)
std::span< const uint8_t > take(const size_t count)
Sphincs_Address & set_tree_height(TreeLayerIndex tree_height)
Sphincs_Address & set_tree_index(TreeNodeIndex tree_index)
void T(std::span< uint8_t > out, const Sphincs_Address &address, BufferTs &&... in)
underlying_span get() const
decltype(auto) size() const noexcept(noexcept(this->m_span.size()))
size_type size() const noexcept(noexcept(this->get().size()))
Strong< std::vector< uint8_t >, struct SphincsTreeNode_ > SphincsTreeNode
Either an XMSS or FORS tree node or leaf.
std::function< void(StrongSpan< SphincsTreeNode >, TreeNodeIndex)> GenerateLeafFunction
Strong< uint32_t, struct TreeNodeIndex_, EnableArithmeticWithPlainNumber > TreeNodeIndex
Index of an individual node inside an XMSS or FORS tree.
Strong< uint32_t, struct TreeLayerIndex_, EnableArithmeticWithPlainNumber > TreeLayerIndex
Index of the layer within a FORS/XMSS tree.
constexpr void copy_mem(T *out, const T *in, size_t n)
void treehash(StrongSpan< SphincsTreeNode > out_root, StrongSpan< SphincsAuthenticationPath > out_auth_path, const Sphincs_Parameters ¶ms, Sphincs_Hash_Functions &hashes, std::optional< TreeNodeIndex > leaf_idx, uint32_t idx_offset, uint32_t total_tree_height, const GenerateLeafFunction &gen_leaf, Sphincs_Address &tree_address)
void compute_root(StrongSpan< SphincsTreeNode > out, const Sphincs_Parameters ¶ms, Sphincs_Hash_Functions &hashes, const SphincsTreeNode &leaf, TreeNodeIndex leaf_idx, uint32_t idx_offset, StrongSpan< const SphincsAuthenticationPath > authentication_path, uint32_t total_tree_height, Sphincs_Address &tree_address)