Botan 3.6.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;
23class Sphincs_Hash_Functions;
24
25using GenerateLeafFunction = std::function<void(StrongSpan<SphincsTreeNode> /* leaf out parameter */, TreeNodeIndex)>;
26
27/**
28 * Implements a generic Merkle tree hash. Will be used for both FORS and XMSS
29 * signatures.
30 * @p gen_leaf is used to create leaf nodes in the respective trees.
31 * Additionally XMSS uses the gen_leaf logic to store the WOTS Signature in the
32 * main SLH-DSA signature. The @p leaf_idx is the index of leaf to sign. If
33 * only the root node must be computed (without a signature), the @p leaf_idx is
34 * set to std::nullopt.
35 */
38 const Sphincs_Parameters& params,
40 std::optional<TreeNodeIndex> leaf_idx,
41 uint32_t idx_offset,
42 uint32_t tree_height,
43 const GenerateLeafFunction& gen_leaf,
44 Sphincs_Address& tree_address);
45
46/**
47 * Using a leaf node and the authentication path (neighbor nodes on the way from
48 * leaf to root), computes the the root node of the respective tree. This
49 * function is generic and used by FORS and XMSS in the SLH-DSA verification
50 * logic.
51 */
53 const Sphincs_Parameters& params,
55 const SphincsTreeNode& leaf,
56 TreeNodeIndex leaf_idx,
57 uint32_t idx_offset,
59 uint32_t tree_height,
60 Sphincs_Address& tree_address);
61
62} // namespace Botan
63
64#endif
#define BOTAN_TEST_API
Definition compiler.h:51
std::function< void(StrongSpan< SphincsTreeNode >, TreeNodeIndex)> GenerateLeafFunction
Definition sp_treehash.h:25
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 GenerateLeafFunction &gen_leaf, Sphincs_Address &tree_address)
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)