Botan 3.14.1
Crypto and TLS for C&
Botan::XMSS_Tree_Builder Class Referencefinal

#include <xmss_tree_builder.h>

Public Member Functions

const secure_vector< uint8_t > & public_seed () const
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)

Detailed Description

Bundles the inputs needed to compute the internal nodes (and root) of an XMSS Merkle tree: the WOTS+ parameters and the public/private seeds. The same computation is needed both during key generation (before the immutable public key exists) and during signing (auth path computation), so it is factored out here and shared via thin wrappers on XMSS_PrivateKey. It is also used by XMSS^MT, which builds one XMSS tree per hypertree node; the caller then presets the layer/tree fields of the passed XMSS_Address.

Definition at line 33 of file xmss_tree_builder.h.

Constructor & Destructor Documentation

◆ XMSS_Tree_Builder()

Botan::XMSS_Tree_Builder::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 )
inline

Definition at line 35 of file xmss_tree_builder.h.

38 :
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) {}
const secure_vector< uint8_t > & public_seed() const

References public_seed().

Member Function Documentation

◆ public_seed()

const secure_vector< uint8_t > & Botan::XMSS_Tree_Builder::public_seed ( ) const
inline

Definition at line 51 of file xmss_tree_builder.h.

51{ return m_public_seed; }

Referenced by tree_hash(), wots_private_key_for(), and XMSS_Tree_Builder().

◆ tree_hash()

secure_vector< uint8_t > Botan::XMSS_Tree_Builder::tree_hash ( size_t start_idx,
size_t target_node_height,
const XMSS_Address & adrs,
XMSS_Hash & hash ) const

Definition at line 30 of file xmss_tree_builder.cpp.

33 {
34 BOTAN_ASSERT_NOMSG(target_node_height <= 30);
35 BOTAN_ASSERT((start_idx % (static_cast<size_t>(1) << target_node_height)) == 0,
36 "Start index must be divisible by 2^{target node height}.");
37
38 const size_t n = m_wots_params.element_size();
39 const secure_vector<uint8_t>& seed = this->public_seed();
40 const size_t last_idx = (static_cast<size_t>(1) << target_node_height) + start_idx;
41
42 const size_t batch = std::min<size_t>(LEAF_BATCH, last_idx - start_idx);
43 secure_vector<uint8_t> leaves(batch * n);
44
45 // node stack, holds all nodes on stack and one extra "pending" node. This
46 // temporary node referred to as "node" in the XMSS standard document stays
47 // a pending element, meaning it is not regarded as element on the stack
48 // until level is increased.
49 std::vector<secure_vector<uint8_t>> nodes(target_node_height + 1, secure_vector<uint8_t>(n));
50 std::vector<uint8_t> node_levels(target_node_height + 1);
51
52 uint8_t level = 0; // current level on the node stack.
53
54 XMSS_Address adrs(adrs_in);
56
57 for(size_t i = start_idx; i < last_idx; i++) {
58 const size_t b = (i - start_idx) % batch;
59 if(b == 0) {
60 const size_t count = std::min(batch, last_idx - i);
61 compute_leaves(std::span(leaves).first(count * n), i, count, adrs, hash);
62 }
63
64 copy_mem(nodes[level], std::span(leaves).subspan(b * n, n));
65 node_levels[level] = 0;
66
67 adrs.set_tree_height(0);
68 adrs.set_tree_index(static_cast<uint32_t>(i));
69
70 while(level > 0 && node_levels[level] == node_levels[level - 1]) {
71 adrs.set_tree_index(((adrs.get_tree_index() - 1) >> 1));
72 XMSS_Common_Ops::randomize_tree_hash(nodes[level - 1], nodes[level - 1], nodes[level], adrs, seed, hash, n);
73 node_levels[level - 1]++;
74 level--; //Pop stack top element
75 adrs.set_tree_height(adrs.get_tree_height() + 1);
76 }
77 level++; //push temporary node to stack
78 }
79 return nodes[level - 1];
80}
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:82
#define BOTAN_ASSERT(expr, assertion_made)
Definition assert.h:69
static void randomize_tree_hash(secure_vector< uint8_t > &result, const secure_vector< uint8_t > &left, const secure_vector< uint8_t > &right, XMSS_Address adrs, const secure_vector< uint8_t > &seed, XMSS_Hash &hash, size_t element_size)
constexpr void copy_mem(T *out, const T *in, size_t n)
Definition mem_ops.h:144
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:128

References BOTAN_ASSERT, BOTAN_ASSERT_NOMSG, Botan::copy_mem(), Botan::XMSS_Address::get_tree_height(), Botan::XMSS_Address::get_tree_index(), Botan::XMSS_Address::Hash_Tree_Address, public_seed(), Botan::XMSS_Common_Ops::randomize_tree_hash(), Botan::XMSS_Address::set_tree_height(), Botan::XMSS_Address::set_tree_index(), and Botan::XMSS_Address::set_type().

◆ wots_private_key_for()

XMSS_WOTS_PrivateKey Botan::XMSS_Tree_Builder::wots_private_key_for ( const XMSS_Address & adrs,
XMSS_Hash & hash ) const

Definition at line 161 of file xmss_tree_builder.cpp.

161 {
162 switch(m_wots_derivation_method) {
164 return XMSS_WOTS_PrivateKey(m_wots_params, public_seed(), m_private_seed, adrs, hash);
166 return XMSS_WOTS_PrivateKey(m_wots_params, m_private_seed, adrs, hash);
167 }
168
169 throw Invalid_State("WOTS derivation method is out of the enum's range");
170}

References Botan::Botan2x, Botan::NIST_SP800_208, and public_seed().


The documentation for this class was generated from the following files: