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