Coverage Report

Created: 2020-11-21 08:34

/src/botan/src/lib/pubkey/xmss/xmss_parameters.cpp
Line
Count
Source (jump to first uncovered line)
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
#include <botan/exceptn.h>
16
17
namespace Botan {
18
19
XMSS_Parameters::xmss_algorithm_t XMSS_Parameters::xmss_id_from_string(const std::string& param_set)
20
0
   {
21
0
   if(param_set == "XMSS-SHA2_10_256")
22
0
      { return XMSS_SHA2_10_256; }
23
0
   if(param_set == "XMSS-SHA2_16_256")
24
0
      { return XMSS_SHA2_16_256; }
25
0
   if(param_set == "XMSS-SHA2_20_256")
26
0
      { return XMSS_SHA2_20_256; }
27
0
   if(param_set == "XMSS-SHA2_10_512")
28
0
      { return XMSS_SHA2_10_512; }
29
0
   if(param_set == "XMSS-SHA2_16_512")
30
0
      { return XMSS_SHA2_16_512; }
31
0
   if(param_set == "XMSS-SHA2_20_512")
32
0
      { return XMSS_SHA2_20_512; }
33
0
   if(param_set == "XMSS-SHAKE_10_256")
34
0
      { return XMSS_SHAKE_10_256; }
35
0
   if(param_set == "XMSS-SHAKE_16_256")
36
0
      { return XMSS_SHAKE_16_256; }
37
0
   if(param_set == "XMSS-SHAKE_20_256")
38
0
      { return XMSS_SHAKE_20_256; }
39
0
   if(param_set == "XMSS-SHAKE_10_512")
40
0
      { return XMSS_SHAKE_10_512; }
41
0
   if(param_set == "XMSS-SHAKE_16_512")
42
0
      { return XMSS_SHAKE_16_512; }
43
0
   if(param_set == "XMSS-SHAKE_20_512")
44
0
      { return XMSS_SHAKE_20_512; }
45
0
   throw Lookup_Error("Unknown XMSS algorithm param '" + param_set + "'");
46
0
   }
47
48
XMSS_Parameters::XMSS_Parameters(const std::string& param_set)
49
   : XMSS_Parameters(XMSS_Parameters::xmss_id_from_string(param_set))
50
0
   {
51
0
   }
52
53
XMSS_Parameters::XMSS_Parameters(xmss_algorithm_t oid)
54
   : m_oid(oid)
55
0
   {
56
0
   switch(oid)
57
0
      {
58
0
      case XMSS_SHA2_10_256:
59
0
         m_element_size = 32;
60
0
         m_w = 16;
61
0
         m_len = 67;
62
0
         m_tree_height = 10;
63
0
         m_name = "XMSS-SHA2_10_256";
64
0
         m_hash_name = "SHA-256";
65
0
         m_strength = 256;
66
0
         m_wots_oid = XMSS_WOTS_Parameters::ots_algorithm_t::WOTSP_SHA2_256;
67
0
         break;
68
0
      case XMSS_SHA2_16_256:
69
0
         m_element_size = 32;
70
0
         m_w = 16;
71
0
         m_len = 67;
72
0
         m_tree_height = 16;
73
0
         m_name = "XMSS-SHA2_16_256";
74
0
         m_hash_name = "SHA-256";
75
0
         m_strength = 256;
76
0
         m_wots_oid = XMSS_WOTS_Parameters::ots_algorithm_t::WOTSP_SHA2_256;
77
0
         break;
78
0
      case XMSS_SHA2_20_256:
79
0
         m_element_size = 32;
80
0
         m_w = 16;
81
0
         m_len = 67;
82
0
         m_tree_height = 20;
83
0
         m_name = "XMSS-SHA2_20_256";
84
0
         m_hash_name = "SHA-256";
85
0
         m_strength = 256;
86
0
         m_wots_oid = XMSS_WOTS_Parameters::ots_algorithm_t::WOTSP_SHA2_256;
87
0
         break;
88
0
      case XMSS_SHA2_10_512:
89
0
         m_element_size = 64;
90
0
         m_w = 16;
91
0
         m_len = 131;
92
0
         m_tree_height = 10;
93
0
         m_name = "XMSS-SHA2_10_512";
94
0
         m_hash_name = "SHA-512";
95
0
         m_strength = 512;
96
0
         m_wots_oid = XMSS_WOTS_Parameters::ots_algorithm_t::WOTSP_SHA2_512;
97
0
         break;
98
0
      case XMSS_SHA2_16_512:
99
0
         m_element_size = 64;
100
0
         m_w = 16;
101
0
         m_len = 131;
102
0
         m_tree_height = 16;
103
0
         m_name = "XMSS-SHA2_16_512";
104
0
         m_hash_name = "SHA-512";
105
0
         m_strength = 512;
106
0
         m_wots_oid = XMSS_WOTS_Parameters::ots_algorithm_t::WOTSP_SHA2_512;
107
0
         break;
108
0
      case XMSS_SHA2_20_512:
109
0
         m_element_size = 64;
110
0
         m_w = 16;
111
0
         m_len = 131;
112
0
         m_tree_height = 20;
113
0
         m_name = "XMSS-SHA2_20_512";
114
0
         m_hash_name = "SHA-512";
115
0
         m_strength = 512;
116
0
         m_wots_oid = XMSS_WOTS_Parameters::ots_algorithm_t::WOTSP_SHA2_512;
117
0
         break;
118
0
      case XMSS_SHAKE_10_256:
119
0
         m_element_size = 32;
120
0
         m_w = 16;
121
0
         m_len = 67;
122
0
         m_tree_height = 10;
123
0
         m_name = "XMSS-SHAKE_10_256";
124
0
         m_hash_name = "SHAKE-128(256)";
125
0
         m_strength = 256;
126
0
         m_wots_oid = XMSS_WOTS_Parameters::ots_algorithm_t::WOTSP_SHAKE_256;
127
0
         break;
128
0
      case XMSS_SHAKE_16_256:
129
0
         m_element_size = 32;
130
0
         m_w = 16;
131
0
         m_len = 67;
132
0
         m_tree_height = 16;
133
0
         m_name = "XMSS-SHAKE_16_256";
134
0
         m_hash_name = "SHAKE-128(256)";
135
0
         m_strength = 256;
136
0
         m_wots_oid = XMSS_WOTS_Parameters::ots_algorithm_t::WOTSP_SHAKE_256;
137
0
         break;
138
0
      case XMSS_SHAKE_20_256:
139
0
         m_element_size = 32;
140
0
         m_w = 16;
141
0
         m_len = 67;
142
0
         m_tree_height = 20;
143
0
         m_name = "XMSS-SHAKE_20_256";
144
0
         m_hash_name = "SHAKE-128(256)";
145
0
         m_strength = 256;
146
0
         m_wots_oid = XMSS_WOTS_Parameters::ots_algorithm_t::WOTSP_SHAKE_256;
147
0
         break;
148
0
      case XMSS_SHAKE_10_512:
149
0
         m_element_size = 64;
150
0
         m_w = 16;
151
0
         m_len = 131;
152
0
         m_tree_height = 10;
153
0
         m_name = "XMSS-SHAKE_10_512";
154
0
         m_hash_name = "SHAKE-256(512)";
155
0
         m_strength = 512;
156
0
         m_wots_oid = XMSS_WOTS_Parameters::ots_algorithm_t::WOTSP_SHAKE_512;
157
0
         break;
158
0
      case XMSS_SHAKE_16_512:
159
0
         m_element_size = 64;
160
0
         m_w = 16;
161
0
         m_len = 131;
162
0
         m_tree_height = 16;
163
0
         m_name = "XMSS-SHAKE_16_512";
164
0
         m_hash_name = "SHAKE-256(512)";
165
0
         m_strength = 512;
166
0
         m_wots_oid = XMSS_WOTS_Parameters::ots_algorithm_t::WOTSP_SHAKE_512;
167
0
         break;
168
0
      case XMSS_SHAKE_20_512:
169
0
         m_element_size = 64;
170
0
         m_w = 16;
171
0
         m_len = 131;
172
0
         m_tree_height = 20;
173
0
         m_name = "XMSS-SHAKE_20_512";
174
0
         m_hash_name = "SHAKE-256(512)";
175
0
         m_strength = 512;
176
0
         m_wots_oid = XMSS_WOTS_Parameters::ots_algorithm_t::WOTSP_SHAKE_512;
177
0
         break;
178
0
      default:
179
0
         throw Not_Implemented("Algorithm id does not match any known XMSS algorithm id:" + std::to_string(oid));
180
0
         break;
181
0
      }
182
0
   }
183
184
}