113 std::optional<AuthPathSS> out_auth_path,
114 std::optional<TreeNodeIndex> leaf_idx,
120 Address& tree_address) {
122 BOTAN_ASSERT(out_auth_path.has_value() == leaf_idx.has_value(),
123 "Both leaf index and auth path buffer is given or neither.");
124 const bool is_signing = leaf_idx.has_value();
125 BOTAN_ASSERT_NOMSG(!is_signing || out_auth_path.value().size() == node_size * total_tree_height.
get());
132 std::vector<TreeNode> last_visited_left_child_at_layer(total_tree_height.
get(), TreeNode(node_size));
134 TreeNode current_node(node_size);
139 const uint32_t leaves_per_batch = std::min<uint32_t>(uint32_t(1) << total_tree_height.
get(), 32);
140 std::vector<uint8_t> leaves(leaves_per_batch * node_size);
146 const uint32_t batch_pos = idx.get() % leaves_per_batch;
148 gen_leaves(std::span(leaves), idx + idx_offset, leaves_per_batch);
150 copy_mem(current_node, std::span(leaves).subspan(batch_pos * node_size, node_size));
154 uint32_t internal_idx_offset = idx_offset;
156 auto internal_leaf = leaf_idx;
160 if(h == total_tree_height) {
168 if(is_signing && (internal_idx ^ internal_leaf.value()) == 0x01U) {
169 const auto auth_path_location = out_auth_path.value().get().subspan(h.get() * node_size, node_size);
170 copy_mem(auth_path_location, current_node);
177 if((internal_idx & 1) == 0U && idx < max_idx) {
180 copy_mem(last_visited_left_child_at_layer.at(h.get()), current_node);
188 internal_idx_offset /= 2;
189 tree_address.set_address(h + 1, internal_idx / 2 + internal_idx_offset);
191 node_pair_hash(current_node, tree_address, last_visited_left_child_at_layer.at(h.get()), current_node);
194 if(internal_leaf.has_value()) {
195 internal_leaf.value() /= 2;
225 AuthPathSS authentication_path,
232 Address& tree_address) {
234 BOTAN_ASSERT_NOMSG(authentication_path.size() == node_size *
static_cast<size_t>(total_tree_height.
get()));
256 right = auth_path.
take<TreeNode>(node_size);
258 if((leaf_idx & 1) == 1U) {
259 std::swap(left, right);
264 tree_address.set_address(i + 1, leaf_idx + idx_offset);
266 node_pair_hash(out_root, tree_address, left, right);
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)