Botan 3.4.0
Crypto and TLS for C&
Classes | Public Member Functions | List of all members
Botan::XMSS_Signature Class Referencefinal

#include <xmss_signature.h>

Classes

struct  TreeSignature
 

Public Member Functions

secure_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, const secure_vector< uint8_t > &raw_sig)
 

Detailed Description

Helper class for marshalling an XMSS signature

Definition at line 23 of file xmss_signature.h.

Constructor & Destructor Documentation

◆ XMSS_Signature() [1/2]

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

References Botan::XMSS_Signature::TreeSignature::authentication_path, Botan::XMSS_Parameters::element_size(), Botan::XMSS_Parameters::len(), Botan::XMSS_Signature::TreeSignature::ots_signature, Botan::XMSS_Parameters::total_number_of_signatures(), and Botan::XMSS_Parameters::tree_height().

◆ 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 50 of file xmss_signature.h.

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

Member Function Documentation

◆ bytes()

secure_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 51 of file xmss_signature.cpp.

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

References Botan::XMSS_Signature::TreeSignature::authentication_path, Botan::XMSS_Signature::TreeSignature::ots_signature, and tree().

◆ randomness() [1/2]

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

Definition at line 62 of file xmss_signature.h.

62{ return m_randomness; }

◆ randomness() [2/2]

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

Definition at line 55 of file xmss_signature.h.

55{ return m_randomness; }

Referenced by set_randomness().

◆ set_randomness()

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

Definition at line 64 of file xmss_signature.h.

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

References randomness().

◆ set_tree()

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

Definition at line 68 of file xmss_signature.h.

68{ 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 60 of file xmss_signature.h.

60{ m_leaf_idx = idx; }

◆ tree() [1/2]

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

Definition at line 66 of file xmss_signature.h.

66{ return m_tree_sig; }

◆ tree() [2/2]

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

Definition at line 57 of file xmss_signature.h.

57{ return m_tree_sig; }

Referenced by bytes().

◆ unused_leaf_index()

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

Definition at line 53 of file xmss_signature.h.

53{ return m_leaf_idx; }

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