Botan 3.5.0
Crypto and TLS for C&
Botan::HSS_Signature Class Referencefinal

A HSS-LMS signature. More...

#include <hss.h>

Classes

class  Signed_Pub_Key
 A LMS public key signed by the HSS layer above it. More...
 

Public Member Functions

const LMS_Signaturebottom_sig () const
 Returns the LMS signature by the bottom layer of the signed message.
 
HSS_Level Nspk () const
 Returns the number of signed public keys (Nspk = L-1).
 
const Signed_Pub_Keysigned_pub_key (HSS_Level layer) const
 Returns the signed LMS key signed by a specific layer.
 

Static Public Member Functions

static HSS_Signature from_bytes_or_throw (std::span< const uint8_t > sig_bytes)
 Parse a HSS-LMS signature.
 
static size_t size (const HSS_LMS_Params &params)
 Returns the size a signature would have in its encoded format.
 

Detailed Description

A HSS-LMS signature.

Format according to RFC 8554: u32str(Nspk) || sig[0] || pub[1] || ... || sig[Nspk-1] || pub[Nspk] || sig[Nspk]

Definition at line 314 of file hss.h.

Member Function Documentation

◆ bottom_sig()

const LMS_Signature & Botan::HSS_Signature::bottom_sig ( ) const
inline

Returns the LMS signature by the bottom layer of the signed message.

Definition at line 377 of file hss.h.

377{ return m_sig; }

Referenced by Botan::HSS_LMS_PublicKeyInternal::verify_signature().

◆ from_bytes_or_throw()

HSS_Signature Botan::HSS_Signature::from_bytes_or_throw ( std::span< const uint8_t > sig_bytes)
static

Parse a HSS-LMS signature.

Parameters
sig_bytesThe signature bytes to parse.
Returns
The parsed HSS-LMS signature.
Exceptions
Decoding_ErrorIf parsing the signature fails.

Definition at line 372 of file hss.cpp.

372 {
373 if(sig_bytes.size() < sizeof(uint32_t)) {
374 throw Decoding_Error("Too few HSS signature bytes.");
375 }
376 BufferSlicer slicer(sig_bytes);
377
378 const auto Nspk = load_be(slicer.take<sizeof(uint32_t)>());
379 if(Nspk >= HSS_MAX_LEVELS) {
380 throw Decoding_Error("Invalid number of HSS layers in signature.");
381 }
382
383 std::vector<Signed_Pub_Key> signed_pub_keys;
384 for(size_t i = 0; i < Nspk; ++i) {
385 LMS_Signature sig = LMS_Signature::from_bytes_or_throw(slicer);
386 LMS_PublicKey pub_key = LMS_PublicKey::from_bytes_or_throw(slicer);
387 signed_pub_keys.push_back(Signed_Pub_Key(std::move(sig), std::move(pub_key)));
388 }
389
390 auto sig = LMS_Signature::from_bytes_or_throw(slicer);
391
392 if(!slicer.empty()) {
393 throw Decoding_Error("HSS-LMS signature contains more bytes than expected.");
394 }
395 return HSS_Signature(std::move(signed_pub_keys), std::move(sig));
396}
HSS_Level Nspk() const
Returns the number of signed public keys (Nspk = L-1).
Definition hss.h:364
static LMS_PublicKey from_bytes_or_throw(BufferSlicer &slicer)
Parse a public LMS key.
Definition lms.cpp:263
static LMS_Signature from_bytes_or_throw(BufferSlicer &slicer)
Parse the bytes of a lms signature into a LMS Signature object.
Definition lms.cpp:316
constexpr auto load_be(ParamTs &&... params)
Definition loadstor.h:467

References Botan::BufferSlicer::empty(), Botan::LMS_PublicKey::from_bytes_or_throw(), Botan::LMS_Signature::from_bytes_or_throw(), Botan::load_be(), Nspk(), and Botan::BufferSlicer::take().

◆ Nspk()

HSS_Level Botan::HSS_Signature::Nspk ( ) const
inline

Returns the number of signed public keys (Nspk = L-1).

Definition at line 364 of file hss.h.

364{ return HSS_Level(static_cast<uint32_t>(m_signed_pub_keys.size())); }
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:33

Referenced by from_bytes_or_throw(), and Botan::HSS_LMS_PublicKeyInternal::verify_signature().

◆ signed_pub_key()

const Signed_Pub_Key & Botan::HSS_Signature::signed_pub_key ( HSS_Level layer) const
inline

Returns the signed LMS key signed by a specific layer.

Parameters
layerThe layer by which the LMS key is signed.
Returns
The LMS key and the signature by its parent layer.

Definition at line 372 of file hss.h.

372{ return m_signed_pub_keys.at(layer.get()); }

References Botan::detail::Strong_Base< T >::get().

Referenced by Botan::HSS_LMS_PublicKeyInternal::verify_signature().

◆ size()

size_t Botan::HSS_Signature::size ( const HSS_LMS_Params & params)
static

Returns the size a signature would have in its encoded format.

Parameters
paramsThe HSS-LMS parameters.
Returns
size_t The expected size in bytes.

Definition at line 398 of file hss.cpp.

398 {
399 size_t size = sizeof(uint32_t);
400 size += LMS_Signature::size(params.params_at_level(HSS_Level(0)).lms_params(),
401 params.params_at_level(HSS_Level(0)).lmots_params());
402 for(HSS_Level layer(1); layer < params.L(); ++layer) {
403 const auto& param = params.params_at_level(layer);
404 size += LMS_PublicKey::size(param.lms_params());
405 size += LMS_Signature::size(param.lms_params(), param.lmots_params());
406 }
407 return size;
408}
static size_t size(const HSS_LMS_Params &params)
Returns the size a signature would have in its encoded format.
Definition hss.cpp:398
static size_t size(const LMS_Params &lms_params)
The expected size of an LMS public key for given lms_params.
Definition lms.cpp:312
static size_t size(const LMS_Params &lms_params, const LMOTS_Params &lmots_params)
Definition lms.cpp:418

References Botan::HSS_LMS_Params::L(), Botan::HSS_LMS_Params::params_at_level(), size(), Botan::LMS_PublicKey::size(), and Botan::LMS_Signature::size().

Referenced by Botan::HSS_LMS_PrivateKeyInternal::sign(), and size().


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