Botan 3.14.1
Crypto and TLS for C&
lm_ots.cpp
Go to the documentation of this file.
1/**
2 * LM-OTS - Leighton-Micali One-Time Signatures
3 * (C) 2023 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/lm_ots.h>
10
11#include <botan/exceptn.h>
12#include <botan/strong_type.h>
13#include <botan/internal/bit_ops.h>
14#include <botan/internal/buffer_slicer.h>
15#include <botan/internal/buffer_stuffer.h>
16#include <botan/internal/ct_utils.h>
17#include <botan/internal/hash_engine.h>
18#include <botan/internal/hss_lms_utils.h>
19#include <botan/internal/int_utils.h>
20
21namespace Botan {
22
23namespace {
24constexpr uint16_t D_PBLC = 0x8080;
25constexpr uint16_t D_MESG = 0x8181;
26/// For derivation of C as in https://github.com/cisco/hash-sigs
27constexpr uint16_t C_INDEX = 0xFFFD;
28
29/**
30 * Steps many hash chains at once, computing for each selected lane
31 * Hash(identifier || u32str(q) || u16str(i) || u8str(j) || inputs[lane])
32 *
33 * The lanes cover the p chains of one or more consecutive LM-OTS
34 * instances, instance-major (all chains of first_q, then those of
35 * first_q + 1, ...).
36 */
37class Batch_Chain_Generator {
38 public:
39 Batch_Chain_Generator(
40 Hash_Engine& engine, const LMS_Identifier& identifier, LMS_Tree_Node_Idx first_q, size_t q_count, uint16_t p) :
41 m_engine(engine),
42 m_prefix_len(identifier.size() + sizeof(uint32_t) + sizeof(uint16_t) + sizeof(uint8_t)),
43 m_prefixes(q_count * p * m_prefix_len) {
44 for(size_t lane = 0; lane != q_count * p; ++lane) {
45 BufferStuffer prefix(chain_prefix(lane));
46 prefix.append(identifier);
47 prefix.append(store_be(LMS_Tree_Node_Idx(first_q.get() + static_cast<uint32_t>(lane / p))));
48 prefix.append(store_be(static_cast<uint16_t>(lane % p)));
49 prefix.next(1)[0] = 0;
50 }
51 }
52
53 Batch_Chain_Generator(Hash_Engine& engine, const LMS_Identifier& identifier, LMS_Tree_Node_Idx q, uint16_t p) :
54 Batch_Chain_Generator(engine, identifier, q, 1, p) {}
55
56 void process(std::span<const uint16_t> lanes,
57 uint8_t j,
58 std::span<std::span<uint8_t>> outputs,
59 std::span<std::span<const uint8_t>> inputs) {
60 m_prefix_spans.resize(lanes.size());
61 for(size_t c = 0; c != lanes.size(); ++c) {
62 const auto prefix = chain_prefix(lanes[c]);
63 prefix[m_prefix_len - 1] = j;
64 m_prefix_spans[c] = prefix;
65 }
66 m_engine.batch_hash(outputs, m_prefix_spans, inputs);
67 }
68
69 private:
70 std::span<uint8_t> chain_prefix(size_t lane) {
71 return std::span(m_prefixes).subspan(lane * m_prefix_len, m_prefix_len);
72 }
73
74 Hash_Engine& m_engine;
75 size_t m_prefix_len;
76 std::vector<uint8_t> m_prefixes;
77 std::vector<std::span<const uint8_t>> m_prefix_spans;
78};
79
80// RFC 8554 3.1.1
81uint8_t byte(std::span<const uint8_t> S, uint32_t i) {
82 BOTAN_ARG_CHECK(i < S.size(), "Index out of range");
83 return S[i];
84}
85
86// RFC 8554 3.1.3
87uint8_t coef(std::span<const uint8_t> S, uint32_t i, const LMOTS_Params& params) {
88 const uint8_t w_bit_mask = params.coef_max();
89 const uint8_t coef_byte = byte(S, (i * params.w()) / 8);
90 const uint8_t shift = 8 - (params.w() * (i % (8 / params.w())) + params.w());
91
92 return w_bit_mask & (coef_byte >> shift);
93}
94
95// RFC 8554 4.4
96uint16_t checksum(const LMOTS_Params& params, std::span<const uint8_t> S) {
97 size_t sum = 0;
98 for(uint32_t i = 0; i < (params.n() * 8 / params.w()); ++i) {
99 sum += params.coef_max() - coef(S, i, params);
100 }
101 return checked_cast_to<uint16_t>(sum << params.ls());
102}
103
104std::vector<uint8_t> gen_Q_with_cksm(const LMOTS_Params& params,
105 const LMS_Identifier& identifier,
106 const LMS_Tree_Node_Idx& q,
107 std::span<const uint8_t> C,
108 const LMS_Message& msg) {
109 std::vector<uint8_t> Q_with_cksm(params.n() + sizeof(uint16_t));
110 BufferStuffer qwc_stuffer(Q_with_cksm);
111 const auto hash = params.hash();
112 hash->update(identifier);
113 hash->update(store_be(q));
114 hash->update(store_be(D_MESG));
115 hash->update(C);
116 hash->update(msg);
117 const auto Q_span = qwc_stuffer.next(params.n());
118 hash->final(Q_span);
119
120 qwc_stuffer.append(store_be(checksum(params, Q_span)));
121
122 return Q_with_cksm;
123}
124
125} // namespace
126
127std::unique_ptr<HashFunction> LMOTS_Params::hash() const {
129}
130
132 auto [hash_name, w] = [](const LMOTS_Algorithm_Type& lmots_type) -> std::pair<std::string_view, uint8_t> {
133 switch(lmots_type) {
135 return {"SHA-256", static_cast<uint8_t>(1)};
137 return {"SHA-256", static_cast<uint8_t>(2)};
139 return {"SHA-256", static_cast<uint8_t>(4)};
141 return {"SHA-256", static_cast<uint8_t>(8)};
143 return {"Truncated(SHA-256,192)", static_cast<uint8_t>(1)};
145 return {"Truncated(SHA-256,192)", static_cast<uint8_t>(2)};
147 return {"Truncated(SHA-256,192)", static_cast<uint8_t>(4)};
149 return {"Truncated(SHA-256,192)", static_cast<uint8_t>(8)};
151 return {"SHAKE-256(256)", static_cast<uint8_t>(1)};
153 return {"SHAKE-256(256)", static_cast<uint8_t>(2)};
155 return {"SHAKE-256(256)", static_cast<uint8_t>(4)};
157 return {"SHAKE-256(256)", static_cast<uint8_t>(8)};
159 return {"SHAKE-256(192)", static_cast<uint8_t>(1)};
161 return {"SHAKE-256(192)", static_cast<uint8_t>(2)};
163 return {"SHAKE-256(192)", static_cast<uint8_t>(4)};
165 return {"SHAKE-256(192)", static_cast<uint8_t>(8)};
167 throw Decoding_Error("Unsupported LMS algorithm type");
168 }
169 throw Decoding_Error("Unsupported LMS algorithm type");
170 }(type);
171
172 return LMOTS_Params(type, hash_name, w);
173}
174
175LMOTS_Params LMOTS_Params::create_or_throw(std::string_view hash_name, uint8_t w) {
176 if(w != 1 && w != 2 && w != 4 && w != 8) {
177 throw Decoding_Error("Invalid Winternitz parameter");
178 }
179 const LMOTS_Algorithm_Type type = [](std::string_view hash, uint8_t w_p) -> LMOTS_Algorithm_Type {
180 if(hash == "SHA-256") {
181 switch(w_p) {
182 case 1:
184 case 2:
186 case 4:
188 case 8:
190 default:
191 throw Decoding_Error("Unsupported Winternitz parameter");
192 }
193 }
194 if(hash == "Truncated(SHA-256,192)") {
195 switch(w_p) {
196 case 1:
198 case 2:
200 case 4:
202 case 8:
204 default:
205 throw Decoding_Error("Unsupported Winternitz parameter");
206 }
207 }
208 if(hash == "SHAKE-256(256)") {
209 switch(w_p) {
210 case 1:
212 case 2:
214 case 4:
216 case 8:
218 default:
219 throw Decoding_Error("Unsupported Winternitz parameter");
220 }
221 }
222 if(hash == "SHAKE-256(192)") {
223 switch(w_p) {
224 case 1:
226 case 2:
228 case 4:
230 case 8:
232 default:
233 throw Decoding_Error("Unsupported Winternitz parameter");
234 }
235 }
236 throw Decoding_Error("Unsupported hash function");
237 }(hash_name, w);
238
239 return LMOTS_Params(type, hash_name, w);
240}
241
242LMOTS_Params::LMOTS_Params(LMOTS_Algorithm_Type algorithm_type, std::string_view hash_name, uint8_t w) :
243 m_algorithm_type(algorithm_type), m_w(w), m_hash_name(hash_name) {
244 const auto hash = HashFunction::create_or_throw(m_hash_name);
245 m_n = hash->output_length();
246 // RFC 8553 Appendix B - Parameter Computation
247 const auto u = ceil_division<size_t>(8 * m_n, m_w); // ceil(8*n/w)
248 const auto v =
249 ceil_division<size_t>(high_bit(((1 << m_w) - 1) * u), m_w); // ceil((floor(lg[(2^w - 1) * u]) + 1) / w)
250 m_ls = checked_cast_to<uint8_t>(16 - (v * w));
251 m_p = checked_cast_to<uint16_t>(u + v);
252}
253
254LMOTS_Signature::LMOTS_Signature(LMOTS_Algorithm_Type lmots_type,
255 std::vector<uint8_t> C,
256 std::vector<uint8_t> y_buffer) :
257 m_algorithm_type(lmots_type), m_C(std::move(C)), m_y_buffer(std::move(y_buffer)) {
258 const LMOTS_Params params = LMOTS_Params::create_or_throw(m_algorithm_type);
259
260 BOTAN_ASSERT_NOMSG(m_C.size() == params.n());
261 BOTAN_ASSERT_NOMSG(m_y_buffer.size() == params.p() * params.n());
262}
263
265 // C is n bytes long, as is each element of y
266 const size_t n = m_C.size();
267 BOTAN_ARG_CHECK((static_cast<size_t>(chain_idx) + 1) * n <= m_y_buffer.size(), "Invalid LM-OTS chain index");
268 return StrongSpan<const LMOTS_Node>(std::span(m_y_buffer).subspan(chain_idx * n, n));
269}
270
272 const size_t total_remaining_bytes = slicer.remaining();
273 // Alg. 6a. 1. (last 4 bytes) / Alg. 4b. 1.
274 if(total_remaining_bytes < sizeof(LMOTS_Algorithm_Type)) {
275 throw Decoding_Error("Too few signature bytes while parsing LMOTS signature.");
276 }
277 // Alg. 6a. 2.b. / Alg. 4b. 2.a.
279
280 // Alg. 6a. 2.d. / Alg. 4b. 2.c.
282
283 if(total_remaining_bytes < size(params)) {
284 throw Decoding_Error("Too few signature bytes while parsing LMOTS signature.");
285 }
286
287 // Alg. 4b. 2.d.
288 auto C = slicer.copy_as_vector(params.n());
289 // Alg. 4b. 2.e.
290 auto m_y_buffer = slicer.copy_as_vector(params.p() * params.n());
291
292 return LMOTS_Signature(algorithm_type, std::move(C), std::move(m_y_buffer));
293}
294
298 const LMS_Seed& seed) :
299 LMOTS_Private_Key(params, identifier, q, seed, *Hash_Engine::create_or_throw(params.hash_name())) {}
300
304 const LMS_Seed& seed,
305 Hash_Engine& engine) :
306 OTS_Instance(params, identifier, q), m_seed(seed) {
307 const uint16_t p = params.p();
308
309 m_ots_sk.reserve(p);
310 std::vector<uint16_t> chains(p);
311 std::vector<std::span<uint8_t>> outputs(p);
312 std::vector<std::span<const uint8_t>> inputs(p);
313 for(uint16_t i = 0; i < p; ++i) {
314 m_ots_sk.emplace_back(params.n());
315 chains[i] = i;
316 outputs[i] = std::span<uint8_t>(m_ots_sk.back().get());
317 inputs[i] = std::span<const uint8_t>(seed.get());
318 }
319
320 Batch_Chain_Generator chain_gen(engine, identifier, q, p);
321 chain_gen.process(chains, 0xff, outputs, inputs);
322}
323
325 BOTAN_ARG_CHECK(out_sig.size() == LMOTS_Signature::size(params()), "Invalid output buffer size");
326 BufferStuffer sig_stuffer(out_sig);
327 const auto hash = params().hash();
328 sig_stuffer.append(store_be(params().algorithm_type()));
329 const auto C = sig_stuffer.next(params().n());
330
331 // Since we do not store the signatures of the lms trees in the HSS sk,
332 // we need deterministic signatures to avoid reusing a OTS key to generate multiple signatures.
333 // See also: https://github.com/cisco/hash-sigs/blob/b0631b8891295bf2929e68761205337b7c031726/lm_ots_sign.c#L110-L115
334 derive_random_C(C, *hash);
335 CT::unpoison(C); // contained in signature
336
337 const auto Q_with_cksm = gen_Q_with_cksm(params(), identifier(), q(), C, msg);
338
339 const uint16_t p = params().p();
340 const size_t n = params().n();
341 const auto y = sig_stuffer.next(p * n);
342 BOTAN_ASSERT_NOMSG(sig_stuffer.full());
343
344 std::vector<uint8_t> a(p);
345 for(uint16_t i = 0; i < p; ++i) {
346 a[i] = coef(Q_with_cksm, i, params());
347 copy_mem(y.subspan(i * n, n), chain_input(i));
348 }
349
350 const auto engine = Hash_Engine::create_or_throw(params().hash_name());
351 Batch_Chain_Generator chain_gen(*engine, identifier(), q(), p);
352
353 std::vector<uint16_t> active;
354 std::vector<std::span<uint8_t>> outputs;
355 std::vector<std::span<const uint8_t>> inputs;
356 active.reserve(p);
357 outputs.reserve(p);
358 inputs.reserve(p);
359
360 // Chain i takes a[i] steps in total; step all unfinished chains together
361 for(uint8_t j = 0;; ++j) {
362 active.clear();
363 outputs.clear();
364 inputs.clear();
365 for(uint16_t i = 0; i < p; ++i) {
366 if(j < a[i]) {
367 active.push_back(i);
368 const auto node = y.subspan(i * n, n);
369 outputs.push_back(node);
370 inputs.push_back(node);
371 }
372 }
373 if(active.empty()) {
374 break;
375 }
376 chain_gen.process(active, j, outputs, inputs);
377 }
378}
379
380void LMOTS_Private_Key::derive_random_C(std::span<uint8_t> out, HashFunction& hash) const {
382
383 gen.set_q(q().get());
384 gen.set_i(C_INDEX);
385 gen.set_j(0xff);
386
387 gen.gen(out, hash, m_seed);
388}
389
391 LMOTS_Public_Key(lmots_sk, *Hash_Engine::create_or_throw(lmots_sk.params().hash_name())) {}
392
394 /* NOLINT(*-slicing) */ OTS_Instance(lmots_sk) {
395 const uint16_t p = lmots_sk.params().p();
396 const size_t n = lmots_sk.params().n();
397
398 // Walk all chains to the top in lock-step
399 secure_vector<uint8_t> nodes(p * n);
400 std::vector<uint16_t> chains(p);
401 std::vector<std::span<uint8_t>> outputs(p);
402 std::vector<std::span<const uint8_t>> inputs(p);
403 for(uint16_t i = 0; i < p; ++i) {
404 chains[i] = i;
405 const auto node = std::span(nodes).subspan(i * n, n);
406 copy_mem(node, lmots_sk.chain_input(i));
407 outputs[i] = node;
408 inputs[i] = node;
409 }
410
411 Batch_Chain_Generator chain_gen(engine, lmots_sk.identifier(), lmots_sk.q(), p);
412 for(uint8_t j = 0; j < lmots_sk.params().coef_max(); ++j) {
413 chain_gen.process(chains, j, outputs, inputs);
414 }
415
416 const auto pk_hash = lmots_sk.params().hash();
417 pk_hash->update(lmots_sk.identifier());
418 pk_hash->update(store_be(lmots_sk.q()));
419 pk_hash->update(store_be(D_PBLC));
420 pk_hash->update(nodes);
421 m_K = pk_hash->final<LMOTS_K>();
422}
423
424void lmots_compute_pubkeys(std::span<uint8_t> out_ks,
425 const LMOTS_Params& params,
426 const LMS_Identifier& identifier,
427 LMS_Tree_Node_Idx first_q,
428 size_t count,
429 const LMS_Seed& seed,
430 Hash_Engine& engine) {
431 BOTAN_ASSERT_NOMSG(out_ks.size() == count * params.n());
432
433 const uint16_t p = params.p();
434 const size_t n = params.n();
435 const size_t lanes = count * p;
436 BOTAN_ASSERT_NOMSG(lanes <= 0xFFFF);
437
438 secure_vector<uint8_t> nodes(lanes * n);
439
440 std::vector<uint16_t> lane_ids(lanes);
441 std::vector<std::span<uint8_t>> outputs(lanes);
442 std::vector<std::span<const uint8_t>> inputs(lanes);
443 for(size_t l = 0; l != lanes; ++l) {
444 lane_ids[l] = static_cast<uint16_t>(l);
445 outputs[l] = std::span(nodes).subspan(l * n, n);
446 inputs[l] = std::span<const uint8_t>(seed.get());
447 }
448
449 Batch_Chain_Generator chain_gen(engine, identifier, first_q, count, p);
450
451 // Derive the secret chain inputs (x[] in RFC 8554 4.2)
452 chain_gen.process(lane_ids, 0xff, outputs, inputs);
453
454 // Walk all chains of all instances to the top in lock-step
455 for(size_t l = 0; l != lanes; ++l) {
456 inputs[l] = outputs[l];
457 }
458 for(uint8_t j = 0; j < params.coef_max(); ++j) {
459 chain_gen.process(lane_ids, j, outputs, inputs);
460 }
461
462 // Compute each instance's K over its chain ends (RFC 8554 4.3)
463 const size_t k_prefix_len = identifier.size() + sizeof(uint32_t) + sizeof(uint16_t);
464 std::vector<uint8_t> k_prefixes(count * k_prefix_len);
465 std::vector<std::span<uint8_t>> k_outs(count);
466 std::vector<std::span<const uint8_t>> k_prefix_spans(count);
467 std::vector<std::span<const uint8_t>> k_nodes(count);
468 for(size_t i = 0; i != count; ++i) {
469 const auto prefix_span = std::span(k_prefixes).subspan(i * k_prefix_len, k_prefix_len);
470 BufferStuffer prefix(prefix_span);
471 prefix.append(identifier);
472 prefix.append(store_be(LMS_Tree_Node_Idx(first_q.get() + static_cast<uint32_t>(i))));
473 prefix.append(store_be(D_PBLC));
474 k_prefix_spans[i] = prefix_span;
475 k_outs[i] = out_ks.subspan(i * n, n);
476 k_nodes[i] = std::span(nodes).subspan(i * p * n, p * n);
477 }
478 engine.batch_hash(k_outs, k_prefix_spans, k_nodes);
479}
480
482 const LMS_Message& msg,
483 const LMS_Identifier& identifier,
485 const auto params = LMOTS_Params::create_or_throw(sig.algorithm_type());
486
487 // Alg. 4b 3.
488
489 const auto Q_with_cksm = gen_Q_with_cksm(params, identifier, q, sig.C(), msg);
490
491 const uint16_t p = params.p();
492 const size_t n = params.n();
493
494 secure_vector<uint8_t> nodes(p * n);
495 std::vector<uint8_t> a(p);
496 for(uint16_t i = 0; i < p; ++i) {
497 a[i] = coef(Q_with_cksm, i, params);
498 copy_mem(std::span(nodes).subspan(i * n, n), sig.y(i));
499 }
500
501 const auto engine = Hash_Engine::create_or_throw(params.hash_name());
502 Batch_Chain_Generator chain_gen(*engine, identifier, q, p);
503
504 std::vector<uint16_t> active;
505 std::vector<std::span<uint8_t>> outputs;
506 std::vector<std::span<const uint8_t>> inputs;
507 active.reserve(p);
508 outputs.reserve(p);
509 inputs.reserve(p);
510
511 // Chain i continues from position a[i] up to the top
512 for(uint8_t j = 0; j < params.coef_max(); ++j) {
513 active.clear();
514 outputs.clear();
515 inputs.clear();
516 for(uint16_t i = 0; i < p; ++i) {
517 if(a[i] <= j) {
518 active.push_back(i);
519 const auto node = std::span(nodes).subspan(i * n, n);
520 outputs.push_back(node);
521 inputs.push_back(node);
522 }
523 }
524 if(!active.empty()) {
525 chain_gen.process(active, j, outputs, inputs);
526 }
527 }
528
529 // Prefill the final hash object
530 const auto pk_hash = params.hash();
531 pk_hash->update(identifier);
532 pk_hash->update(store_be(q));
533 pk_hash->update(store_be(D_PBLC));
534 pk_hash->update(nodes);
535 // Alg. 4b 4.
536 return pk_hash->final<LMOTS_K>();
537}
538
539} // namespace Botan
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:82
#define BOTAN_ARG_CHECK(expr, msg)
Definition assert.h:33
size_t remaining() const
std::span< const uint8_t > take(const size_t count)
auto copy_as_vector(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
static std::unique_ptr< HashFunction > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition hash.cpp:311
static std::unique_ptr< Hash_Engine > create_or_throw(std::string_view hash_fn, std::span< const uint8_t > common_prefix={}, std::string_view provider="")
void batch_hash(std::span< std::span< uint8_t > > outputs, std::span< std::span< const uint8_t > > inputs)
Definition hash_engine.h:57
The LM-OTS parameters.
Definition lm_ots.h:104
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
uint8_t coef_max() const
The maximum the winternitz coefficients can have.
Definition lm_ots.h:139
std::unique_ptr< HashFunction > hash() const
Construct a new hash instance for the OTS instance.
Definition lm_ots.cpp:127
size_t n() const
The number of bytes of the output of the hash function.
Definition lm_ots.h:129
uint8_t w() const
The width (in bits) of the Winternitz coefficients.
Definition lm_ots.h:134
const std::string & hash_name() const
Name of the hash function to use.
Definition lm_ots.h:154
uint16_t p() const
The number of n-byte string elements that make up the LM-OTS signature.
Definition lm_ots.h:144
Representation of an LMOTS private key.
Definition lm_ots.h:260
const LMOTS_Node & chain_input(uint16_t chain_idx) const
The secret chain input at a given chain index. (x[] in RFC 8554 4.2).
Definition lm_ots.h:285
void sign(StrongSpan< LMOTS_Signature_Bytes > out_sig, const LMS_Message &msg) const
Generate a new LMOTS signature.
Definition lm_ots.cpp:324
LMOTS_Private_Key(const LMOTS_Params &params, const LMS_Identifier &identifier, LMS_Tree_Node_Idx q, const LMS_Seed &seed)
Derive a LMOTS private key for a given seed.
Definition lm_ots.cpp:295
LMOTS_Public_Key(const LMOTS_Private_Key &lmots_sk)
Derivivation of an LMOTS public key using an LMOTS_Private_Key as defined in RFC 8554 4....
Definition lm_ots.cpp:390
Representation of a LM-OTS signature.
Definition lm_ots.h:182
static size_t size(const LMOTS_Params &params)
The expected size of the signature.
Definition lm_ots.h:211
StrongSpan< const LMOTS_Node > y(uint16_t chain_idx) const
Returns the part of the signature for chain_idx.
Definition lm_ots.cpp:264
LMOTS_Algorithm_Type algorithm_type() const
Returns the LM-OTS algorithm type.
Definition lm_ots.h:196
static LMOTS_Signature from_bytes_or_throw(BufferSlicer &slicer)
Parse a LM-OTS signature.
Definition lm_ots.cpp:271
std::span< const uint8_t > C() const
The n-byte randomizer of the signature.
Definition lm_ots.h:201
const LMS_Identifier & identifier() const
The LMS identifier of the LMS tree containing this OTS instance ('I' in RFC 8554).
Definition lm_ots.h:241
OTS_Instance(const LMOTS_Params &params, const LMS_Identifier &identifier, LMS_Tree_Node_Idx q)
Constructor storing the specific OTS parameters.
Definition lm_ots.h:230
LMS_Tree_Node_Idx q() const
The index of the LMS tree leaf associated with this OTS instance.
Definition lm_ots.h:246
const LMOTS_Params & params() const
The LMOTS parameters.
Definition lm_ots.h:236
Helper class used to derive secret values based in the pseudorandom key generation described in RFC 8...
decltype(auto) size() const noexcept(noexcept(this->m_span.size()))
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
LMOTS_K lmots_compute_pubkey_from_sig(const LMOTS_Signature &sig, const LMS_Message &msg, const LMS_Identifier &identifier, LMS_Tree_Node_Idx q)
Compute a public key candidate for an OTS-signature-message pair and the OTS instance parameters.
Definition lm_ots.cpp:481
Strong< std::vector< uint8_t >, struct LMOTS_K_ > LMOTS_K
The K value from the LM-OTS public key.
Definition lm_ots.h:39
BOTAN_FORCE_INLINE constexpr T ceil_division(T a, T b)
Definition bit_ops.h:167
constexpr RT checked_cast_to(AT i)
Definition int_utils.h:104
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
Strong< std::vector< uint8_t >, struct LMS_Message_ > LMS_Message
A message that is signed with an LMS tree.
Definition lm_ots.h:59
BOTAN_FORCE_INLINE constexpr size_t high_bit(T n)
Definition bit_ops.h:73
void lmots_compute_pubkeys(std::span< uint8_t > out_ks, const LMOTS_Params &params, const LMS_Identifier &identifier, LMS_Tree_Node_Idx first_q, size_t count, const LMS_Seed &seed, Hash_Engine &engine)
Compute the public key hash values K (RFC 8554 4.3) of count consecutive LM-OTS instances beginning a...
Definition lm_ots.cpp:424
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
std::uint8_t byte
Unsigned 8 bit integer; retained for compatibility with older versions.
Definition types.h:112
constexpr auto store_be(ParamTs &&... params)
Definition loadstor.h:745
constexpr auto load_be(ParamTs &&... params)
Definition loadstor.h:504