Botan
3.6.1
Crypto and TLS for C&
src
lib
pubkey
xmss
xmss_parameters.cpp
Go to the documentation of this file.
1
/*
2
* XMSS Parameters
3
* Descibes a signature method for XMSS, as defined in:
4
* [1] XMSS: Extended Hash-Based Signatures,
5
* Request for Comments: 8391
6
* Release: May 2018.
7
* https://datatracker.ietf.org/doc/rfc8391/
8
*
9
* (C) 2016,2017,2018 Matthias Gierlings
10
*
11
* Botan is released under the Simplified BSD License (see license.txt)
12
**/
13
14
#include <botan/xmss_parameters.h>
15
16
#include <botan/exceptn.h>
17
#include <botan/internal/fmt.h>
18
19
namespace
Botan
{
20
21
XMSS_Parameters::xmss_algorithm_t
XMSS_Parameters::xmss_id_from_string
(std::string_view param_set) {
22
if
(param_set ==
"XMSS-SHA2_10_256"
) {
23
return
XMSS_SHA2_10_256
;
24
}
25
if
(param_set ==
"XMSS-SHA2_16_256"
) {
26
return
XMSS_SHA2_16_256
;
27
}
28
if
(param_set ==
"XMSS-SHA2_20_256"
) {
29
return
XMSS_SHA2_20_256
;
30
}
31
if
(param_set ==
"XMSS-SHA2_10_512"
) {
32
return
XMSS_SHA2_10_512
;
33
}
34
if
(param_set ==
"XMSS-SHA2_16_512"
) {
35
return
XMSS_SHA2_16_512
;
36
}
37
if
(param_set ==
"XMSS-SHA2_20_512"
) {
38
return
XMSS_SHA2_20_512
;
39
}
40
if
(param_set ==
"XMSS-SHAKE_10_256"
) {
41
return
XMSS_SHAKE_10_256
;
42
}
43
if
(param_set ==
"XMSS-SHAKE_16_256"
) {
44
return
XMSS_SHAKE_16_256
;
45
}
46
if
(param_set ==
"XMSS-SHAKE_20_256"
) {
47
return
XMSS_SHAKE_20_256
;
48
}
49
if
(param_set ==
"XMSS-SHAKE_10_512"
) {
50
return
XMSS_SHAKE_10_512
;
51
}
52
if
(param_set ==
"XMSS-SHAKE_16_512"
) {
53
return
XMSS_SHAKE_16_512
;
54
}
55
if
(param_set ==
"XMSS-SHAKE_20_512"
) {
56
return
XMSS_SHAKE_20_512
;
57
}
58
if
(param_set ==
"XMSS-SHA2_10_192"
) {
59
return
XMSS_SHA2_10_192
;
60
}
61
if
(param_set ==
"XMSS-SHA2_16_192"
) {
62
return
XMSS_SHA2_16_192
;
63
}
64
if
(param_set ==
"XMSS-SHA2_20_192"
) {
65
return
XMSS_SHA2_20_192
;
66
}
67
if
(param_set ==
"XMSS-SHAKE256_10_256"
) {
68
return
XMSS_SHAKE256_10_256
;
69
}
70
if
(param_set ==
"XMSS-SHAKE256_16_256"
) {
71
return
XMSS_SHAKE256_16_256
;
72
}
73
if
(param_set ==
"XMSS-SHAKE256_20_256"
) {
74
return
XMSS_SHAKE256_20_256
;
75
}
76
if
(param_set ==
"XMSS-SHAKE256_10_192"
) {
77
return
XMSS_SHAKE256_10_192
;
78
}
79
if
(param_set ==
"XMSS-SHAKE256_16_192"
) {
80
return
XMSS_SHAKE256_16_192
;
81
}
82
if
(param_set ==
"XMSS-SHAKE256_20_192"
) {
83
return
XMSS_SHAKE256_20_192
;
84
}
85
86
throw
Lookup_Error
(
fmt
(
"Unknown XMSS algorithm param '{}'"
, param_set));
87
}
88
89
XMSS_Parameters::XMSS_Parameters
(std::string_view param_set) :
90
XMSS_Parameters
(
XMSS_Parameters
::xmss_id_from_string(param_set)) {}
91
92
XMSS_Parameters::XMSS_Parameters
(
xmss_algorithm_t
oid) : m_oid(oid) {
93
switch
(
oid
) {
94
case
XMSS_SHA2_10_256
:
95
m_element_size = 32;
96
m_hash_id_size = 32;
97
m_w = 16;
98
m_len = 67;
99
m_tree_height = 10;
100
m_name =
"XMSS-SHA2_10_256"
;
101
m_hash_name =
"SHA-256"
;
102
m_strength = 256;
103
m_wots_oid =
XMSS_WOTS_Parameters::ots_algorithm_t::WOTSP_SHA2_256
;
104
break
;
105
case
XMSS_SHA2_16_256
:
106
m_element_size = 32;
107
m_hash_id_size = 32;
108
m_w = 16;
109
m_len = 67;
110
m_tree_height = 16;
111
m_name =
"XMSS-SHA2_16_256"
;
112
m_hash_name =
"SHA-256"
;
113
m_strength = 256;
114
m_wots_oid =
XMSS_WOTS_Parameters::ots_algorithm_t::WOTSP_SHA2_256
;
115
break
;
116
case
XMSS_SHA2_20_256
:
117
m_element_size = 32;
118
m_hash_id_size = 32;
119
m_w = 16;
120
m_len = 67;
121
m_tree_height = 20;
122
m_name =
"XMSS-SHA2_20_256"
;
123
m_hash_name =
"SHA-256"
;
124
m_strength = 256;
125
m_wots_oid =
XMSS_WOTS_Parameters::ots_algorithm_t::WOTSP_SHA2_256
;
126
break
;
127
case
XMSS_SHA2_10_512
:
128
m_element_size = 64;
129
m_hash_id_size = 64;
130
m_w = 16;
131
m_len = 131;
132
m_tree_height = 10;
133
m_name =
"XMSS-SHA2_10_512"
;
134
m_hash_name =
"SHA-512"
;
135
m_strength = 512;
136
m_wots_oid =
XMSS_WOTS_Parameters::ots_algorithm_t::WOTSP_SHA2_512
;
137
break
;
138
case
XMSS_SHA2_16_512
:
139
m_element_size = 64;
140
m_hash_id_size = 64;
141
m_w = 16;
142
m_len = 131;
143
m_tree_height = 16;
144
m_name =
"XMSS-SHA2_16_512"
;
145
m_hash_name =
"SHA-512"
;
146
m_strength = 512;
147
m_wots_oid =
XMSS_WOTS_Parameters::ots_algorithm_t::WOTSP_SHA2_512
;
148
break
;
149
case
XMSS_SHA2_20_512
:
150
m_element_size = 64;
151
m_hash_id_size = 64;
152
m_w = 16;
153
m_len = 131;
154
m_tree_height = 20;
155
m_name =
"XMSS-SHA2_20_512"
;
156
m_hash_name =
"SHA-512"
;
157
m_strength = 512;
158
m_wots_oid =
XMSS_WOTS_Parameters::ots_algorithm_t::WOTSP_SHA2_512
;
159
break
;
160
case
XMSS_SHAKE_10_256
:
161
m_element_size = 32;
162
m_hash_id_size = 32;
163
m_w = 16;
164
m_len = 67;
165
m_tree_height = 10;
166
m_name =
"XMSS-SHAKE_10_256"
;
167
m_hash_name =
"SHAKE-128(256)"
;
168
m_strength = 256;
169
m_wots_oid =
XMSS_WOTS_Parameters::ots_algorithm_t::WOTSP_SHAKE_256
;
170
break
;
171
case
XMSS_SHAKE_16_256
:
172
m_element_size = 32;
173
m_hash_id_size = 32;
174
m_w = 16;
175
m_len = 67;
176
m_tree_height = 16;
177
m_name =
"XMSS-SHAKE_16_256"
;
178
m_hash_name =
"SHAKE-128(256)"
;
179
m_strength = 256;
180
m_wots_oid =
XMSS_WOTS_Parameters::ots_algorithm_t::WOTSP_SHAKE_256
;
181
break
;
182
case
XMSS_SHAKE_20_256
:
183
m_element_size = 32;
184
m_hash_id_size = 32;
185
m_w = 16;
186
m_len = 67;
187
m_tree_height = 20;
188
m_name =
"XMSS-SHAKE_20_256"
;
189
m_hash_name =
"SHAKE-128(256)"
;
190
m_strength = 256;
191
m_wots_oid =
XMSS_WOTS_Parameters::ots_algorithm_t::WOTSP_SHAKE_256
;
192
break
;
193
case
XMSS_SHAKE_10_512
:
194
m_element_size = 64;
195
m_hash_id_size = 64;
196
m_w = 16;
197
m_len = 131;
198
m_tree_height = 10;
199
m_name =
"XMSS-SHAKE_10_512"
;
200
m_hash_name =
"SHAKE-256(512)"
;
201
m_strength = 512;
202
m_wots_oid =
XMSS_WOTS_Parameters::ots_algorithm_t::WOTSP_SHAKE_512
;
203
break
;
204
case
XMSS_SHAKE_16_512
:
205
m_element_size = 64;
206
m_hash_id_size = 64;
207
m_w = 16;
208
m_len = 131;
209
m_tree_height = 16;
210
m_name =
"XMSS-SHAKE_16_512"
;
211
m_hash_name =
"SHAKE-256(512)"
;
212
m_strength = 512;
213
m_wots_oid =
XMSS_WOTS_Parameters::ots_algorithm_t::WOTSP_SHAKE_512
;
214
break
;
215
case
XMSS_SHAKE_20_512
:
216
m_element_size = 64;
217
m_hash_id_size = 64;
218
m_w = 16;
219
m_len = 131;
220
m_tree_height = 20;
221
m_name =
"XMSS-SHAKE_20_512"
;
222
m_hash_name =
"SHAKE-256(512)"
;
223
m_strength = 512;
224
m_wots_oid =
XMSS_WOTS_Parameters::ots_algorithm_t::WOTSP_SHAKE_512
;
225
break
;
226
case
XMSS_SHA2_10_192
:
227
m_element_size = 24;
228
m_hash_id_size = 4;
229
m_w = 16;
230
m_len = 51;
231
m_tree_height = 10;
232
m_name =
"XMSS-SHA2_10_192"
;
233
m_hash_name =
"Truncated(SHA-256,192)"
;
234
m_strength = 192;
235
m_wots_oid =
XMSS_WOTS_Parameters::ots_algorithm_t::WOTSP_SHA2_192
;
236
break
;
237
case
XMSS_SHA2_16_192
:
238
m_element_size = 24;
239
m_hash_id_size = 4;
240
m_w = 16;
241
m_len = 51;
242
m_tree_height = 16;
243
m_name =
"XMSS-SHA2_16_192"
;
244
m_hash_name =
"Truncated(SHA-256,192)"
;
245
m_strength = 192;
246
m_wots_oid =
XMSS_WOTS_Parameters::ots_algorithm_t::WOTSP_SHA2_192
;
247
break
;
248
case
XMSS_SHA2_20_192
:
249
m_element_size = 24;
250
m_hash_id_size = 4;
251
m_w = 16;
252
m_len = 51;
253
m_tree_height = 20;
254
m_name =
"XMSS-SHA2_20_192"
;
255
m_hash_name =
"Truncated(SHA-256,192)"
;
256
m_strength = 192;
257
m_wots_oid =
XMSS_WOTS_Parameters::ots_algorithm_t::WOTSP_SHA2_192
;
258
break
;
259
case
XMSS_SHAKE256_10_256
:
260
m_element_size = 32;
261
m_hash_id_size = 32;
262
m_w = 16;
263
m_len = 67;
264
m_tree_height = 10;
265
m_name =
"XMSS-SHAKE256_10_256"
;
266
m_hash_name =
"SHAKE-256(256)"
;
267
m_strength = 256;
268
m_wots_oid =
XMSS_WOTS_Parameters::ots_algorithm_t::WOTSP_SHAKE_256_256
;
269
break
;
270
case
XMSS_SHAKE256_16_256
:
271
m_element_size = 32;
272
m_hash_id_size = 32;
273
m_w = 16;
274
m_len = 67;
275
m_tree_height = 16;
276
m_name =
"XMSS-SHAKE256_16_256"
;
277
m_hash_name =
"SHAKE-256(256)"
;
278
m_strength = 256;
279
m_wots_oid =
XMSS_WOTS_Parameters::ots_algorithm_t::WOTSP_SHAKE_256_256
;
280
break
;
281
case
XMSS_SHAKE256_20_256
:
282
m_element_size = 32;
283
m_hash_id_size = 32;
284
m_w = 16;
285
m_len = 67;
286
m_tree_height = 20;
287
m_name =
"XMSS-SHAKE256_20_256"
;
288
m_hash_name =
"SHAKE-256(256)"
;
289
m_strength = 256;
290
m_wots_oid =
XMSS_WOTS_Parameters::ots_algorithm_t::WOTSP_SHAKE_256_256
;
291
break
;
292
case
XMSS_SHAKE256_10_192
:
293
m_element_size = 24;
294
m_hash_id_size = 4;
295
m_w = 16;
296
m_len = 51;
297
m_tree_height = 10;
298
m_name =
"XMSS-SHAKE256_10_192"
;
299
m_hash_name =
"SHAKE-256(192)"
;
300
m_strength = 192;
301
m_wots_oid =
XMSS_WOTS_Parameters::ots_algorithm_t::WOTSP_SHAKE_256_192
;
302
break
;
303
case
XMSS_SHAKE256_16_192
:
304
m_element_size = 24;
305
m_hash_id_size = 4;
306
m_w = 16;
307
m_len = 51;
308
m_tree_height = 16;
309
m_name =
"XMSS-SHAKE256_16_192"
;
310
m_hash_name =
"SHAKE-256(192)"
;
311
m_strength = 192;
312
m_wots_oid =
XMSS_WOTS_Parameters::ots_algorithm_t::WOTSP_SHAKE_256_192
;
313
break
;
314
case
XMSS_SHAKE256_20_192
:
315
m_element_size = 24;
316
m_hash_id_size = 4;
317
m_w = 16;
318
m_len = 51;
319
m_tree_height = 20;
320
m_name =
"XMSS-SHAKE256_20_192"
;
321
m_hash_name =
"SHAKE-256(192)"
;
322
m_strength = 192;
323
m_wots_oid =
XMSS_WOTS_Parameters::ots_algorithm_t::WOTSP_SHAKE_256_192
;
324
break
;
325
326
default
:
327
throw
Not_Implemented
(
"Algorithm id does not match any known XMSS algorithm id:"
+ std::to_string(
oid
));
328
}
329
}
330
331
}
// namespace Botan
Botan::Lookup_Error
Definition
exceptn.h:235
Botan::Not_Implemented
Definition
exceptn.h:334
Botan::XMSS_Parameters
Definition
xmss_parameters.h:129
Botan::XMSS_Parameters::xmss_id_from_string
static xmss_algorithm_t xmss_id_from_string(std::string_view algo_name)
Definition
xmss_parameters.cpp:21
Botan::XMSS_Parameters::XMSS_Parameters
XMSS_Parameters(std::string_view algo_name)
Definition
xmss_parameters.cpp:89
Botan::XMSS_Parameters::oid
xmss_algorithm_t oid() const
Definition
xmss_parameters.h:212
Botan::XMSS_Parameters::xmss_algorithm_t
xmss_algorithm_t
Definition
xmss_parameters.h:131
Botan::XMSS_Parameters::XMSS_SHA2_10_512
@ XMSS_SHA2_10_512
Definition
xmss_parameters.h:139
Botan::XMSS_Parameters::XMSS_SHA2_20_512
@ XMSS_SHA2_20_512
Definition
xmss_parameters.h:141
Botan::XMSS_Parameters::XMSS_SHAKE256_16_192
@ XMSS_SHAKE256_16_192
Definition
xmss_parameters.h:157
Botan::XMSS_Parameters::XMSS_SHAKE_10_512
@ XMSS_SHAKE_10_512
Definition
xmss_parameters.h:145
Botan::XMSS_Parameters::XMSS_SHAKE256_16_256
@ XMSS_SHAKE256_16_256
Definition
xmss_parameters.h:154
Botan::XMSS_Parameters::XMSS_SHA2_16_512
@ XMSS_SHA2_16_512
Definition
xmss_parameters.h:140
Botan::XMSS_Parameters::XMSS_SHA2_20_256
@ XMSS_SHA2_20_256
Definition
xmss_parameters.h:135
Botan::XMSS_Parameters::XMSS_SHA2_20_192
@ XMSS_SHA2_20_192
Definition
xmss_parameters.h:152
Botan::XMSS_Parameters::XMSS_SHAKE_10_256
@ XMSS_SHAKE_10_256
Definition
xmss_parameters.h:142
Botan::XMSS_Parameters::XMSS_SHA2_10_192
@ XMSS_SHA2_10_192
Definition
xmss_parameters.h:150
Botan::XMSS_Parameters::XMSS_SHAKE_16_256
@ XMSS_SHAKE_16_256
Definition
xmss_parameters.h:143
Botan::XMSS_Parameters::XMSS_SHAKE_20_256
@ XMSS_SHAKE_20_256
Definition
xmss_parameters.h:144
Botan::XMSS_Parameters::XMSS_SHAKE_16_512
@ XMSS_SHAKE_16_512
Definition
xmss_parameters.h:146
Botan::XMSS_Parameters::XMSS_SHAKE_20_512
@ XMSS_SHAKE_20_512
Definition
xmss_parameters.h:147
Botan::XMSS_Parameters::XMSS_SHAKE256_20_256
@ XMSS_SHAKE256_20_256
Definition
xmss_parameters.h:155
Botan::XMSS_Parameters::XMSS_SHA2_16_192
@ XMSS_SHA2_16_192
Definition
xmss_parameters.h:151
Botan::XMSS_Parameters::XMSS_SHAKE256_20_192
@ XMSS_SHAKE256_20_192
Definition
xmss_parameters.h:158
Botan::XMSS_Parameters::XMSS_SHAKE256_10_256
@ XMSS_SHAKE256_10_256
Definition
xmss_parameters.h:153
Botan::XMSS_Parameters::XMSS_SHA2_10_256
@ XMSS_SHA2_10_256
Definition
xmss_parameters.h:133
Botan::XMSS_Parameters::XMSS_SHAKE256_10_192
@ XMSS_SHAKE256_10_192
Definition
xmss_parameters.h:156
Botan::XMSS_Parameters::XMSS_SHA2_16_256
@ XMSS_SHA2_16_256
Definition
xmss_parameters.h:134
Botan::XMSS_WOTS_Parameters::WOTSP_SHA2_192
@ WOTSP_SHA2_192
Definition
xmss_parameters.h:44
Botan::XMSS_WOTS_Parameters::WOTSP_SHAKE_256
@ WOTSP_SHAKE_256
Definition
xmss_parameters.h:40
Botan::XMSS_WOTS_Parameters::WOTSP_SHAKE_256_192
@ WOTSP_SHAKE_256_192
Definition
xmss_parameters.h:46
Botan::XMSS_WOTS_Parameters::WOTSP_SHAKE_512
@ WOTSP_SHAKE_512
Definition
xmss_parameters.h:41
Botan::XMSS_WOTS_Parameters::WOTSP_SHAKE_256_256
@ WOTSP_SHAKE_256_256
Definition
xmss_parameters.h:45
Botan::XMSS_WOTS_Parameters::WOTSP_SHA2_256
@ WOTSP_SHA2_256
Definition
xmss_parameters.h:35
Botan::XMSS_WOTS_Parameters::WOTSP_SHA2_512
@ WOTSP_SHA2_512
Definition
xmss_parameters.h:39
Botan
Definition
alg_id.cpp:13
Botan::fmt
std::string fmt(std::string_view format, const T &... args)
Definition
fmt.h:53
Generated by
1.12.0