Botan  2.7.0
Crypto and TLS for C++11
xmss_signature.h
Go to the documentation of this file.
1 /*
2  * XMSS Signature
3  * (C) 2016 Matthias Gierlings
4  *
5  * Botan is released under the Simplified BSD License (see license.txt)
6  **/
7 
8 #ifndef BOTAN_XMSS_SIGNATURE_H_
9 #define BOTAN_XMSS_SIGNATURE_H_
10 
11 #include <cstddef>
12 #include <botan/exceptn.h>
13 #include <botan/types.h>
14 #include <botan/secmem.h>
15 #include <botan/xmss_parameters.h>
16 #include <botan/xmss_wots_publickey.h>
17 
18 namespace Botan {
19 
20 class XMSS_Signature final
21  {
22  public:
23  /**
24  * Creates a signature from an XMSS signature method and a uint8_t sequence
25  * representing a raw signature.
26  *
27  * @param oid XMSS signature method
28  * @param raw_sig An XMSS signature serialized using
29  * XMSS_Signature::bytes().
30  **/
32  const secure_vector<uint8_t>& raw_sig);
33 
34  /**
35  * Creates an XMSS Signature from a leaf index used for signature
36  * generation, a random value and a tree signature.
37  *
38  * @param leaf_idx Leaf index used to generate the signature.
39  * @param randomness A random value.
40  * @param tree_sig A tree signature.
41  **/
42  XMSS_Signature(size_t leaf_idx,
44  const XMSS_WOTS_PublicKey::TreeSignature& tree_sig)
45  : m_leaf_idx(leaf_idx), m_randomness(randomness),
46  m_tree_sig(tree_sig) {}
47 
48  /**
49  * Creates an XMSS Signature from a leaf index used for signature
50  * generation, a random value and a tree signature.
51  *
52  * @param leaf_idx Leaf index used to generate the signature.
53  * @param randomness A random value.
54  * @param tree_sig A tree signature.
55  **/
56  XMSS_Signature(size_t leaf_idx,
59  : m_leaf_idx(leaf_idx), m_randomness(std::move(randomness)),
60  m_tree_sig(std::move(tree_sig)) {}
61 
62  size_t unused_leaf_index() const { return m_leaf_idx; }
63  void set_unused_leaf_idx(size_t idx) { m_leaf_idx = idx; }
64 
66  {
67  return m_randomness;
68  }
69 
71  {
72  return m_randomness;
73  }
74 
76  {
77  m_randomness = randomness;
78  }
79 
81  {
82  m_randomness = std::move(randomness);
83  }
84 
86  {
87  return m_tree_sig;
88  }
89 
91  {
92  return m_tree_sig;
93  }
94 
96  {
97  m_tree_sig = tree_sig;
98  }
99 
101  {
102  m_tree_sig = std::move(tree_sig);
103  }
104 
105  /**
106  * Generates a serialized representation of XMSS Signature by
107  * concatenating the following elements in order:
108  * 8-byte leaf index, n-bytes randomness, ots_signature,
109  * authentication path.
110  *
111  * n is the element_size(), len equal to len(), h the tree height
112  * defined by the chosen XMSS signature method.
113  *
114  * @return serialized signature, a sequence of
115  * (len + h + 1)n bytes.
116  **/
118 
119  private:
120  uint64_t m_leaf_idx;
121  secure_vector<uint8_t> m_randomness;
123  };
124 
125 }
126 
127 #endif
XMSS_Signature(XMSS_Parameters::xmss_algorithm_t oid, const secure_vector< uint8_t > &raw_sig)
secure_vector< uint8_t > bytes() const
const XMSS_WOTS_PublicKey::TreeSignature & tree() const
const secure_vector< uint8_t > randomness() const
Definition: bigint.h:796
void set_unused_leaf_idx(size_t idx)
secure_vector< uint8_t > & randomness()
void set_tree(XMSS_WOTS_PublicKey::TreeSignature &&tree_sig)
XMSS_Signature(size_t leaf_idx, const secure_vector< uint8_t > &randomness, const XMSS_WOTS_PublicKey::TreeSignature &tree_sig)
void set_randomness(const secure_vector< uint8_t > &randomness)
XMSS_WOTS_PublicKey::TreeSignature & tree()
void set_tree(const XMSS_WOTS_PublicKey::TreeSignature &tree_sig)
Definition: alg_id.cpp:13
void set_randomness(secure_vector< uint8_t > &&randomness)
size_t unused_leaf_index() const
XMSS_Signature(size_t leaf_idx, secure_vector< uint8_t > &&randomness, XMSS_WOTS_PublicKey::TreeSignature &&tree_sig)
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:88