Botan 3.14.1
Crypto and TLS for C&
xmss_tree_builder.h
Go to the documentation of this file.
1/*
2 * XMSS Tree Builder
3 * (C) 2016,2017,2018 Matthias Gierlings
4 * (C) 2019,2026 Jack Lloyd
5 * (C) 2023 René Meusel - Rohde & Schwarz Cybersecurity
6 * (C) 2026 Johannes Roth - MTG AG
7 *
8 * Botan is released under the Simplified BSD License (see license.txt)
9 **/
10
11#ifndef BOTAN_XMSS_TREE_BUILDER_H_
12#define BOTAN_XMSS_TREE_BUILDER_H_
13
14#include <botan/secmem.h>
15#include <botan/xmss.h>
16#include <botan/internal/xmss_address.h>
17#include <botan/internal/xmss_wots.h>
18#include <span>
19
20namespace Botan {
21
22class XMSS_Hash;
23
24/**
25 * Bundles the inputs needed to compute the internal nodes (and root) of an
26 * XMSS Merkle tree: the WOTS+ parameters and the public/private seeds. The
27 * same computation is needed both during key generation (before the immutable
28 * public key exists) and during signing (auth path computation), so it is
29 * factored out here and shared via thin wrappers on XMSS_PrivateKey. It is
30 * also used by XMSS^MT, which builds one XMSS tree per hypertree node; the
31 * caller then presets the layer/tree fields of the passed XMSS_Address.
32 **/
33class XMSS_Tree_Builder final {
34 public:
36 WOTS_Derivation_Method wots_derivation_method,
38 const secure_vector<uint8_t>& private_seed) :
39 m_wots_params(wots_params),
40 m_wots_derivation_method(wots_derivation_method),
41 m_public_seed(public_seed),
42 m_private_seed(private_seed) {}
43
44 secure_vector<uint8_t> tree_hash(size_t start_idx,
45 size_t target_node_height,
46 const XMSS_Address& adrs,
47 XMSS_Hash& hash) const;
48
50
51 const secure_vector<uint8_t>& public_seed() const { return m_public_seed; }
52
53 private:
54 /**
55 * Compute the leaves [start_idx, start_idx + count) of the tree into
56 * leaves (count * n bytes)
57 */
58 void compute_leaves(
59 std::span<uint8_t> leaves, size_t start_idx, size_t count, const XMSS_Address& adrs, XMSS_Hash& hash) const;
60
61 /**
62 * Derive the WOTS+ private keys of addrs.size() / len leaves into
63 * sks; addrs holds the OTS hash address of every chain of every leaf
64 */
65 void wots_private_keys(std::span<uint8_t> sks, std::span<const XMSS_Address> addrs, XMSS_Hash& hash) const;
66
67 XMSS_WOTS_Parameters m_wots_params;
68 WOTS_Derivation_Method m_wots_derivation_method;
69 const secure_vector<uint8_t>& m_public_seed;
70 const secure_vector<uint8_t>& m_private_seed;
71};
72
73} // namespace Botan
74
75#endif
secure_vector< uint8_t > tree_hash(size_t start_idx, size_t target_node_height, const XMSS_Address &adrs, XMSS_Hash &hash) const
XMSS_WOTS_PrivateKey wots_private_key_for(const XMSS_Address &adrs, XMSS_Hash &hash) const
XMSS_Tree_Builder(const XMSS_WOTS_Parameters &wots_params, WOTS_Derivation_Method wots_derivation_method, const secure_vector< uint8_t > &public_seed, const secure_vector< uint8_t > &private_seed)
const secure_vector< uint8_t > & public_seed() const
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:128
WOTS_Derivation_Method
Definition xmss.h:151