Botan 3.14.1
Crypto and TLS for C&
xmss_common_ops.h
Go to the documentation of this file.
1/*
2 * XMSS Common Ops
3 * (C) 2016,2017 Matthias Gierlings
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 **/
7
8#ifndef BOTAN_XMSS_COMMON_OPS_H_
9#define BOTAN_XMSS_COMMON_OPS_H_
10
11#include <botan/secmem.h>
12#include <botan/xmss_parameters.h>
13#include <botan/internal/xmss_address.h>
14#include <span>
15#include <vector>
16
17namespace Botan {
18
19class XMSS_Hash;
20
21typedef std::vector<secure_vector<uint8_t>> wots_keysig_t;
22
23/**
24 * Bundles the WOTS+ signature and the authentication path of a single XMSS
25 * tree. For XMSS this makes up the entire signature (together with the leaf
26 * index and randomness), while an XMSS^MT signature contains one such
27 * "reduced signature" per hypertree layer.
28 **/
34
35/**
36 * Operations shared by XMSS signature generation and verification operations.
37 **/
39 public:
40 /**
41 * Algorithm 7: "RAND_HASH"
42 *
43 * Generates a randomized hash.
44 *
45 * This overload is used in multithreaded scenarios, where it is
46 * required to provide separate instances of XMSS_Hash to each
47 * thread.
48 *
49 * @param[out] result The resulting randomized hash.
50 * @param[in] left Left half of the hash function input.
51 * @param[in] right Right half of the hash function input.
52 * @param[in] adrs Address of the hash function call.
53 * @param[in] seed The seed for G.
54 * @param[in] hash Instance of XMSS_Hash, that may only by the thread
55 * executing generate_public_key.
56 * @param[in] element_size Size of each node in bytes, the parameter "n"
57 **/
59 const secure_vector<uint8_t>& left,
60 const secure_vector<uint8_t>& right,
61 XMSS_Address adrs,
62 const secure_vector<uint8_t>& seed,
63 XMSS_Hash& hash,
64 size_t element_size);
65
66 /**
67 * Algorithm 8: "ltree"
68 * Create an L-tree used to compute the leaves of the binary hash tree.
69 * Takes a WOTS+ public key and compresses it to a single n-byte value.
70 *
71 * This overload is used in multithreaded scenarios, where it is
72 * required to provide separate instances of XMSS_Hash to each thread.
73 *
74 * @param[out] result Public key compressed to a single n-byte value
75 * pk[0].
76 * @param[in] pk Winternitz One Time Signatures+ public key.
77 * @param[in] adrs Address encoding the address of the L-Tree
78 * @param[in] seed The seed generated during the public key generation.
79 * @param[in] hash Instance of XMSS_Hash, that may only be used by the
80 * thread executing create_l_tree.
81 * @param[in] element_size Size of each node in bytes, the parameter "n"
82 * @param[in] wots_len Number of WOTS+ chains, the parameter "len"
83 **/
84 static void create_l_tree(secure_vector<uint8_t>& result,
85 const wots_keysig_t& pk,
86 XMSS_Address adrs,
87 const secure_vector<uint8_t>& seed,
88 XMSS_Hash& hash,
89 size_t element_size,
90 size_t wots_len);
91
92 /**
93 * Algorithm 8: "ltree", applied to many WOTS+ public keys at once,
94 * batching the hash calls of each tree level across all keys.
95 *
96 * @param[out] leaves The compressed n-byte value of each key
97 * @param[in,out] pks The WOTS+ public keys, each len*n bytes,
98 * contiguous. Destroyed by the computation.
99 * @param[in,out] addrs Per key, its L-tree address with the L-tree
100 * address set. The tree height/index and key/mask
101 * mode are modified.
102 * @param[in] seed The public seed
103 * @param[in] hash Instance of XMSS_Hash, that may only be used by the
104 * thread executing create_l_trees.
105 * @param[in] element_size Size of each node in bytes, the parameter "n"
106 * @param[in] wots_len Number of WOTS+ chains, the parameter "len"
107 **/
108 static void create_l_trees(std::span<uint8_t> leaves,
109 std::span<uint8_t> pks,
110 std::span<XMSS_Address> addrs,
111 std::span<const uint8_t> seed,
112 XMSS_Hash& hash,
113 size_t element_size,
114 size_t wots_len);
115
116 /**
117 * Algorithm 13: "XMSS_rootFromSig"
118 * Computes a root node using a tree signature and a message.
119 *
120 * @param[in] idx_leaf Index of the WOTS+ key pair (the leaf) within the
121 * tree.
122 * @param[in] tree_sig The WOTS+ signature and authentication path.
123 * @param[in] msg The signed message (for XMSS^MT layers above the
124 * lowest: the root node of the tree below).
125 * @param[in] adrs Address of the tree. The caller presets the layer and
126 * tree address fields (both zero for XMSS).
127 * @param[in] seed The public seed.
128 * @param[in] hash The hash instance to use.
129 * @param[in] wots_params The WOTS+ parameters.
130 * @param[in] tree_height Height of the tree, the parameter "h"
131 * (for XMSS^MT: the height of a single layer's tree, "h/d").
132 *
133 * @return An n-byte string holding the value of the root of the tree
134 * defined by the input parameters.
135 **/
136 static secure_vector<uint8_t> root_from_signature(uint32_t idx_leaf,
137 const XMSS_TreeSignature& tree_sig,
138 const secure_vector<uint8_t>& msg,
139 XMSS_Address adrs,
140 const secure_vector<uint8_t>& seed,
141 XMSS_Hash& hash,
142 const XMSS_WOTS_Parameters& wots_params,
143 size_t tree_height);
144};
145
146} // namespace Botan
147
148#endif
static void create_l_tree(secure_vector< uint8_t > &result, const wots_keysig_t &pk, XMSS_Address adrs, const secure_vector< uint8_t > &seed, XMSS_Hash &hash, size_t element_size, size_t wots_len)
static void create_l_trees(std::span< uint8_t > leaves, std::span< uint8_t > pks, std::span< XMSS_Address > addrs, std::span< const uint8_t > seed, XMSS_Hash &hash, size_t element_size, size_t wots_len)
static secure_vector< uint8_t > root_from_signature(uint32_t idx_leaf, const XMSS_TreeSignature &tree_sig, const secure_vector< uint8_t > &msg, XMSS_Address adrs, const secure_vector< uint8_t > &seed, XMSS_Hash &hash, const XMSS_WOTS_Parameters &wots_params, size_t tree_height)
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)
std::vector< secure_vector< uint8_t > > wots_keysig_t
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:128
wots_keysig_t authentication_path