Botan 3.14.1
Crypto and TLS for C&
Botan::XMSS_Signature_Operation Class Referencefinal

#include <xmss_signature_operation.h>

Inheritance diagram for Botan::XMSS_Signature_Operation:
Botan::PK_Ops::Signature

Public Member Functions

AlgorithmIdentifier algorithm_identifier () const override
std::string hash_function () const override
std::vector< uint8_t > sign (RandomNumberGenerator &rng) override
size_t signature_length () const override
void update (std::span< const uint8_t > input) override
 XMSS_Signature_Operation (const XMSS_PrivateKey &private_key)

Detailed Description

Signature generation operation for Extended Hash-Based Signatures (XMSS) as defined in:

[1] XMSS: Extended Hash-Based Signatures, Request for Comments: 8391 Release: May 2018. https://datatracker.ietf.org/doc/rfc8391/

Definition at line 29 of file xmss_signature_operation.h.

Constructor & Destructor Documentation

◆ XMSS_Signature_Operation()

Botan::XMSS_Signature_Operation::XMSS_Signature_Operation ( const XMSS_PrivateKey & private_key)
explicit

Definition at line 24 of file xmss_signature_operation.cpp.

24 :
25 m_priv_key(private_key), m_hash(private_key.xmss_parameters()) {}

Member Function Documentation

◆ algorithm_identifier()

AlgorithmIdentifier Botan::XMSS_Signature_Operation::algorithm_identifier ( ) const
overridevirtual

Return an algorithm identifier associated with this signature scheme.

Default implementation throws an exception

Reimplemented from Botan::PK_Ops::Signature.

Definition at line 83 of file xmss_signature_operation.cpp.

83 {
84 return AlgorithmIdentifier(OID::from_string("XMSS"), AlgorithmIdentifier::USE_EMPTY_PARAM);
85}
static OID from_string(std::string_view str)
Definition asn1_oid.cpp:80

References Botan::OID::from_string(), and Botan::AlgorithmIdentifier::USE_EMPTY_PARAM.

◆ hash_function()

std::string Botan::XMSS_Signature_Operation::hash_function ( ) const
inlineoverridevirtual

Return the hash function being used by this signer

Implements Botan::PK_Ops::Signature.

Definition at line 47 of file xmss_signature_operation.h.

47{ return m_hash.hash_function(); }

◆ sign()

std::vector< uint8_t > Botan::XMSS_Signature_Operation::sign ( RandomNumberGenerator & rng)
overridevirtual

Creates an XMSS signature for the message provided through call to update().

Returns
serialized XMSS signature.

Implements Botan::PK_Ops::Signature.

Definition at line 39 of file xmss_signature_operation.cpp.

39 {
40 const std::vector<uint8_t> msg = std::exchange(m_msg_buffer, {});
41
42 const auto& params = m_priv_key.xmss_parameters();
43
44 // reserve leaf index so it can not be reused by another signature
45 // operation using the same private key.
46 const auto leaf_idx = static_cast<uint32_t>(m_priv_key.reserve_unused_leaf_index());
47
48 secure_vector<uint8_t> index_bytes;
49 secure_vector<uint8_t> randomness;
50
51 // write prefix for message hashing into buffer.
52 xmss_concat(index_bytes, leaf_idx, 32);
53 m_hash.prf(randomness, m_priv_key.prf_value(), index_bytes);
54 index_bytes.clear();
55 xmss_concat(index_bytes, leaf_idx, params.element_size());
56 m_hash.h_msg_init(randomness, m_priv_key.root(), index_bytes);
57 m_hash.h_msg_update(msg);
58
59 const auto msg_hash = m_hash.h_msg_final();
60
61 wots_keysig_t auth_path(params.tree_height());
62
63 XMSS_Address adrs;
65
66 for(size_t j = 0; j < params.tree_height(); j++) {
67 const size_t k = (leaf_idx / (static_cast<size_t>(1) << j)) ^ 0x01;
68 auth_path[j] = m_priv_key.tree_hash(k * (static_cast<size_t>(1) << j), j, adrs, m_hash);
69 }
70
72 adrs.set_ots_address(leaf_idx);
73
75 tree_sig.authentication_path = auth_path;
76 tree_sig.ots_signature =
77 m_priv_key.wots_private_key_for(adrs, m_hash).sign(msg_hash, m_priv_key.public_seed(), adrs, m_hash);
78
79 const XMSS_Signature sig(leaf_idx, randomness, tree_sig);
80 return sig.bytes();
81}
XMSS_TreeSignature TreeSignature
std::vector< secure_vector< uint8_t > > wots_keysig_t
void xmss_concat(secure_vector< uint8_t > &target, const T &src)
Definition xmss_tools.h:28
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:128
wots_keysig_t authentication_path

References Botan::XMSS_TreeSignature::authentication_path, Botan::XMSS_Signature::bytes(), Botan::XMSS_Address::Hash_Tree_Address, Botan::XMSS_Address::OTS_Hash_Address, Botan::XMSS_TreeSignature::ots_signature, Botan::XMSS_Address::set_ots_address(), Botan::XMSS_Address::set_type(), and Botan::xmss_concat().

◆ signature_length()

size_t Botan::XMSS_Signature_Operation::signature_length ( ) const
overridevirtual

Return an upper bound on the length of the output signature

Implements Botan::PK_Ops::Signature.

Definition at line 27 of file xmss_signature_operation.cpp.

27 {
28 const auto& params = m_priv_key.xmss_parameters();
29 return sizeof(uint32_t) + // size of leaf index
30 params.element_size() + params.len() * params.element_size() + params.tree_height() * params.element_size();
31}

◆ update()

void Botan::XMSS_Signature_Operation::update ( std::span< const uint8_t > input)
overridevirtual

Add more data to the message currently being signed

Parameters
inputthe input to be hashed/signed

Implements Botan::PK_Ops::Signature.

Definition at line 33 of file xmss_signature_operation.cpp.

33 {
34 // The leaf index is part of the message hash prefix, so the message is
35 // buffered to avoid reserving a leaf before sign() is called
36 m_msg_buffer.insert(m_msg_buffer.end(), input.begin(), input.end());
37}

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