Botan 3.6.1
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 259 of file lm_ots.cpp.

262 :
263 OTS_Instance(params, identifier, q), m_seed(seed) {
264 PseudorandomKeyGeneration gen(identifier);
265 const auto hash = params.hash();
266
267 gen.set_q(q.get());
268 gen.set_j(0xff);
269
270 for(uint16_t i = 0; i < params.p(); ++i) {
271 gen.set_i(i);
272 m_ots_sk.push_back(gen.gen<LMOTS_Node>(*hash, seed));
273 }
274}
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
constexpr T & get() &
Definition strong_type.h:50
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 276 of file lm_ots.cpp.

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

References Botan::BufferStuffer::append(), BOTAN_ARG_CHECK, BOTAN_ASSERT_NOMSG, chain_input(), Botan::BufferStuffer::full(), Botan::LMOTS_Params::hash(), Botan::OTS_Instance::identifier(), 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: