Botan 3.5.0
Crypto and TLS for C&
Botan::LMOTS_Private_Key Class Reference

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_Nodechain_input (uint16_t chain_idx) const
 The secret chain input at a given chain index. (x[] in RFC 8554 4.2).
 
const LMS_Identifieridentifier () 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.
 
const LMOTS_Paramsparams () 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 257 of file lm_ots.h.

Constructor & Destructor Documentation

◆ LMOTS_Private_Key()

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 258 of file lm_ots.cpp.

261 :
262 OTS_Instance(params, identifier, q), m_seed(seed) {
263 PseudorandomKeyGeneration gen(identifier);
264 const auto hash = params.hash();
265
266 gen.set_q(q.get());
267 gen.set_j(0xff);
268
269 for(uint16_t i = 0; i < params.p(); ++i) {
270 gen.set_i(i);
271 m_ots_sk.push_back(gen.gen<LMOTS_Node>(*hash, seed));
272 }
273}
std::unique_ptr< HashFunction > hash() const
Construct a new hash instance for the OTS instance.
Definition lm_ots.h:155
uint16_t p() const
The number of n-byte string elements that make up the LM-OTS signature.
Definition lm_ots.h:140
const LMS_Identifier & identifier() const
The LMS identifier of the LMS tree containing this OTS instance ('I' in RFC 8554)
Definition lm_ots.h:238
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:227
LMS_Tree_Node_Idx q() const
The index of the LMS tree leaf associated with this OTS instance.
Definition lm_ots.h:243
const LMOTS_Params & params() const
The LMOTS parameters.
Definition lm_ots.h:233
Strong< secure_vector< uint8_t >, struct LMOTS_Node_ > LMOTS_Node
One node within one LM-OTS hash chain.
Definition lm_ots.h:30

References Botan::PseudorandomKeyGeneration::gen(), Botan::detail::Strong_Base< T >::get(), Botan::LMOTS_Params::hash(), Botan::OTS_Instance::identifier(), Botan::LMOTS_Params::p(), Botan::OTS_Instance::params(), Botan::OTS_Instance::q(), Botan::PseudorandomKeyGeneration::set_i(), Botan::PseudorandomKeyGeneration::set_j(), and Botan::PseudorandomKeyGeneration::set_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 272 of file lm_ots.h.

272{ return m_ots_sk.at(chain_idx); }

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 238 of file lm_ots.h.

238{ return m_identifier; }

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

◆ params()

const LMOTS_Params & Botan::OTS_Instance::params ( ) const
inlineinherited

The LMOTS parameters.

Definition at line 233 of file lm_ots.h.

233{ return m_params; }

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

◆ q()

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

The index of the LMS tree leaf associated with this OTS instance.

Definition at line 243 of file lm_ots.h.

243{ return m_q; }

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

◆ 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 275 of file lm_ots.cpp.

275 {
276 BOTAN_ARG_CHECK(out_sig.size() == LMOTS_Signature::size(params()), "Invalid output buffer size");
277 BufferStuffer sig_stuffer(out_sig);
278 const auto hash = params().hash();
279 sig_stuffer.append(store_be(params().algorithm_type()));
280 const auto C = sig_stuffer.next(params().n());
281
282 // Since we do not store the signatures of the lms trees in the HSS sk,
283 // we need deterministic signatures to avoid reusing a OTS key to generate multiple signatures.
284 // See also: https://github.com/cisco/hash-sigs/blob/b0631b8891295bf2929e68761205337b7c031726/lm_ots_sign.c#L110-L115
285 derive_random_C(C, *hash);
286
287 const auto Q_with_cksm = gen_Q_with_cksm(params(), identifier(), q(), C, msg);
288
289 Chain_Generator chain_gen(identifier(), q());
290 for(uint16_t i = 0; i < params().p(); ++i) {
291 const auto y_i = sig_stuffer.next(params().n());
292 const uint8_t a = coef(Q_with_cksm, i, params());
293 chain_gen.process(*hash, i, 0, a, chain_input(i), y_i);
294 }
295 BOTAN_ASSERT_NOMSG(sig_stuffer.full());
296}
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:59
#define BOTAN_ARG_CHECK(expr, msg)
Definition assert.h:29
size_t n() const
The number of bytes of the output of the hash function.
Definition lm_ots.h:125
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:272
static size_t size(const LMOTS_Params &params)
The expected size of the signature.
Definition lm_ots.h:207
constexpr auto store_be(ParamTs &&... params)
Definition loadstor.h:707

References Botan::BufferStuffer::append(), BOTAN_ARG_CHECK, BOTAN_ASSERT_NOMSG, chain_input(), 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(), and Botan::store_be().

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


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