Botan 3.7.1
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 321 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 384 of file hss.h.

384{ 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 380 of file hss.cpp.

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

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 371 of file hss.h.

371{ 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:34

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 379 of file hss.h.

379{ 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 406 of file hss.cpp.

406 {
407 size_t size = sizeof(uint32_t);
408 size += LMS_Signature::size(params.params_at_level(HSS_Level(0)).lms_params(),
409 params.params_at_level(HSS_Level(0)).lmots_params());
410 for(HSS_Level layer(1); layer < params.L(); ++layer) {
411 const auto& param = params.params_at_level(layer);
412 size += LMS_PublicKey::size(param.lms_params());
413 size += LMS_Signature::size(param.lms_params(), param.lmots_params());
414 }
415 return size;
416}
static size_t size(const HSS_LMS_Params &params)
Returns the size a signature would have in its encoded format.
Definition hss.cpp:406
static size_t size(const LMS_Params &lms_params)
The expected size of an LMS public key for given lms_params.
Definition lms.cpp:313
static size_t size(const LMS_Params &lms_params, const LMOTS_Params &lmots_params)
Definition lms.cpp:419

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: