21 std::optional<TreeNodeIndex> leaf_idx,
23 uint32_t total_tree_height,
30 const TreeNodeIndex max_idx((uint32_t(1) << total_tree_height) - 1);
34 std::vector<uint8_t> stack(total_tree_height * params.
n());
38 const uint32_t leaves_per_batch = std::min<uint32_t>(uint32_t(1) << total_tree_height, 128);
39 std::vector<uint8_t> leaves(leaves_per_batch * params.
n());
52 const uint32_t batch_pos = idx.get() % leaves_per_batch;
54 gen_leaves(leaves, idx + idx_offset, leaves_per_batch);
57 const auto current_node = std::span(leaves).subspan(batch_pos * params.
n(), params.
n());
61 uint32_t internal_idx_offset = idx_offset;
63 auto internal_leaf = leaf_idx;
67 if(h.get() == total_tree_height) {
75 if(internal_leaf.has_value() && (internal_idx ^ internal_leaf.value()) == 0x01U) {
76 const auto auth_path_location = out_auth_path.
get().subspan(h.get() * params.
n(), params.
n());
77 copy_mem(auth_path_location, current_node);
82 const auto stack_location = std::span(stack).subspan(h.get() * params.
n(), params.
n());
88 if((internal_idx & 1) == 0U && idx < max_idx) {
91 copy_mem(stack_location, current_node);
99 internal_idx_offset /= 2;
101 tree_address.
set_tree_index(internal_idx / 2 + internal_idx_offset);
103 hashes.
T(current_node, tree_address, stack_location, current_node);
106 if(internal_leaf.has_value()) {
107 internal_leaf.value() /= 2;
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 GenerateLeavesFunction &gen_leaves, Sphincs_Address &tree_address)
Strong< uint32_t, struct TreeNodeIndex_, EnableArithmeticWithPlainNumber > TreeNodeIndex
Index of an individual node inside an XMSS or FORS tree.
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)