116 std::optional<AuthPathSS> out_auth_path,
117 std::optional<TreeNodeIndex> leaf_idx,
123 Address& tree_address) {
125 BOTAN_ASSERT(out_auth_path.has_value() == leaf_idx.has_value(),
126 "Both leaf index and auth path buffer is given or neither.");
127 const bool is_signing = leaf_idx.has_value();
128 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);
145 uint32_t internal_idx_offset = idx_offset;
147 auto internal_leaf = leaf_idx;
151 if(h == total_tree_height) {
159 if(is_signing && (internal_idx ^ internal_leaf.value()) == 0x01U) {
160 auto auth_path_location = out_auth_path.value().get().subspan(h.get() * node_size, node_size);
161 copy_mem(auth_path_location, current_node);
168 if((internal_idx & 1) == 0U && idx < max_idx) {
171 copy_mem(last_visited_left_child_at_layer.at(h.get()), current_node);
179 internal_idx_offset /= 2;
180 tree_address.set_address(h + 1, internal_idx / 2 + internal_idx_offset);
182 node_pair_hash(current_node, tree_address, last_visited_left_child_at_layer.at(h.get()), current_node);
185 if(internal_leaf.has_value()) {
186 internal_leaf.value() /= 2;
216 AuthPathSS authentication_path,
223 Address& tree_address) {
225 BOTAN_ASSERT_NOMSG(authentication_path.size() == node_size *
static_cast<size_t>(total_tree_height.
get()));
247 right = auth_path.
take<TreeNode>(node_size);
249 if((leaf_idx & 1) == 1U) {
250 std::swap(left, right);
255 tree_address.set_address(i + 1, leaf_idx + idx_offset);
257 node_pair_hash(out_root, tree_address, left, right);
Strong< uint32_t, struct TreeNodeIndex_, EnableArithmeticWithPlainNumber > TreeNodeIndex
Index of an individual node inside an XMSS or FORS tree.
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)