112 std::optional<AuthPathSS> out_auth_path,
113 std::optional<TreeNodeIndex> leaf_idx,
119 Address& tree_address) {
121 BOTAN_ASSERT(out_auth_path.has_value() == leaf_idx.has_value(),
122 "Both leaf index and auth path buffer is given or neither.");
123 const bool is_signing = leaf_idx.has_value();
124 BOTAN_ASSERT_NOMSG(!is_signing || out_auth_path.value().size() == node_size * total_tree_height.
get());
128 std::vector<TreeNode> last_visited_left_child_at_layer(total_tree_height.
get(), TreeNode(node_size));
130 TreeNode current_node(node_size);
141 uint32_t internal_idx_offset = idx_offset;
143 auto internal_leaf = leaf_idx;
147 if(h == total_tree_height) {
155 if(is_signing && (internal_idx ^ internal_leaf.value()) == 0x01U) {
156 auto auth_path_location = out_auth_path.value().get().subspan(h.get() * node_size, node_size);
157 copy_mem(auth_path_location, current_node);
164 if((internal_idx & 1) == 0U && idx < max_idx) {
167 copy_mem(last_visited_left_child_at_layer.at(h.get()), current_node);
175 internal_idx_offset /= 2;
176 tree_address.set_address(h + 1, internal_idx / 2 + internal_idx_offset);
178 node_pair_hash(current_node, tree_address, last_visited_left_child_at_layer.at(h.get()), current_node);
181 if(internal_leaf.has_value()) {
182 internal_leaf.value() /= 2;
212 AuthPathSS authentication_path,
219 Address& tree_address) {
221 BOTAN_ASSERT_NOMSG(authentication_path.size() == node_size *
static_cast<size_t>(total_tree_height.
get()));
243 right = auth_path.
take<TreeNode>(node_size);
245 if((leaf_idx & 1) == 1U) {
246 std::swap(left, right);
251 tree_address.set_address(i + 1, leaf_idx + idx_offset);
253 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)