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

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

392 {
393 if(sig_bytes.size() < sizeof(uint32_t)) {
394 throw Decoding_Error("Too few HSS signature bytes.");
395 }
396 BufferSlicer slicer(sig_bytes);
397
398 const auto Nspk = load_be(slicer.take<sizeof(uint32_t)>());
399 if(Nspk >= HSS_MAX_LEVELS) {
400 throw Decoding_Error("Invalid number of HSS layers in signature.");
401 }
402
403 std::vector<Signed_Pub_Key> signed_pub_keys;
404 for(size_t i = 0; i < Nspk; ++i) {
405 LMS_Signature sig = LMS_Signature::from_bytes_or_throw(slicer);
406 LMS_PublicKey pub_key = LMS_PublicKey::from_bytes_or_throw(slicer);
407 signed_pub_keys.push_back(Signed_Pub_Key(std::move(sig), std::move(pub_key)));
408 }
409
410 auto sig = LMS_Signature::from_bytes_or_throw(slicer);
411
412 if(!slicer.empty()) {
413 throw Decoding_Error("HSS-LMS signature contains more bytes than expected.");
414 }
415 return HSS_Signature(std::move(signed_pub_keys), std::move(sig));
416}
A LMS public key signed by the HSS layer above it.
Definition hss.h:331
HSS_Level Nspk() const
Returns the number of signed public keys (Nspk = L-1).
Definition hss.h:373
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 373 of file hss.h.

373{ 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 381 of file hss.h.

381{ 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 418 of file hss.cpp.

418 {
419 size_t size = sizeof(uint32_t);
420 size += LMS_Signature::size(params.params_at_level(HSS_Level(0)).lms_params(),
421 params.params_at_level(HSS_Level(0)).lmots_params());
422 for(HSS_Level layer(1); layer < params.L(); ++layer) {
423 const auto& param = params.params_at_level(layer);
424 size += LMS_PublicKey::size(param.lms_params());
425 size += LMS_Signature::size(param.lms_params(), param.lmots_params());
426 }
427 return size;
428}
static size_t size(const HSS_LMS_Params &params)
Returns the size a signature would have in its encoded format.
Definition hss.cpp:418
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: