Botan 3.14.1
Crypto and TLS for C&
Botan::LMOTS_Private_Key Class Referencefinal

Representation of an LMOTS private key. More...

#include <lm_ots.h>

Inheritance diagram for Botan::LMOTS_Private_Key:
Botan::OTS_Instance

Public Member Functions

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).
const LMS_Identifier & identifier () const
 The LMS identifier of the LMS tree containing this OTS instance ('I' in RFC 8554).
 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.
 LMOTS_Private_Key (const LMOTS_Params &params, const LMS_Identifier &identifier, LMS_Tree_Node_Idx q, const LMS_Seed &seed, Hash_Engine &engine)
 As above, but using a caller-provided hash engine, allowing its reuse over many key derivations.
const LMOTS_Params & params () const
 The LMOTS parameters.
LMS_Tree_Node_Idx q () const
 The index of the LMS tree leaf associated with this OTS instance.
void sign (StrongSpan< LMOTS_Signature_Bytes > out_sig, const LMS_Message &msg) const
 Generate a new LMOTS signature.

Detailed Description

Representation of an LMOTS private key.

Contains the OTS params, I, q, the secret LMS seed and its derived secret chain inputs (x[] in RFC 8554 4.2)

Definition at line 260 of file lm_ots.h.

Constructor & Destructor Documentation

◆ LMOTS_Private_Key() [1/2]

Botan::LMOTS_Private_Key::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.

Implements RFC 8554 4.2 using derivation of Appendix A

Definition at line 295 of file lm_ots.cpp.

298 :
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="")
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
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
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

References Botan::OTS_Instance::identifier(), LMOTS_Private_Key(), Botan::OTS_Instance::params(), and Botan::OTS_Instance::q().

Referenced by LMOTS_Private_Key().

◆ LMOTS_Private_Key() [2/2]

Botan::LMOTS_Private_Key::LMOTS_Private_Key ( const LMOTS_Params & params,
const LMS_Identifier & identifier,
LMS_Tree_Node_Idx q,
const LMS_Seed & seed,
Hash_Engine & engine )

As above, but using a caller-provided hash engine, allowing its reuse over many key derivations.

Definition at line 301 of file lm_ots.cpp.

305 :
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}
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

References Botan::detail::Strong_Base< T >::get(), Botan::OTS_Instance::identifier(), Botan::OTS_Instance::OTS_Instance(), Botan::OTS_Instance::params(), and Botan::OTS_Instance::q().

Member Function Documentation

◆ chain_input()

const LMOTS_Node & Botan::LMOTS_Private_Key::chain_input ( uint16_t chain_idx) const
inline

The secret chain input at a given chain index. (x[] in RFC 8554 4.2).

Definition at line 285 of file lm_ots.h.

285{ return m_ots_sk.at(chain_idx); }

References Botan::detail::Strong_Adapter< T >::at().

Referenced by Botan::LMOTS_Public_Key::LMOTS_Public_Key(), and sign().

◆ identifier()

const LMS_Identifier & Botan::OTS_Instance::identifier ( ) const
inlineinherited

The LMS identifier of the LMS tree containing this OTS instance ('I' in RFC 8554).

Definition at line 241 of file lm_ots.h.

241{ return m_identifier; }

Referenced by Botan::LMOTS_Private_Key::LMOTS_Private_Key(), Botan::LMOTS_Private_Key::LMOTS_Private_Key(), Botan::LMOTS_Public_Key::LMOTS_Public_Key(), Botan::LMOTS_Public_Key::LMOTS_Public_Key(), OTS_Instance(), and Botan::LMOTS_Private_Key::sign().

◆ params()

◆ q()

LMS_Tree_Node_Idx Botan::OTS_Instance::q ( ) const
inlineinherited

◆ sign()

void Botan::LMOTS_Private_Key::sign ( StrongSpan< LMOTS_Signature_Bytes > out_sig,
const LMS_Message & msg ) const

Generate a new LMOTS signature.

Defined in RFC 8554 4.5

Definition at line 324 of file lm_ots.cpp.

324 {
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}
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:82
#define BOTAN_ARG_CHECK(expr, msg)
Definition assert.h:33
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
uint16_t p() const
The number of n-byte string elements that make up the LM-OTS signature.
Definition lm_ots.h:144
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
static size_t size(const LMOTS_Params &params)
The expected size of the signature.
Definition lm_ots.h:211
constexpr void unpoison(const T *p, size_t n)
Definition ct_utils.h:67
constexpr void copy_mem(T *out, const T *in, size_t n)
Definition mem_ops.h:144
constexpr auto store_be(ParamTs &&... params)
Definition loadstor.h:745

References Botan::BufferStuffer::append(), BOTAN_ARG_CHECK, BOTAN_ASSERT_NOMSG, chain_input(), Botan::copy_mem(), Botan::Hash_Engine::create_or_throw(), Botan::BufferStuffer::full(), Botan::LMOTS_Params::hash(), Botan::OTS_Instance::identifier(), Botan::LMOTS_Params::n(), Botan::BufferStuffer::next(), Botan::LMOTS_Params::p(), Botan::OTS_Instance::params(), Botan::OTS_Instance::q(), Botan::LMOTS_Signature::size(), Botan::StrongSpan< T >::size(), Botan::store_be(), and Botan::CT::unpoison().

Referenced by Botan::LMS_PrivateKey::sign_and_get_pk().


The documentation for this class was generated from the following files: