Botan 3.12.0
Crypto and TLS for C&
Botan::XMSS_Signature Class Referencefinal

#include <xmss_signature.h>

Classes

struct  TreeSignature

Public Member Functions

std::vector< uint8_t > bytes () const
secure_vector< uint8_t > & randomness ()
const secure_vector< uint8_t > & randomness () const
void set_randomness (secure_vector< uint8_t > randomness)
void set_tree (XMSS_Signature::TreeSignature tree_sig)
void set_unused_leaf_idx (size_t idx)
XMSS_Signature::TreeSignaturetree ()
const XMSS_Signature::TreeSignaturetree () const
size_t unused_leaf_index () const
 XMSS_Signature (size_t leaf_idx, secure_vector< uint8_t > randomness, XMSS_Signature::TreeSignature tree_sig)
 XMSS_Signature (XMSS_Parameters::xmss_algorithm_t oid, std::span< const uint8_t > raw_sig)

Detailed Description

Helper class for marshalling an XMSS signature

Definition at line 22 of file xmss_signature.h.

Constructor & Destructor Documentation

◆ XMSS_Signature() [1/2]

Botan::XMSS_Signature::XMSS_Signature ( XMSS_Parameters::xmss_algorithm_t oid,
std::span< const uint8_t > raw_sig )

Creates a signature from an XMSS signature method and a uint8_t sequence representing a raw signature.

Parameters
oidXMSS signature method
raw_sigAn XMSS signature serialized using XMSS_Signature::bytes().

Definition at line 13 of file xmss_signature.cpp.

13 :
14 m_leaf_idx(0), m_randomness(0, 0x00) {
15 const auto params = XMSS_Parameters::from_id(oid);
16
17 if(raw_sig.size() != (params.len() + params.tree_height() + 1) * params.element_size() + sizeof(uint32_t)) {
18 throw Decoding_Error("XMSS signature size invalid.");
19 }
20
21 for(size_t i = 0; i < 4; i++) {
22 m_leaf_idx = ((m_leaf_idx << 8) | raw_sig[i]);
23 }
24
25 if(m_leaf_idx >= params.total_number_of_signatures()) {
26 throw Decoding_Error("XMSS signature leaf index out of bounds.");
27 }
28
29 auto begin = raw_sig.begin() + sizeof(uint32_t);
30 auto end = begin + params.element_size();
31 std::copy(begin, end, std::back_inserter(m_randomness));
32
33 for(size_t i = 0; i < params.len(); i++) {
34 begin = end;
35 end = begin + params.element_size();
36 m_tree_sig.ots_signature.push_back(secure_vector<uint8_t>(0));
37 m_tree_sig.ots_signature.back().reserve(params.element_size());
38 std::copy(begin, end, std::back_inserter(m_tree_sig.ots_signature.back()));
39 }
40
41 for(size_t i = 0; i < params.tree_height(); i++) {
42 begin = end;
43 end = begin + params.element_size();
44 m_tree_sig.authentication_path.push_back(secure_vector<uint8_t>(0));
45 m_tree_sig.authentication_path.back().reserve(params.element_size());
46 std::copy(begin, end, std::back_inserter(m_tree_sig.authentication_path.back()));
47 }
48}
static XMSS_Parameters from_id(xmss_algorithm_t id)
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:68

References Botan::XMSS_Parameters::from_id().

◆ XMSS_Signature() [2/2]

Botan::XMSS_Signature::XMSS_Signature ( size_t leaf_idx,
secure_vector< uint8_t > randomness,
XMSS_Signature::TreeSignature tree_sig )
inline

Creates an XMSS Signature from a leaf index used for signature generation, a random value and a tree signature.

Parameters
leaf_idxLeaf index used to generate the signature.
randomnessA random value.
tree_sigA tree signature.

Definition at line 49 of file xmss_signature.h.

49 :
50 m_leaf_idx(leaf_idx), m_randomness(std::move(randomness)), m_tree_sig(std::move(tree_sig)) {}
const secure_vector< uint8_t > & randomness() const

References randomness().

Member Function Documentation

◆ bytes()

std::vector< uint8_t > Botan::XMSS_Signature::bytes ( ) const

Generates a serialized representation of XMSS Signature by concatenating the following elements in order: 4-byte leaf index, n-bytes randomness, ots_signature, authentication path.

n is the element_size(), len equal to len(), h the tree height defined by the chosen XMSS signature method.

Returns
serialized signature, a sequence of 4+(len + h + 1)n bytes.

Definition at line 50 of file xmss_signature.cpp.

50 {
51 std::vector<uint8_t> result{static_cast<uint8_t>(m_leaf_idx >> 24U),
52 static_cast<uint8_t>(m_leaf_idx >> 16U),
53 static_cast<uint8_t>(m_leaf_idx >> 8U),
54 static_cast<uint8_t>(m_leaf_idx)};
55
56 std::copy(m_randomness.begin(), m_randomness.end(), std::back_inserter(result));
57
58 for(const auto& sig : tree().ots_signature) {
59 std::copy(sig.begin(), sig.end(), std::back_inserter(result));
60 }
61
62 for(const auto& auth : tree().authentication_path) {
63 std::copy(auth.begin(), auth.end(), std::back_inserter(result));
64 }
65 return result;
66}
const XMSS_Signature::TreeSignature & tree() const

References tree().

Referenced by Botan::XMSS_Signature_Operation::sign().

◆ randomness() [1/2]

secure_vector< uint8_t > & Botan::XMSS_Signature::randomness ( )
inline

Definition at line 61 of file xmss_signature.h.

61{ return m_randomness; }

◆ randomness() [2/2]

const secure_vector< uint8_t > & Botan::XMSS_Signature::randomness ( ) const
inline

Definition at line 54 of file xmss_signature.h.

54{ return m_randomness; }

Referenced by set_randomness(), and XMSS_Signature().

◆ set_randomness()

void Botan::XMSS_Signature::set_randomness ( secure_vector< uint8_t > randomness)
inline

Definition at line 63 of file xmss_signature.h.

63{ m_randomness = std::move(randomness); }

References randomness().

◆ set_tree()

void Botan::XMSS_Signature::set_tree ( XMSS_Signature::TreeSignature tree_sig)
inline

Definition at line 67 of file xmss_signature.h.

67{ m_tree_sig = std::move(tree_sig); }

◆ set_unused_leaf_idx()

void Botan::XMSS_Signature::set_unused_leaf_idx ( size_t idx)
inline

Definition at line 59 of file xmss_signature.h.

59{ m_leaf_idx = idx; }

◆ tree() [1/2]

XMSS_Signature::TreeSignature & Botan::XMSS_Signature::tree ( )
inline

Definition at line 65 of file xmss_signature.h.

65{ return m_tree_sig; }

◆ tree() [2/2]

const XMSS_Signature::TreeSignature & Botan::XMSS_Signature::tree ( ) const
inline

Definition at line 56 of file xmss_signature.h.

56{ return m_tree_sig; }

Referenced by bytes().

◆ unused_leaf_index()

size_t Botan::XMSS_Signature::unused_leaf_index ( ) const
inline

Definition at line 52 of file xmss_signature.h.

52{ return m_leaf_idx; }

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