Botan 3.12.0
Crypto and TLS for C&
xmss_parameters.h
Go to the documentation of this file.
1/*
2 * XMSS Parameters
3 * (C) 2016,2018 Matthias Gierlings
4 * 2026 Jack Lloyd
5 *
6 * Botan is released under the Simplified BSD License (see license.txt)
7 **/
8
9#ifndef BOTAN_XMSS_PARAMETERS_H_
10#define BOTAN_XMSS_PARAMETERS_H_
11
12#include <botan/secmem.h>
13#include <botan/types.h>
14#include <string_view>
15
16namespace Botan {
17
18/*
19* TODO(Botan4) this header is only needed by xmss.h due to xmss_algorithm_t
20* Split xmss_algorithm_t out somehow, and make this header internal
21*/
22
23/**
24 * Describes a signature method for XMSS Winternitz One Time Signatures,
25 * as defined in:
26 * [1] XMSS: Extended Hash-Based Signatures,
27 * Request for Comments: 8391
28 * Release: May 2018.
29 * https://datatracker.ietf.org/doc/rfc8391/
30 * [2] Recommendation for Stateful Hash-Based Signature Schemes
31 * NIST Special Publication 800-208
32 * Release: October 2020.
33 * https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-208.pdf
34 **/
36 public:
37 enum ots_algorithm_t : uint32_t /* NOLINT(*-enum-size,*-use-enum-class) */ {
38 // from RFC 8391
39 WOTSP_SHA2_256 = 0x00000001,
40
41 // from RFC 8391 but not approved by NIST SP.800-208
42 // (see footnote on page 16)
43 WOTSP_SHA2_512 = 0x00000002,
44 WOTSP_SHAKE_256 = 0x00000003,
45 WOTSP_SHAKE_512 = 0x00000004,
46
47 // from NIST SP.800-208
48 WOTSP_SHA2_192 = 0x00000005,
49 WOTSP_SHAKE_256_256 = 0x00000006,
50 WOTSP_SHAKE_256_192 = 0x00000007,
51 };
52
53 static XMSS_WOTS_Parameters from_id(ots_algorithm_t id);
54
56 XMSS_WOTS_Parameters(XMSS_WOTS_Parameters&& other) noexcept = default;
60
61 /**
62 * Retrieves the uniform length of a message, and the size of
63 * each node. This correlates to XMSS parameter "n" defined
64 * in [1].
65 *
66 * @return element length in bytes.
67 **/
68 size_t element_size() const { return m_element_size; }
69
70 /**
71 * The Winternitz parameter.
72 *
73 * @return numeric base used for internal representation of data.
74 *
75 * Fixed at 16 for this implementation.
76 **/
77 size_t wots_parameter() const { return 16; }
78
79 /**
80 * The log2 of wots_parameter
81 */
82 size_t lg_w() const { return 4; }
83
84 size_t len() const { return m_len; }
85
86 size_t len_1() const { return m_len_1; }
87
88 size_t len_2() const { return m_len_2; }
89
90 ots_algorithm_t oid() const { return m_id; }
91
92 // Return estimated workfactor in bits
93 size_t estimated_strength() const { return 8 * m_element_size; }
94
95 bool operator==(const XMSS_WOTS_Parameters& p) const { return m_id == p.m_id; }
96
97 private:
98 static XMSS_WOTS_Parameters from_hash_len(ots_algorithm_t id, size_t hash_len);
99
100 XMSS_WOTS_Parameters(ots_algorithm_t id, size_t hash_len, size_t len, size_t len1, size_t len2) :
101 m_id(id), m_element_size(hash_len), m_len(len), m_len_1(len1), m_len_2(len2) {}
102
103 ots_algorithm_t m_id{};
104 size_t m_element_size;
105 size_t m_len;
106 size_t m_len_1;
107 size_t m_len_2;
108};
109
110/**
111 * Describes a signature method for XMSS, as defined in:
112 * [1] XMSS: Extended Hash-Based Signatures,
113 * Request for Comments: 8391
114 * Release: May 2018.
115 * https://datatracker.ietf.org/doc/rfc8391/
116 * [2] Recommendation for Stateful Hash-Based Signature Schemes
117 * NIST Special Publication 800-208
118 * Release: October 2020.
119 * https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-208.pdf
120 **/
122 public:
123 enum xmss_algorithm_t : uint32_t /* NOLINT(*-enum-size,*-use-enum-class) */ {
124 // from RFC 8391
125 XMSS_SHA2_10_256 = 0x00000001,
126 XMSS_SHA2_16_256 = 0x00000002,
127 XMSS_SHA2_20_256 = 0x00000003,
128
129 // from RFC 8391 but not approved by NIST SP.800-208
130 // (see footnote on page 16)
131 XMSS_SHA2_10_512 = 0x00000004,
132 XMSS_SHA2_16_512 = 0x00000005,
133 XMSS_SHA2_20_512 = 0x00000006,
134 XMSS_SHAKE_10_256 = 0x00000007,
135 XMSS_SHAKE_16_256 = 0x00000008,
136 XMSS_SHAKE_20_256 = 0x00000009,
137 XMSS_SHAKE_10_512 = 0x0000000a,
138 XMSS_SHAKE_16_512 = 0x0000000b,
139 XMSS_SHAKE_20_512 = 0x0000000c,
140
141 // from NIST SP.800-208
142 XMSS_SHA2_10_192 = 0x0000000d,
143 XMSS_SHA2_16_192 = 0x0000000e,
144 XMSS_SHA2_20_192 = 0x0000000f,
151 };
152
153 static xmss_algorithm_t xmss_id_from_string(std::string_view algo_name);
154
155 BOTAN_DEPRECATED("Use XMSS_Parameters::from_name") explicit XMSS_Parameters(std::string_view algo_name);
156
157 BOTAN_DEPRECATED("Use XMSS_Parameters::from_id") explicit XMSS_Parameters(xmss_algorithm_t oid);
158
159 static XMSS_Parameters from_name(std::string_view algo_name);
160
161 static XMSS_Parameters from_id(xmss_algorithm_t id);
162
163 XMSS_Parameters(const XMSS_Parameters& other) = default;
164 XMSS_Parameters(XMSS_Parameters&& other) noexcept = default;
165 XMSS_Parameters& operator=(const XMSS_Parameters& other) = default;
166 XMSS_Parameters& operator=(XMSS_Parameters&& other) noexcept = default;
167 ~XMSS_Parameters() = default;
168
169 /**
170 * @return XMSS registry name for the chosen parameter set.
171 **/
172 std::string_view name() const;
173
174 std::string_view hash_function_name() const;
175
176 /**
177 * Retrieves the uniform length of a message, and the size of
178 * each node. This correlates to XMSS parameter "n" defined
179 * in [1].
180 *
181 * @return element length in bytes.
182 **/
183 size_t element_size() const { return m_element_size; }
184
185 /**
186 * Retrieves the length of the hash identifier (domain separator)
187 * in bytes. See definition of `toByte()` in RFC 8391 Section 2.4
188 * and the concrete definitions of hash functions in Section 5.1
189 * where this parameter is always equal to the output length of the
190 * underlying hash primitive. Also see NIST SP.800-208 where
191 * instantiations utilizing truncated hashes use shorter hash IDs.
192 */
193 size_t hash_id_size() const { return m_hash_id_size; }
194
195 /**
196 * @returns The height (number of levels - 1) of the tree
197 **/
198 size_t tree_height() const { return m_tree_height; }
199
200 /**
201 * @returns total number of signatures allowed for this XMSS instance
202 */
203 size_t total_number_of_signatures() const { return static_cast<size_t>(1) << tree_height(); }
204
205 /**
206 * The Winternitz parameter.
207 *
208 * @return numeric base used for internal representation of
209 * data.
210 **/
211 size_t wots_parameter() const { return 16; }
212
213 size_t len() const { return m_len; }
214
215 xmss_algorithm_t oid() const { return m_oid; }
216
217 XMSS_WOTS_Parameters::ots_algorithm_t ots_oid() const { return m_wots_oid; }
218
220
221 /**
222 * Returns the estimated pre-quantum security level of
223 * the chosen algorithm.
224 **/
225 size_t estimated_strength() const { return 8 * m_element_size; }
226
227 size_t raw_public_key_size() const { return sizeof(uint32_t) + 2 * element_size(); }
228
230 return raw_public_key_size() + sizeof(uint32_t) + 2 * element_size();
231 }
232
233 size_t raw_private_key_size() const {
234 return raw_legacy_private_key_size() + 1 /* identifier for WOTS+ key derivation method */;
235 }
236
237 bool operator==(const XMSS_Parameters& p) const { return m_oid == p.m_oid; }
238
239 private:
240 XMSS_Parameters(xmss_algorithm_t oid,
242 size_t hash_len,
243 size_t hash_id_size,
244 size_t tree_height,
245 size_t len) :
246 m_oid(oid),
247 m_wots_oid(wots_oid),
248 m_element_size(hash_len),
249 m_hash_id_size(hash_id_size),
250 m_tree_height(tree_height),
251 m_len(len) {}
252
253 xmss_algorithm_t m_oid{};
254 XMSS_WOTS_Parameters::ots_algorithm_t m_wots_oid;
255 size_t m_element_size;
256 size_t m_hash_id_size;
257 size_t m_tree_height;
258 size_t m_len;
259};
260
261} // namespace Botan
262
263#endif
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:21
#define BOTAN_DEPRECATED(msg)
Definition api.h:73
size_t total_number_of_signatures() const
std::string_view name() const
size_t hash_id_size() const
size_t raw_private_key_size() const
XMSS_Parameters(std::string_view algo_name)
size_t estimated_strength() const
size_t wots_parameter() const
size_t raw_public_key_size() const
xmss_algorithm_t oid() const
XMSS_WOTS_Parameters::ots_algorithm_t ots_oid() const
std::string_view hash_function_name() const
size_t raw_legacy_private_key_size() const
size_t element_size() const
XMSS_WOTS_Parameters wots_parameters() const
bool operator==(const XMSS_Parameters &p) const
XMSS_WOTS_Parameters(XMSS_WOTS_Parameters &&other) noexcept=default
XMSS_WOTS_Parameters(const XMSS_WOTS_Parameters &other)=default
static XMSS_WOTS_Parameters from_id(ots_algorithm_t id)
ots_algorithm_t oid() const
XMSS_WOTS_Parameters & operator=(const XMSS_WOTS_Parameters &other)=default
bool operator==(const XMSS_WOTS_Parameters &p) const
XMSS_WOTS_Parameters & operator=(XMSS_WOTS_Parameters &&other) noexcept=default