Botan 3.14.1
Crypto and TLS for C&
hss.cpp
Go to the documentation of this file.
1/**
2 * HSS - Hierarchical Signatures System (RFC 8554)
3 * (C) 2023,2026 Jack Lloyd
4 * 2023 Fabian Albert, Philippe Lieser - Rohde & Schwarz Cybersecurity GmbH
5 *
6 * Botan is released under the Simplified BSD License (see license.txt)
7 */
8
9#include <botan/internal/hss.h>
10
11#include <botan/rng.h>
12#include <botan/internal/algorithm_spec.h>
13#include <botan/internal/buffer_slicer.h>
14#include <botan/internal/buffer_stuffer.h>
15#include <botan/internal/concat_util.h>
16#include <botan/internal/fmt.h>
17#include <botan/internal/hss_lms_utils.h>
18#include <botan/internal/int_utils.h>
19#include <botan/internal/stateful_key_index_registry.h>
20#include <limits>
21
22namespace Botan {
23
24namespace {
25
26/**
27 * @brief The maximum number of levels in a HSS-LMS tree.
28 *
29 * RFC 8554 Section 6:
30 * The number of levels is denoted as L and is between one
31 * and eight, inclusive.
32 */
33constexpr HSS_Level HSS_MAX_LEVELS(8);
34
35/**
36 * @brief Domain-separation parameter for generation the seed of a child LMS tree.
37 *
38 * This comes from https://github.com/cisco/hash-sigs.
39 */
40constexpr uint16_t SEED_CHILD_SEED = 0xfffe;
41
42/**
43 * @brief Domain-separation parameter for generation the identifier of a child LMS tree.
44 *
45 * This comes from https://github.com/cisco/hash-sigs.
46 */
47constexpr uint16_t SEED_CHILD_I = 0xffff;
48
49/**
50 * @brief Check that the given @p hash_name is one of the supported hash functions for HSS-LMS.
51 */
52constexpr bool is_supported_hash_function(std::string_view hash_name) {
53 return hash_name == "SHA-256" || hash_name == "Truncated(SHA-256,192)" || hash_name == "SHAKE-256(256)" ||
54 hash_name == "SHAKE-256(192)";
55}
56
57/**
58 * Given an HSS index, i.e. the number of already created HSS signatures, return the lms leaf indices for
59 * the different LMS layers from root layer to bottom layer.
60 */
61std::vector<LMS_Tree_Node_Idx> derive_lms_leaf_indices_from_hss_index(HSS_Sig_Idx hss_idx,
62 const HSS_LMS_Params& hss_params) {
63 std::vector<LMS_Tree_Node_Idx> q(hss_params.L().get());
64 for(int32_t layer_ctr = hss_params.L().get() - 1; layer_ctr >= 0; --layer_ctr) {
65 HSS_Level layer(layer_ctr);
66 const HSS_LMS_Params::LMS_LMOTS_Params_Pair& layer_params = hss_params.params_at_level(layer);
67 const size_t layer_h = layer_params.lms_params().h();
68 q.at(layer.get()) =
69 checked_cast_to<LMS_Tree_Node_Idx>(hss_idx.get() % checked_cast_to<uint64_t>(1ULL << layer_h));
70 hss_idx = hss_idx >> layer_h;
71 }
72 BOTAN_ARG_CHECK(hss_idx == HSS_Sig_Idx(0), "HSS Tree is exhausted");
73
74 return q;
75}
76
77/**
78 * Encode the HSS-LMS parameter set, for use as the algorithm parameters
79 * in the key's Stateful_Key_Index_Registry identity.
80 */
81std::vector<uint8_t> hss_param_encoding(const HSS_LMS_Params& params) {
82 std::vector<uint8_t> enc;
83 enc.reserve(sizeof(uint32_t) * (1 + 2 * params.L().get()));
84
85 const auto append = [&](std::span<const uint8_t> bytes) { enc.insert(enc.end(), bytes.begin(), bytes.end()); };
86
87 append(store_be(params.L()));
88 for(HSS_Level layer(0); layer < params.L(); ++layer) {
89 const auto& layer_params = params.params_at_level(layer);
90 append(store_be(layer_params.lms_params().algorithm_type()));
91 append(store_be(layer_params.lmots_params().algorithm_type()));
92 }
93
94 return enc;
95}
96
97} // namespace
98
99HSS_LMS_Params::HSS_LMS_Params(std::vector<LMS_LMOTS_Params_Pair> lm_lmots_params) :
100 m_lms_lmots_params(std::move(lm_lmots_params)), m_max_sig_count(calc_max_sig_count()) {
101 BOTAN_ARG_CHECK(!m_lms_lmots_params.empty() && m_lms_lmots_params.size() <= HSS_MAX_LEVELS,
102 "Invalid number of levels");
103
104 const auto& hash_name = m_lms_lmots_params.front().lms_params().hash_name();
105 for(const auto& param : m_lms_lmots_params) {
106 BOTAN_ARG_CHECK(param.lms_params().hash_name() == hash_name && param.lmots_params().hash_name() == hash_name,
107 "Inconsistent hash functions are not allowed");
108 }
109}
110
111HSS_LMS_Params::HSS_LMS_Params(std::string_view algo_params) : m_max_sig_count(0) {
112 const auto wrap_in_hss_lms = [&]() {
113 if(algo_params.starts_with("HSS-LMS(")) {
114 return std::string(algo_params);
115 } else {
116 return fmt("HSS-LMS({})", algo_params);
117 }
118 }();
119 const AlgorithmSpec spec(wrap_in_hss_lms);
120
121 const auto m = spec.match("HSS-LMS({hash},{layer}...)");
122 BOTAN_ARG_CHECK(m.has_value(), "Invalid HSS-LMS parameters");
123 const auto layers = m->rest("layer");
124 BOTAN_ARG_CHECK(layers.size() <= HSS_MAX_LEVELS, "Invalid number of layer arguments");
125 const std::string hash(m->str("hash"));
126 BOTAN_ARG_CHECK(is_supported_hash_function(hash), "Supported HSS-LMS hash function");
127
128 for(const auto& layer : layers) {
129 const auto lm = layer.match("HW({h:int},{w:int})");
130 BOTAN_ARG_CHECK(lm.has_value(), "Invalid layer parameters");
131 const auto h = checked_cast_to_or_throw<uint8_t, Invalid_Argument>(lm->integer("h"), "Invalid tree height");
132 const auto w =
133 checked_cast_to_or_throw<uint8_t, Invalid_Argument>(lm->integer("w"), "Invalid Winternitz parameter");
134 m_lms_lmots_params.push_back({LMS_Params::create_or_throw(hash, h), LMOTS_Params::create_or_throw(hash, w)});
135 }
136 m_max_sig_count = calc_max_sig_count();
137}
138
139HSS_Sig_Idx HSS_LMS_Params::calc_max_sig_count() const {
140 uint32_t total_height_counter = 0;
141 for(HSS_Level level(0); level < L(); level++) {
142 total_height_counter += params_at_level(level).lms_params().h();
143 }
144 if(total_height_counter >= sizeof(HSS_Sig_Idx) * 8) {
145 return HSS_Sig_Idx(std::numeric_limits<HSS_Sig_Idx::wrapped_type>::max());
146 }
147 return HSS_Sig_Idx(1) << total_height_counter;
148}
149
151 m_hss_params(hss_params),
152 m_hss_seed(rng.random_vec<LMS_Seed>(m_hss_params.params_at_level(HSS_Level(0)).lms_params().m())),
153 m_identifier(rng.random_vec<LMS_Identifier>(LMS_IDENTIFIER_LEN)),
154 m_keyid(
155 "HSS-LMS", hss_param_encoding(m_hss_params), m_hss_params.max_sig_count().get(), m_hss_seed, m_identifier),
156 m_sig_size(HSS_Signature::size(m_hss_params)) {}
157
159 LMS_Seed hss_seed,
160 LMS_Identifier identifier) :
161 m_hss_params(std::move(hss_params)),
162 m_hss_seed(std::move(hss_seed)),
163 m_identifier(std::move(identifier)),
164 m_keyid(
165 "HSS-LMS", hss_param_encoding(m_hss_params), m_hss_params.max_sig_count().get(), m_hss_seed, m_identifier),
166 m_sig_size(HSS_Signature::size(m_hss_params)) {
167 BOTAN_ARG_CHECK(m_hss_seed.size() == m_hss_params.params_at_level(HSS_Level(0)).lms_params().m(),
168 "Invalid HSS-LMS seed size");
169 BOTAN_ARG_CHECK(m_identifier.size() == LMS_IDENTIFIER_LEN, "Invalid HSS-LMS identifier size");
170}
171
172std::shared_ptr<HSS_LMS_PrivateKeyInternal> HSS_LMS_PrivateKeyInternal::from_bytes_or_throw(
173 std::span<const uint8_t> key_bytes) {
174 if(key_bytes.size() < sizeof(HSS_Level) + sizeof(HSS_Sig_Idx)) {
175 throw Decoding_Error("Too few private key bytes.");
176 }
177 BufferSlicer slicer(key_bytes);
178
179 const auto L = load_be<HSS_Level>(slicer.take<sizeof(HSS_Level)>());
180 if(L == 0U || L > HSS_MAX_LEVELS) {
181 throw Decoding_Error("Invalid number of HSS layers in private HSS-LMS key.");
182 }
183
184 const auto sig_idx = load_be<HSS_Sig_Idx>(slicer.take<sizeof(HSS_Sig_Idx)>());
185
186 std::vector<HSS_LMS_Params::LMS_LMOTS_Params_Pair> params;
187 for(size_t layer = 1; layer <= L; ++layer) {
188 if(slicer.remaining() < sizeof(LMS_Algorithm_Type) + sizeof(LMOTS_Algorithm_Type)) {
189 throw Decoding_Error("Out of bytes while parsing private HSS-LMS key.");
190 }
191 const auto lms_type = load_be<LMS_Algorithm_Type>(slicer.take<sizeof(LMS_Algorithm_Type)>());
192 const auto lmots_type = load_be<LMOTS_Algorithm_Type>(slicer.take<sizeof(LMOTS_Algorithm_Type)>());
193 params.push_back({LMS_Params::create_or_throw(lms_type), LMOTS_Params::create_or_throw(lmots_type)});
194 }
195 const auto& hash_name = params.at(0).lms_params().hash_name();
196
197 for(const auto& param : params) {
198 const bool invalid_lmots_hash = param.lmots_params().hash_name() != hash_name;
199 const bool invalid_lms_hash = param.lms_params().hash_name() != hash_name;
200 if(invalid_lmots_hash || invalid_lms_hash) {
201 throw Decoding_Error("Inconsistent hash functions are not allowed.");
202 }
203 }
204
205 if(slicer.remaining() < params.at(0).lms_params().m() + LMS_IDENTIFIER_LEN) {
206 throw Decoding_Error("Out of bytes while parsing private HSS-LMS key.");
207 }
208 auto hss_seed = slicer.copy<LMS_Seed>(params.at(0).lms_params().m());
209 auto identifier = slicer.copy<LMS_Identifier>(LMS_IDENTIFIER_LEN);
210
211 if(!slicer.empty()) {
212 throw Decoding_Error("Private HSS-LMS key contains more bytes than expected.");
213 }
214 auto sk = std::shared_ptr<HSS_LMS_PrivateKeyInternal>(
215 new HSS_LMS_PrivateKeyInternal(HSS_LMS_Params(std::move(params)), std::move(hss_seed), std::move(identifier)));
216
217 sk->set_idx(sig_idx);
218 return sk;
219}
220
222 secure_vector<uint8_t> sk_bytes(size());
223 BufferStuffer stuffer(sk_bytes);
224
225 const uint64_t current_index = Stateful_Key_Index_Registry::global().current_index(m_keyid);
226
227 stuffer.append(store_be(hss_params().L()));
228 stuffer.append(store_be(current_index));
229
230 for(HSS_Level layer(1); layer <= hss_params().L(); ++layer) {
231 const auto& params = hss_params().params_at_level(layer - 1);
232 stuffer.append(store_be(params.lms_params().algorithm_type()));
233 stuffer.append(store_be(params.lmots_params().algorithm_type()));
234 }
235 stuffer.append(m_hss_seed);
236 stuffer.append(m_identifier);
237 BOTAN_ASSERT_NOMSG(stuffer.full());
238
239 return sk_bytes;
240}
241
245
247 // An index equal to max_sig_count is valid and denotes an exhausted key
248 if(idx > m_hss_params.max_sig_count()) {
249 throw Decoding_Error("HSS-LMS private key index out of bounds");
250 }
252}
253
254HSS_Sig_Idx HSS_LMS_PrivateKeyInternal::reserve_next_idx() const {
256 if(!idx.has_value()) {
257 throw Invalid_State("HSS private key is exhausted");
258 }
259 return HSS_Sig_Idx(idx.value());
260}
261
262size_t HSS_LMS_PrivateKeyInternal::size() const {
263 size_t sk_size = sizeof(HSS_Level) + sizeof(HSS_Sig_Idx);
264 // The concatenated algorithm types for all layers
265 sk_size += hss_params().L().get() * (sizeof(LMS_Algorithm_Type) + sizeof(LMOTS_Algorithm_Type));
266 sk_size += m_hss_seed.size() + m_identifier.size();
267 return sk_size;
268}
269
270std::vector<uint8_t> HSS_LMS_PrivateKeyInternal::sign(std::span<const uint8_t> msg) const {
271 std::vector<uint8_t> sig(HSS_Signature::size(hss_params()));
272 BufferStuffer sig_stuffer(sig);
273 sig_stuffer.append(store_be(hss_params().L() - 1));
274
275 std::vector<LMS_Tree_Node_Idx> q = derive_lms_leaf_indices_from_hss_index(reserve_next_idx(), hss_params());
276
277 // Derive LMS private keys and compute buffers
278 std::vector<LMS_PrivateKey> lms_key_at_layer;
279 std::vector<StrongSpan<LMS_Signature_Bytes>> out_lms_sig_buffer_at_layer;
280 std::vector<std::span<uint8_t>> out_child_pk_buffer_at_layer;
281 for(HSS_Level layer(0); layer < hss_params().L(); ++layer) {
282 // Generate key for current layer
284 if(layer == HSS_Level(0)) {
285 lms_key_at_layer.push_back(hss_derive_root_lms_private_key());
286 } else {
287 lms_key_at_layer.push_back(
288 hss_derive_child_lms_private_key(layer_params, lms_key_at_layer.back(), q.at(layer.get() - 1)));
289 out_child_pk_buffer_at_layer.push_back(sig_stuffer.next(LMS_PublicKey::size(layer_params.lms_params())));
290 }
291 out_lms_sig_buffer_at_layer.push_back(sig_stuffer.next<LMS_Signature_Bytes>(
292 LMS_Signature::size(layer_params.lms_params(), layer_params.lmots_params())));
293 }
294 BOTAN_ASSERT_NOMSG(sig_stuffer.full());
295
296 // Sign and write the signature from bottom layer to root layer
297 std::vector<uint8_t> current_pk;
298 for(int32_t layer_it = hss_params().L().get() - 1; layer_it >= 0; --layer_it) {
299 HSS_Level layer(layer_it);
300 if(layer == hss_params().L() - 1) {
301 current_pk =
302 lms_key_at_layer.at(layer.get())
303 .sign_and_get_pk(out_lms_sig_buffer_at_layer.at(layer.get()), q.at(layer.get()), LMS_Message(msg))
304 .to_bytes();
305 } else {
306 copy_mem(out_child_pk_buffer_at_layer.at(layer.get()), current_pk);
307 current_pk =
308 lms_key_at_layer.at(layer.get())
309 .sign_and_get_pk(out_lms_sig_buffer_at_layer.at(layer.get()), q.at(layer.get()), LMS_Message(current_pk))
310 .to_bytes();
311 }
312 }
313
314 return sig;
315}
316
318 const auto& top_params = hss_params().params_at_level(HSS_Level(0));
319 return LMS_PrivateKey(top_params.lms_params(), top_params.lmots_params(), m_identifier, m_hss_seed);
320}
321
322LMS_PrivateKey HSS_LMS_PrivateKeyInternal::hss_derive_child_lms_private_key(
323 const HSS_LMS_Params::LMS_LMOTS_Params_Pair& child_lms_lmots_params,
324 const LMS_PrivateKey& parent_sk,
325 LMS_Tree_Node_Idx parent_q) {
326 const auto hash = HashFunction::create_or_throw(child_lms_lmots_params.lms_params().hash_name());
327
328 // CHILD_SEED = H( PARENT_I || PARENT_Q || SEED_CHILD_SEED || 0xff || PARENT_SEED )
329 PseudorandomKeyGeneration seed_generator(parent_sk.identifier());
330 seed_generator.set_q(parent_q.get());
331 seed_generator.set_i(SEED_CHILD_SEED);
332 seed_generator.set_j(0xff);
333 auto child_seed = seed_generator.gen<LMS_Seed>(*hash, parent_sk.seed());
334
335 // CHILD_I = H( PARENT_I || PARENT_Q || SEED_CHILD_I || 0xff || PARENT_SEED )
336 seed_generator.set_i(SEED_CHILD_I);
337 auto child_identifier = seed_generator.gen<LMS_Identifier>(*hash, parent_sk.seed());
338 child_identifier.resize(LMS_IDENTIFIER_LEN);
339 CT::unpoison(child_identifier); // identifiers are part of the signature
340
341 return LMS_PrivateKey(child_lms_lmots_params.lms_params(),
342 child_lms_lmots_params.lmots_params(),
343 std::move(child_identifier),
344 std::move(child_seed));
345}
346
348 const auto& hss_params = hss_sk.hss_params();
349
350 const auto root_sk = hss_sk.hss_derive_root_lms_private_key();
351 LMS_PublicKey top_pub_key = LMS_PublicKey(root_sk);
352
353 return HSS_LMS_PublicKeyInternal(hss_params.L(), std::move(top_pub_key));
354}
355
356std::shared_ptr<HSS_LMS_PublicKeyInternal> HSS_LMS_PublicKeyInternal::from_bytes_or_throw(
357 std::span<const uint8_t> key_bytes) {
358 if(key_bytes.size() < sizeof(HSS_Level)) {
359 throw Decoding_Error("Too few public key bytes.");
360 }
361 BufferSlicer slicer(key_bytes);
362
363 const auto L = load_be<HSS_Level>(slicer.take<sizeof(HSS_Level)>());
364 if(L == 0U || L > HSS_MAX_LEVELS) {
365 throw Decoding_Error("Invalid number of HSS layers in public HSS-LMS key.");
366 }
367
369
370 if(!slicer.empty()) {
371 throw Decoding_Error("Public HSS-LMS key contains more bytes than expected.");
372 }
373 return std::make_shared<HSS_LMS_PublicKeyInternal>(L, std::move(lms_pub_key));
374}
375
376std::vector<uint8_t> HSS_LMS_PublicKeyInternal::to_bytes() const {
377 return concat<std::vector<uint8_t>>(store_be(m_L), m_top_lms_pub_key.to_bytes());
378}
379
383
387
389 return sizeof(m_L) + LMS_PublicKey::size(m_top_lms_pub_key.lms_params());
390}
391
392bool HSS_LMS_PublicKeyInternal::verify_signature(std::span<const uint8_t> msg, const HSS_Signature& sig) const {
393 if(checked_cast_to<HSS_Level>(sig.Nspk()) + 1 != m_L) {
394 // HSS levels in the public key does not match with the signature's
395 return false;
396 }
397
398 const LMS_PublicKey* lms_pk = &lms_pub_key();
399 const auto hash_name = lms_pk->lms_params().hash_name();
400
401 // Verify the signature by the above layer over the LMS public keys for layer 1 to Nspk.
402 for(HSS_Level layer(0); layer < sig.Nspk(); ++layer) {
403 const HSS_Signature::Signed_Pub_Key& signed_pub_key = sig.signed_pub_key(layer);
404 if(signed_pub_key.public_key().lms_params().hash_name() != hash_name ||
405 signed_pub_key.public_key().lmots_params().hash_name() != hash_name) {
406 // We do not allow HSS-LMS instances with multiple different hash functions.
407 return false;
408 }
409 if(!lms_pk->verify_signature(LMS_Message(signed_pub_key.public_key().to_bytes()), signed_pub_key.signature())) {
410 return false;
411 }
412 lms_pk = &signed_pub_key.public_key();
413 }
414
415 // Verify the signature by the bottom layer over the message.
416 return lms_pk->verify_signature(LMS_Message(msg), sig.bottom_sig());
417}
418
420 m_sig(std::move(sig)), m_pub(std::move(pub)) {}
421
422HSS_Signature HSS_Signature::from_bytes_or_throw(std::span<const uint8_t> sig_bytes) {
423 if(sig_bytes.size() < sizeof(uint32_t)) {
424 throw Decoding_Error("Too few HSS signature bytes.");
425 }
426 BufferSlicer slicer(sig_bytes);
427
428 const auto Nspk = load_be(slicer.take<sizeof(uint32_t)>());
429 if(Nspk >= HSS_MAX_LEVELS) {
430 throw Decoding_Error("Invalid number of HSS layers in signature.");
431 }
432
433 std::vector<Signed_Pub_Key> signed_pub_keys;
434 for(size_t i = 0; i < Nspk; ++i) {
437 signed_pub_keys.push_back(Signed_Pub_Key(std::move(sig), std::move(pub_key)));
438 }
439
440 auto sig = LMS_Signature::from_bytes_or_throw(slicer);
441
442 if(!slicer.empty()) {
443 throw Decoding_Error("HSS-LMS signature contains more bytes than expected.");
444 }
445 return HSS_Signature(std::move(signed_pub_keys), std::move(sig));
446}
447
448size_t HSS_Signature::size(const HSS_LMS_Params& params) {
449 size_t size = sizeof(uint32_t);
450 size += LMS_Signature::size(params.params_at_level(HSS_Level(0)).lms_params(),
451 params.params_at_level(HSS_Level(0)).lmots_params());
452 for(HSS_Level layer(1); layer < params.L(); ++layer) {
453 const auto& param = params.params_at_level(layer);
454 size += LMS_PublicKey::size(param.lms_params());
455 size += LMS_Signature::size(param.lms_params(), param.lmots_params());
456 }
457 return size;
458}
459
460} // namespace Botan
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:82
#define BOTAN_ARG_CHECK(expr, msg)
Definition assert.h:33
std::optional< AlgorithmMatch > match(const AlgorithmPattern &pattern) const &
size_t remaining() const
auto copy(const size_t count)
std::span< const uint8_t > take(const size_t count)
Helper class to ease in-place marshalling of concatenated fixed-length values.
constexpr void append(std::span< const uint8_t > buffer)
constexpr std::span< uint8_t > next(size_t bytes)
constexpr bool full() const
Represents a pair of LMS and LMOTS parameters associated with one LMS tree layer.
Definition hss.h:47
const LMS_Params & lms_params() const
The LMS parameters.
Definition hss.h:52
const LMOTS_Params & lmots_params() const
The LMOTS parameters.
Definition hss.h:57
The HSS-LMS parameters.
Definition hss.h:42
const LMS_LMOTS_Params_Pair & params_at_level(HSS_Level level) const
Returns the LMS an LM-OTS parameters at the specified level of the HSS tree.
Definition hss.h:99
HSS_Level L() const
Returns the number of layers the HSS tree has.
Definition hss.h:104
HSS_LMS_Params(std::vector< LMS_LMOTS_Params_Pair > lm_lmots_params)
Construct the HSS-LMS parameters from a vector LMS and LM-OTS parameters.
Definition hss.cpp:99
The internal HSS-LMS private key.
Definition hss.h:127
static std::shared_ptr< HSS_LMS_PrivateKeyInternal > from_bytes_or_throw(std::span< const uint8_t > key_bytes)
Parse a private HSS-LMS key.
Definition hss.cpp:172
const HSS_LMS_Params & hss_params() const
Returns the used HSS-LMS parameters.
Definition hss.h:149
LMS_PrivateKey hss_derive_root_lms_private_key() const
Create the HSS root LMS tree's LMS_PrivateKey using the HSS-LMS private key.
Definition hss.cpp:317
secure_vector< uint8_t > to_bytes() const
Returns the key in its encoded format.
Definition hss.cpp:221
void set_idx(HSS_Sig_Idx idx) const
Set the idx of the next signature to generate.
Definition hss.cpp:246
HSS_Sig_Idx remaining_operations() const
Get the number of remaining signatures for this key.
Definition hss.cpp:242
HSS_LMS_PrivateKeyInternal(const HSS_LMS_Params &hss_params, RandomNumberGenerator &rng)
Create an internal HSS-LMS private key.
Definition hss.cpp:150
std::vector< uint8_t > sign(std::span< const uint8_t > msg) const
Create a HSS-LMS signature.
Definition hss.cpp:270
static std::shared_ptr< HSS_LMS_PublicKeyInternal > from_bytes_or_throw(std::span< const uint8_t > key_bytes)
Parse a public HSS-LMS key.
Definition hss.cpp:356
bool verify_signature(std::span< const uint8_t > msg, const HSS_Signature &sig) const
Verify a HSS-LMS signature.
Definition hss.cpp:392
std::vector< uint8_t > to_bytes() const
Returns the key in its encoded format.
Definition hss.cpp:376
std::string algo_name() const
The algorithm name for HSS-LMS.
Definition hss.h:302
size_t size() const
Returns the size in bytes the key would have in its encoded format.
Definition hss.cpp:388
OID object_identifier() const
The object identifier for HSS-LMS.
Definition hss.cpp:384
static HSS_LMS_PublicKeyInternal create(const HSS_LMS_PrivateKeyInternal &hss_sk)
Create the public HSS-LMS key from its private key.
Definition hss.cpp:347
HSS_LMS_PublicKeyInternal(HSS_Level L, LMS_PublicKey top_lms_pub_key)
Definition hss.h:271
AlgorithmIdentifier algorithm_identifier() const
The algorithm identifier for HSS-LMS.
Definition hss.cpp:380
const LMS_PublicKey & lms_pub_key() const
Returns the public LMS key of the top LMS tree.
Definition hss.h:282
A LMS public key signed by the HSS layer above it.
Definition hss.h:336
Signed_Pub_Key(LMS_Signature sig, LMS_PublicKey pub)
Constructor for a new sig-pubkey-pair.
Definition hss.cpp:419
const LMS_Signature & signature() const
The signature of the public key.
Definition hss.h:346
const LMS_PublicKey & public_key() const
The signed public key.
Definition hss.h:351
A HSS-LMS signature.
Definition hss.h:328
static size_t size(const HSS_LMS_Params &params)
Returns the size a signature would have in its encoded format.
Definition hss.cpp:448
const LMS_Signature & bottom_sig() const
Returns the LMS signature by the bottom layer of the signed message.
Definition hss.h:391
HSS_Level Nspk() const
Returns the number of signed public keys (Nspk = L-1).
Definition hss.h:378
const Signed_Pub_Key & signed_pub_key(HSS_Level layer) const
Returns the signed LMS key signed by a specific layer.
Definition hss.h:386
static HSS_Signature from_bytes_or_throw(std::span< const uint8_t > sig_bytes)
Parse a HSS-LMS signature.
Definition hss.cpp:422
static std::unique_ptr< HashFunction > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition hash.cpp:311
static LMOTS_Params create_or_throw(LMOTS_Algorithm_Type type)
Create the LM-OTS parameters from a known algorithm type.
Definition lm_ots.cpp:131
const std::string & hash_name() const
Name of the hash function to use.
Definition lm_ots.h:154
const LMS_Params & lms_params() const
The LMS parameters for this LMS instance.
Definition lms.h:166
const LMOTS_Params & lmots_params() const
The LMOTS parameters used for OTS instances of this LMS instance.
Definition lms.h:171
const LMS_Identifier & identifier() const
The identifier of this LMS tree ('I' in RFC 8554).
Definition lms.h:176
const std::string & hash_name() const
Returns the name of the hash function to use.
Definition lms.h:126
uint8_t h() const
Returns the height of the LMS tree.
Definition lms.h:116
static LMS_Params create_or_throw(LMS_Algorithm_Type type)
Create the LMS parameters from a known algorithm type.
Definition lms.cpp:145
Representation of an LMS Private key.
Definition lms.h:192
const LMS_Seed & seed() const
The secret seed used for LMOTS' WOTS chain input creation (RFC 8554 Appendix A).
Definition lms.h:203
The LMS public key.
Definition lms.h:227
static size_t size(const LMS_Params &lms_params)
The expected size of an LMS public key for given lms_params.
Definition lms.cpp:346
std::vector< uint8_t > to_bytes() const
Bytes of the full lms public key according to 8554 5.3.
Definition lms.cpp:327
static LMS_PublicKey from_bytes_or_throw(BufferSlicer &slicer)
Parse a public LMS key.
Definition lms.cpp:297
bool verify_signature(const LMS_Message &msg, const LMS_Signature &sig) const
Verify a LMS signature.
Definition lms.cpp:386
Container for LMS Signature data.
Definition lms.h:295
static LMS_Signature from_bytes_or_throw(BufferSlicer &slicer)
Parse the bytes of a lms signature into a LMS Signature object.
Definition lms.cpp:350
static size_t size(const LMS_Params &lms_params, const LMOTS_Params &lmots_params)
Definition lms.cpp:453
static OID from_string(std::string_view str)
Definition asn1_oid.cpp:80
Helper class used to derive secret values based in the pseudorandom key generation described in RFC 8...
std::optional< uint64_t > reserve_next_index(const KeyId &key_id)
void set_index_lower_bound(const KeyId &key_id, uint64_t min)
static Stateful_Key_Index_Registry & global()
size_type size() const noexcept(noexcept(this->get().size()))
constexpr T & get() &
Definition strong_type.h:81
constexpr void unpoison(const T *p, size_t n)
Definition ct_utils.h:67
LMS_Algorithm_Type
Enum of available LMS algorithm types.
Definition lms.h:32
std::string fmt(std::string_view format, const T &... args)
Definition fmt.h:53
constexpr size_t LMS_IDENTIFIER_LEN
The length in bytes of the LMS identifier (I).
Definition lms.h:69
Strong< uint64_t, struct HSS_Sig_Idx_, EnableArithmeticWithPlainNumber > HSS_Sig_Idx
The index of a node within a specific LMS tree layer.
Definition hss.h:30
constexpr RT checked_cast_to(AT i)
Definition int_utils.h:104
Strong< std::vector< uint8_t >, struct LMS_Signature_Bytes_ > LMS_Signature_Bytes
Raw bytes of an LMS signature.
Definition lms.h:84
Strong< std::vector< uint8_t >, struct LMS_Identifier_ > LMS_Identifier
The identifier of an LMS tree (I in RFC 8554).
Definition lm_ots.h:54
constexpr void copy_mem(T *out, const T *in, size_t n)
Definition mem_ops.h:144
LMOTS_Algorithm_Type
Enum of available LM-OTS algorithm types.
Definition lm_ots.h:69
Strong< secure_vector< uint8_t >, struct LMS_SEED_ > LMS_Seed
Seed of the LMS tree, used to generate the LM-OTS private keys.
Definition lm_ots.h:29
void append(std::vector< T, Alloc > &out, std::type_identity_t< std::span< const T > > in)
constexpr RT checked_cast_to_or_throw(AT i, std::string_view error_msg_on_fail)
Definition int_utils.h:91
Strong< std::vector< uint8_t >, struct LMS_Message_ > LMS_Message
A message that is signed with an LMS tree.
Definition lm_ots.h:59
constexpr auto concat(Rs &&... ranges)
Definition concat_util.h:95
Strong< uint32_t, struct HSS_Level_, EnableArithmeticWithPlainNumber > HSS_Level
The HSS layer in the HSS multi tree starting at 0 from the root.
Definition hss.h:35
Strong< uint32_t, struct LMS_Tree_Node_Idx_, EnableArithmeticWithPlainNumber > LMS_Tree_Node_Idx
The index of a node within a specific LMS tree layer.
Definition lm_ots.h:49
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:128
constexpr auto store_be(ParamTs &&... params)
Definition loadstor.h:745
constexpr auto load_be(ParamTs &&... params)
Definition loadstor.h:504