Botan 3.14.1
Crypto and TLS for C&
sp_treehash.h
Go to the documentation of this file.
1/*
2 * SLH-DSA treehash logic
3 * (C) 2023 Jack Lloyd
4 * 2023 Fabian Albert, René Meusel, Amos Treiber - Rohde & Schwarz Cybersecurity
5 *
6 * Parts of this file have been adapted from https://github.com/sphincs/sphincsplus
7 *
8 * Botan is released under the Simplified BSD License (see license.txt)
9 **/
10
11#ifndef BOTAN_SP_TREEHASH_H_
12#define BOTAN_SP_TREEHASH_H_
13
14#include <botan/sp_parameters.h>
15#include <botan/internal/sp_types.h>
16
17#include <functional>
18#include <optional>
19
20namespace Botan {
21
22class Sphincs_Address;
24
25/**
26 * Creates the nodes of @p count consecutive leaves, starting at the leaf with
27 * address index @p first, into the output buffer. Implementations must fully
28 * specify the hash addresses used for the leaves.
29 */
31 std::function<void(std::span<uint8_t> /* leaves out parameter */, TreeNodeIndex /* first */, uint32_t /* count */)>;
32
33/**
34 * Implements a generic Merkle tree hash. Will be used for both FORS and XMSS
35 * signatures.
36 * @p gen_leaves is used to create batches of leaf nodes in the respective trees.
37 * Additionally XMSS uses the gen_leaves logic to store the WOTS Signature in the
38 * main SLH-DSA signature. The @p leaf_idx is the index of leaf to sign. If
39 * only the root node must be computed (without a signature), the @p leaf_idx is
40 * set to std::nullopt.
41 */
44 const Sphincs_Parameters& params,
46 std::optional<TreeNodeIndex> leaf_idx,
47 uint32_t idx_offset,
48 uint32_t tree_height,
49 const GenerateLeavesFunction& gen_leaves,
50 Sphincs_Address& tree_address);
51
52/**
53 * Using a leaf node and the authentication path (neighbor nodes on the way from
54 * leaf to root), computes the the root node of the respective tree. This
55 * function is generic and used by FORS and XMSS in the SLH-DSA verification
56 * logic.
57 */
59 const Sphincs_Parameters& params,
61 const SphincsTreeNode& leaf,
62 TreeNodeIndex leaf_idx,
63 uint32_t idx_offset,
65 uint32_t tree_height,
66 Sphincs_Address& tree_address);
67
68} // namespace Botan
69
70#endif
#define BOTAN_TEST_API
Definition api.h:41
Strong< std::vector< uint8_t >, struct SphincsTreeNode_ > SphincsTreeNode
Either an XMSS or FORS tree node or leaf.
Definition sp_types.h:70
std::function< void(std::span< uint8_t >, TreeNodeIndex, uint32_t)> GenerateLeavesFunction
Definition sp_treehash.h:30
void treehash(StrongSpan< SphincsTreeNode > out_root, StrongSpan< SphincsAuthenticationPath > out_auth_path, const Sphincs_Parameters &params, 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.
Definition sp_types.h:92
void compute_root(StrongSpan< SphincsTreeNode > out, const Sphincs_Parameters &params, 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)