Botan  2.4.0
Crypto and TLS for C++11
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
 
const secure_vector< uint8_t > randomness () const
 
secure_vector< uint8_t > & randomness ()
 
void set_randomness (const secure_vector< uint8_t > &randomness)
 
void set_randomness (secure_vector< uint8_t > &&randomness)
 
void set_tree (const XMSS_WOTS_PublicKey::TreeSignature &tree_sig)
 
void set_tree (XMSS_WOTS_PublicKey::TreeSignature &&tree_sig)
 
void set_unused_leaf_idx (size_t idx)
 
const XMSS_WOTS_PublicKey::TreeSignaturetree () const
 
XMSS_WOTS_PublicKey::TreeSignaturetree ()
 
size_t unused_leaf_index () const
 
 XMSS_Signature (XMSS_Parameters::xmss_algorithm_t oid, const secure_vector< uint8_t > &raw_sig)
 
 XMSS_Signature (size_t leaf_idx, const secure_vector< uint8_t > &randomness, const XMSS_WOTS_PublicKey::TreeSignature &tree_sig)
 
 XMSS_Signature (size_t leaf_idx, secure_vector< uint8_t > &&randomness, XMSS_WOTS_PublicKey::TreeSignature &&tree_sig)
 

Detailed Description

Definition at line 20 of file xmss_signature.h.

Constructor & Destructor Documentation

◆ XMSS_Signature() [1/3]

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.

References Botan::XMSS_WOTS_PublicKey::TreeSignature::authentication_path(), BOTAN_ASSERT, Botan::XMSS_Parameters::element_size(), Botan::XMSS_Parameters::len(), Botan::XMSS_WOTS_PublicKey::TreeSignature::ots_signature(), and Botan::XMSS_Parameters::tree_height().

15  : m_leaf_idx(0), m_randomness(0, 0x00), m_tree_sig()
16  {
17  BOTAN_ASSERT(sizeof(size_t) >= std::ceil(static_cast<float>(
18  (XMSS_Parameters(oid)).tree_height()) / 8.f),
19  "System type \"size_t\" not big enough to support"
20  " leaf index.");
21 
22  XMSS_Parameters xmss_params(oid);
23  uint64_t leaf_idx = 0;
24  for(size_t i = 0; i < 8; i++)
25  { leaf_idx = ((leaf_idx << 8) | raw_sig[i]); }
26 
27  if(leaf_idx >= (1ull << (xmss_params.tree_height() - 1)))
28  {
29  throw Integrity_Failure("XMSS signature leaf index out of "
30  "bounds.");
31  }
32  m_leaf_idx = static_cast<size_t>(leaf_idx);
33 
34  auto begin = raw_sig.begin() + sizeof(uint64_t);
35  auto end = begin + xmss_params.element_size();
36  std::copy(begin, end, std::back_inserter(m_randomness));
37 
38  for(size_t i = 0; i < xmss_params.len(); i++)
39  {
40  begin = end;
41  end = begin + xmss_params.element_size();
42  m_tree_sig.ots_signature().push_back(secure_vector<uint8_t>(0));
43  m_tree_sig.ots_signature().back().reserve(
44  xmss_params.element_size());
45  std::copy(begin,
46  end,
47  std::back_inserter(m_tree_sig.ots_signature().back()));
48  }
49 
50  for(size_t i = 0; i < xmss_params.tree_height(); i++)
51  {
52  begin = end;
53  end = begin + xmss_params.element_size();
54  m_tree_sig.authentication_path().push_back(secure_vector<uint8_t>(0));
55  m_tree_sig.authentication_path().back().reserve(
56  xmss_params.element_size());
57  std::copy(begin,
58  end,
59  std::back_inserter(m_tree_sig.authentication_path().back()));
60  }
61  }
const wots_keysig_t & authentication_path() const
#define BOTAN_ASSERT(expr, assertion_made)
Definition: assert.h:29
const wots_keysig_t & ots_signature() const

◆ XMSS_Signature() [2/3]

Botan::XMSS_Signature::XMSS_Signature ( size_t  leaf_idx,
const secure_vector< uint8_t > &  randomness,
const 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 42 of file xmss_signature.h.

45  : m_leaf_idx(leaf_idx), m_randomness(randomness),
46  m_tree_sig(tree_sig) {}
const secure_vector< uint8_t > randomness() const

◆ XMSS_Signature() [3/3]

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

59  : m_leaf_idx(leaf_idx), m_randomness(std::move(randomness)),
60  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: 8-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 (len + h + 1)n bytes.

Definition at line 63 of file xmss_signature.cpp.

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

Referenced by set_tree().

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

◆ randomness() [1/2]

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

Definition at line 65 of file xmss_signature.h.

Referenced by set_randomness(), and Botan::XMSS_Verification_Operation::XMSS_Verification_Operation().

66  {
67  return m_randomness;
68  }

◆ randomness() [2/2]

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

Definition at line 70 of file xmss_signature.h.

71  {
72  return m_randomness;
73  }

◆ set_randomness() [1/2]

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

Definition at line 75 of file xmss_signature.h.

References randomness().

76  {
77  m_randomness = randomness;
78  }
const secure_vector< uint8_t > randomness() const

◆ set_randomness() [2/2]

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

Definition at line 80 of file xmss_signature.h.

References randomness().

81  {
82  m_randomness = std::move(randomness);
83  }
const secure_vector< uint8_t > randomness() const

◆ set_tree() [1/2]

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

Definition at line 95 of file xmss_signature.h.

96  {
97  m_tree_sig = tree_sig;
98  }

◆ set_tree() [2/2]

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

Definition at line 100 of file xmss_signature.h.

References bytes().

101  {
102  m_tree_sig = std::move(tree_sig);
103  }

◆ set_unused_leaf_idx()

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

Definition at line 63 of file xmss_signature.h.

63 { m_leaf_idx = idx; }

◆ tree() [1/2]

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

Definition at line 85 of file xmss_signature.h.

Referenced by bytes(), and Botan::XMSS_Verification_Operation::XMSS_Verification_Operation().

86  {
87  return m_tree_sig;
88  }

◆ tree() [2/2]

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

Definition at line 90 of file xmss_signature.h.

91  {
92  return m_tree_sig;
93  }

◆ unused_leaf_index()

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

Definition at line 62 of file xmss_signature.h.

Referenced by Botan::XMSS_Verification_Operation::XMSS_Verification_Operation().

62 { return m_leaf_idx; }

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