Botan 3.0.0-alpha0
Crypto and TLS for C&
Public Member Functions | List of all members
Botan::XMSS_Signature Class Referencefinal

#include <xmss_signature.h>

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_WOTS_PublicKey::TreeSignature tree_sig)
 
void set_unused_leaf_idx (size_t idx)
 
XMSS_WOTS_PublicKey::TreeSignaturetree ()
 
const XMSS_WOTS_PublicKey::TreeSignaturetree () const
 
size_t unused_leaf_index () const
 
 XMSS_Signature (size_t leaf_idx, secure_vector< uint8_t > randomness, XMSS_WOTS_PublicKey::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.

15 : m_leaf_idx(0), m_randomness(0, 0x00), m_tree_sig()
16 {
17 XMSS_Parameters xmss_params(oid);
18
19 if(raw_sig.size() != (xmss_params.len() + xmss_params.tree_height() + 1)
20 * xmss_params.element_size() + sizeof(uint32_t))
21 {
22 throw Decoding_Error("XMSS signature size invalid.");
23 }
24
25 for(size_t i = 0; i < 4; i++)
26 { m_leaf_idx = ((m_leaf_idx << 8) | raw_sig[i]); }
27
28 if(m_leaf_idx >= (1ull << xmss_params.tree_height()))
29 {
30 throw Decoding_Error("XMSS signature leaf index out of bounds.");
31 }
32
33 auto begin = raw_sig.begin() + sizeof(uint32_t);
34 auto end = begin + xmss_params.element_size();
35 std::copy(begin, end, std::back_inserter(m_randomness));
36
37 for(size_t i = 0; i < xmss_params.len(); i++)
38 {
39 begin = end;
40 end = begin + xmss_params.element_size();
41 m_tree_sig.ots_signature().push_back(secure_vector<uint8_t>(0));
42 m_tree_sig.ots_signature().back().reserve(
43 xmss_params.element_size());
44 std::copy(begin,
45 end,
46 std::back_inserter(m_tree_sig.ots_signature().back()));
47 }
48
49 for(size_t i = 0; i < xmss_params.tree_height(); i++)
50 {
51 begin = end;
52 end = begin + xmss_params.element_size();
53 m_tree_sig.authentication_path().push_back(secure_vector<uint8_t>(0));
54 m_tree_sig.authentication_path().back().reserve(
55 xmss_params.element_size());
56 std::copy(begin,
57 end,
58 std::back_inserter(m_tree_sig.authentication_path().back()));
59 }
60 }
const wots_keysig_t & ots_signature() const
Definition: xmss_wots.h:148
const wots_keysig_t & authentication_path() const
Definition: xmss_wots.h:158

References Botan::XMSS_WOTS_PublicKey::TreeSignature::authentication_path(), Botan::XMSS_Parameters::element_size(), Botan::XMSS_Parameters::len(), Botan::XMSS_WOTS_PublicKey::TreeSignature::ots_signature(), 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_WOTS_PublicKey::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 45 of file xmss_signature.h.

48 : m_leaf_idx(leaf_idx), m_randomness(std::move(randomness)),
49 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 62 of file xmss_signature.cpp.

63 {
64 secure_vector<uint8_t> result
65 {
66 static_cast<uint8_t>(m_leaf_idx >> 24U),
67 static_cast<uint8_t>(m_leaf_idx >> 16U),
68 static_cast<uint8_t>(m_leaf_idx >> 8U),
69 static_cast<uint8_t>(m_leaf_idx)
70 };
71
72 std::copy(m_randomness.begin(),
73 m_randomness.end(),
74 std::back_inserter(result));
75
76 for(const auto& sig : tree().ots_signature())
77 {
78 std::copy(sig.begin(),
79 sig.end(),
80 std::back_inserter(result));
81 }
82
83 for(const auto& auth : tree().authentication_path())
84 {
85 std::copy(auth.begin(),
86 auth.end(),
87 std::back_inserter(result));
88 }
89 return result;
90 }
const XMSS_WOTS_PublicKey::TreeSignature & tree() const

References tree().

◆ randomness() [1/2]

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

Definition at line 59 of file xmss_signature.h.

60 {
61 return m_randomness;
62 }

◆ randomness() [2/2]

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

Definition at line 54 of file xmss_signature.h.

55 {
56 return m_randomness;
57 }

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.

65 {
66 m_randomness = std::move(randomness);
67 }

References randomness().

◆ set_tree()

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

Definition at line 79 of file xmss_signature.h.

80 {
81 m_tree_sig = std::move(tree_sig);
82 }

◆ set_unused_leaf_idx()

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

Definition at line 52 of file xmss_signature.h.

52{ m_leaf_idx = idx; }

◆ tree() [1/2]

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

Definition at line 74 of file xmss_signature.h.

75 {
76 return m_tree_sig;
77 }

◆ tree() [2/2]

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

Definition at line 69 of file xmss_signature.h.

70 {
71 return m_tree_sig;
72 }

Referenced by bytes().

◆ unused_leaf_index()

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

Definition at line 51 of file xmss_signature.h.

51{ return m_leaf_idx; }

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