Botan 3.0.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 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 **/
7
8#ifndef BOTAN_XMSS_PARAMETERS_H_
9#define BOTAN_XMSS_PARAMETERS_H_
10
11#include <string>
12#include <map>
13
14#include <botan/build.h>
15#include <botan/secmem.h>
16
17namespace Botan {
18
19/**
20 * Descibes a signature method for XMSS Winternitz One Time Signatures,
21 * as defined in:
22 * [1] XMSS: Extended Hash-Based Signatures,
23 * Request for Comments: 8391
24 * Release: May 2018.
25 * https://datatracker.ietf.org/doc/rfc8391/
26 * [2] Recommendation for Stateful Hash-Based Signature Schemes
27 * NIST Special Publication 800-208
28 * Release: October 2020.
29 * https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-208.pdf
30 **/
32 {
33 public:
35 {
36 // from RFC 8391
37 WOTSP_SHA2_256 = 0x00000001,
38
39 // from RFC 8391 but not approved by NIST SP.800-208
40 // (see footnote on page 16)
41 WOTSP_SHA2_512 = 0x00000002,
42 WOTSP_SHAKE_256 = 0x00000003,
43 WOTSP_SHAKE_512 = 0x00000004,
44
45 // from NIST SP.800-208
46 WOTSP_SHA2_192 = 0x00000005,
47 WOTSP_SHAKE_256_256 = 0x00000006,
48 WOTSP_SHAKE_256_192 = 0x00000007,
49 };
50
51 explicit XMSS_WOTS_Parameters(std::string_view algo_name);
52 XMSS_WOTS_Parameters(ots_algorithm_t ots_spec);
53
54 static ots_algorithm_t xmss_wots_id_from_string(std::string_view param_set);
55
56 /**
57 * Algorithm 1: convert input string to base.
58 *
59 * @param msg Input string (referred to as X in [1]).
60 * @param out_size size of message in base w.
61 *
62 * @return Input string converted to the given base.
63 **/
64 secure_vector<uint8_t> base_w(const secure_vector<uint8_t>& msg, size_t out_size) const;
65
66 secure_vector<uint8_t> base_w(size_t value) const;
67
68 void append_checksum(secure_vector<uint8_t>& data) const;
69
70 /**
71 * @return XMSS WOTS registry name for the chosen parameter set.
72 **/
73 const std::string name() const
74 {
75 return m_name;
76 }
77
78 /**
79 * Retrieves the uniform length of a message, and the size of
80 * each node. This correlates to XMSS parameter "n" defined
81 * in [1].
82 *
83 * @return element length in bytes.
84 **/
85 size_t element_size() const { return m_element_size; }
86
87 /**
88 * The Winternitz parameter.
89 *
90 * @return numeric base used for internal representation of
91 * data.
92 **/
93 size_t wots_parameter() const { return m_w; }
94
95 size_t len() const { return m_len; }
96
97 size_t len_1() const { return m_len_1; }
98
99 size_t len_2() const { return m_len_2; }
100
101 size_t lg_w() const { return m_lg_w; }
102
103 ots_algorithm_t oid() const { return m_oid; }
104
105 size_t estimated_strength() const { return m_strength; }
106
107 bool operator==(const XMSS_WOTS_Parameters& p) const
108 {
109 return m_oid == p.m_oid;
110 }
111
112 private:
113 static const std::map<std::string, ots_algorithm_t> m_oid_name_lut;
114 ots_algorithm_t m_oid;
115 std::string m_name;
116 std::string m_hash_name;
117 size_t m_element_size;
118 size_t m_w;
119 size_t m_len_1;
120 size_t m_len_2;
121 size_t m_len;
122 size_t m_strength;
123 uint8_t m_lg_w;
124 };
125
126/**
127 * Descibes a signature method for XMSS, as defined in:
128 * [1] XMSS: Extended Hash-Based Signatures,
129 * Request for Comments: 8391
130 * Release: May 2018.
131 * https://datatracker.ietf.org/doc/rfc8391/
132 * [2] Recommendation for Stateful Hash-Based Signature Schemes
133 * NIST Special Publication 800-208
134 * Release: October 2020.
135 * https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-208.pdf
136 **/
138 {
139 public:
141 {
142 // from RFC 8391
143 XMSS_SHA2_10_256 = 0x00000001,
144 XMSS_SHA2_16_256 = 0x00000002,
145 XMSS_SHA2_20_256 = 0x00000003,
146
147 // from RFC 8391 but not approved by NIST SP.800-208
148 // (see footnote on page 16)
149 XMSS_SHA2_10_512 = 0x00000004,
150 XMSS_SHA2_16_512 = 0x00000005,
151 XMSS_SHA2_20_512 = 0x00000006,
152 XMSS_SHAKE_10_256 = 0x00000007,
153 XMSS_SHAKE_16_256 = 0x00000008,
154 XMSS_SHAKE_20_256 = 0x00000009,
155 XMSS_SHAKE_10_512 = 0x0000000a,
156 XMSS_SHAKE_16_512 = 0x0000000b,
157 XMSS_SHAKE_20_512 = 0x0000000c,
158
159 // from NIST SP.800-208
160 XMSS_SHA2_10_192 = 0x0000000d,
161 XMSS_SHA2_16_192 = 0x0000000e,
162 XMSS_SHA2_20_192 = 0x0000000f,
163 XMSS_SHAKE256_10_256 = 0x00000010,
164 XMSS_SHAKE256_16_256 = 0x00000011,
165 XMSS_SHAKE256_20_256 = 0x00000012,
166 XMSS_SHAKE256_10_192 = 0x00000013,
167 XMSS_SHAKE256_16_192 = 0x00000014,
168 XMSS_SHAKE256_20_192 = 0x00000015,
169 };
170
171 static xmss_algorithm_t xmss_id_from_string(std::string_view algo_name);
172
173 explicit XMSS_Parameters(std::string_view algo_name);
174 explicit XMSS_Parameters(xmss_algorithm_t oid);
175
176 /**
177 * @return XMSS registry name for the chosen parameter set.
178 **/
179 const std::string name() const
180 {
181 return m_name;
182 }
183
184 const std::string hash_function_name() const
185 {
186 return m_hash_name;
187 }
188
189 /**
190 * Retrieves the uniform length of a message, and the size of
191 * each node. This correlates to XMSS parameter "n" defined
192 * in [1].
193 *
194 * @return element length in bytes.
195 **/
196 size_t element_size() const { return m_element_size; }
197
198 /**
199 * Retrieves the length of the hash identifier (domain separator)
200 * in bytes. See definition of `toByte()` in RFC 8391 Section 2.4
201 * and the concrete definitions of hash functions in Section 5.1
202 * where this parameter is always equal to the output length of the
203 * underlying hash primitive. Also see NIST SP.800-208 where
204 * instantiations utilizing truncated hashes use shorter hash IDs.
205 */
206 size_t hash_id_size() const { return m_hash_id_size; }
207
208 /**
209 * @returns The height (number of levels - 1) of the tree
210 **/
211 size_t tree_height() const { return m_tree_height; }
212
213 /**
214 * @returns total number of signatures allowed for this XMSS instance
215 */
216 size_t total_number_of_signatures() const { return size_t(1) << tree_height(); }
217
218 /**
219 * The Winternitz parameter.
220 *
221 * @return numeric base used for internal representation of
222 * data.
223 **/
224 size_t wots_parameter() const { return m_w; }
225
226 size_t len() const { return m_len; }
227
228 xmss_algorithm_t oid() const { return m_oid; }
229
231 {
232 return m_wots_oid;
233 }
234
235 /**
236 * Returns the estimated pre-quantum security level of
237 * the chosen algorithm.
238 **/
239 size_t estimated_strength() const
240 {
241 return m_strength;
242 }
243
244 size_t raw_public_key_size() const
245 {
246 return sizeof(uint32_t) + 2 * element_size();
247 }
248
250 {
251 return raw_public_key_size() +
252 sizeof(uint32_t) +
253 2 * element_size();
254 }
255
256 size_t raw_private_key_size() const
257 {
258 return raw_legacy_private_key_size()
259 + 1 /* identifier for WOTS+ key derivation method */;
260 }
261
262 bool operator==(const XMSS_Parameters& p) const
263 {
264 return m_oid == p.m_oid;
265 }
266
267 private:
268 xmss_algorithm_t m_oid;
270 std::string m_name;
271 std::string m_hash_name;
272 size_t m_element_size;
273 size_t m_hash_id_size;
274 size_t m_tree_height;
275 size_t m_w;
276 size_t m_len;
277 size_t m_strength;
278 };
279
280}
281
282#endif
size_t total_number_of_signatures() const
size_t hash_id_size() const
size_t raw_private_key_size() const
const std::string name() const
size_t estimated_strength() const
size_t wots_parameter() const
size_t raw_public_key_size() const
size_t tree_height() const
xmss_algorithm_t oid() const
XMSS_WOTS_Parameters::ots_algorithm_t ots_oid() const
const std::string hash_function_name() const
size_t raw_legacy_private_key_size() const
size_t element_size() const
bool operator==(const XMSS_Parameters &p) const
ots_algorithm_t oid() const
const std::string name() const
bool operator==(const XMSS_WOTS_Parameters &p) const
int(* final)(unsigned char *, CTX *)
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
Definition: alg_id.cpp:12
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:64