Botan 3.13.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 328 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 391 of file hss.h.

391{ 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 415 of file hss.cpp.

415 {
416 if(sig_bytes.size() < sizeof(uint32_t)) {
417 throw Decoding_Error("Too few HSS signature bytes.");
418 }
419 BufferSlicer slicer(sig_bytes);
420
421 const auto Nspk = load_be(slicer.take<sizeof(uint32_t)>());
422 if(Nspk >= HSS_MAX_LEVELS) {
423 throw Decoding_Error("Invalid number of HSS layers in signature.");
424 }
425
426 std::vector<Signed_Pub_Key> signed_pub_keys;
427 for(size_t i = 0; i < Nspk; ++i) {
428 LMS_Signature sig = LMS_Signature::from_bytes_or_throw(slicer);
429 LMS_PublicKey pub_key = LMS_PublicKey::from_bytes_or_throw(slicer);
430 signed_pub_keys.push_back(Signed_Pub_Key(std::move(sig), std::move(pub_key)));
431 }
432
433 auto sig = LMS_Signature::from_bytes_or_throw(slicer);
434
435 if(!slicer.empty()) {
436 throw Decoding_Error("HSS-LMS signature contains more bytes than expected.");
437 }
438 return HSS_Signature(std::move(signed_pub_keys), std::move(sig));
439}
A LMS public key signed by the HSS layer above it.
Definition hss.h:336
HSS_Level Nspk() const
Returns the number of signed public keys (Nspk = L-1).
Definition hss.h:378
static LMS_PublicKey from_bytes_or_throw(BufferSlicer &slicer)
Parse a public LMS key.
Definition lms.cpp:272
static LMS_Signature from_bytes_or_throw(BufferSlicer &slicer)
Parse the bytes of a lms signature into a LMS Signature object.
Definition lms.cpp:325
constexpr auto load_be(ParamTs &&... params)
Definition loadstor.h:504

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

378{ 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:35

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

386{ 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 441 of file hss.cpp.

441 {
442 size_t size = sizeof(uint32_t);
443 size += LMS_Signature::size(params.params_at_level(HSS_Level(0)).lms_params(),
444 params.params_at_level(HSS_Level(0)).lmots_params());
445 for(HSS_Level layer(1); layer < params.L(); ++layer) {
446 const auto& param = params.params_at_level(layer);
447 size += LMS_PublicKey::size(param.lms_params());
448 size += LMS_Signature::size(param.lms_params(), param.lmots_params());
449 }
450 return size;
451}
static size_t size(const HSS_LMS_Params &params)
Returns the size a signature would have in its encoded format.
Definition hss.cpp:441
static size_t size(const LMS_Params &lms_params)
The expected size of an LMS public key for given lms_params.
Definition lms.cpp:321
static size_t size(const LMS_Params &lms_params, const LMOTS_Params &lmots_params)
Definition lms.cpp:428

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: