Botan 2.19.5 Crypto and TLS for C&

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.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 **/
31 XMSS_Signature(XMSS_Parameters::xmss_algorithm_t oid,
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,
43 const secure_vector<uint8_t>& randomness,
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,
57 secure_vector<uint8_t>&& randomness,
58 XMSS_WOTS_PublicKey::TreeSignature&& tree_sig)
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
65 const secure_vector<uint8_t> randomness() const
66 {
67 return m_randomness;
68 }
69
70 secure_vector<uint8_t>& randomness()
71 {
72 return m_randomness;
73 }
74
75 void set_randomness(const secure_vector<uint8_t>& randomness)
76 {
77 m_randomness = randomness;
78 }
79
80 void set_randomness(secure_vector<uint8_t>&& randomness)
81 {
82 m_randomness = std::move(randomness);
83 }
84
85 const XMSS_WOTS_PublicKey::TreeSignature& tree() const
86 {
87 return m_tree_sig;
88 }
89
90 XMSS_WOTS_PublicKey::TreeSignature& tree()
91 {
92 return m_tree_sig;
93 }
94
95 void set_tree(const XMSS_WOTS_PublicKey::TreeSignature& tree_sig)
96 {
97 m_tree_sig = tree_sig;
98 }
99
100 void set_tree(XMSS_WOTS_PublicKey::TreeSignature&& tree_sig)
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 * 4-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 * 4+(len + h + 1)n bytes.
116 **/
117 secure_vector<uint8_t> bytes() const;
118
119 private:
120 size_t m_leaf_idx;
121 secure_vector<uint8_t> m_randomness;
122 XMSS_WOTS_PublicKey::TreeSignature m_tree_sig;
123 };
124
125}
126
127#endif
Botan::XMSS_Parameters::xmss_algorithm_t
xmss_algorithm_t
Definition: xmss_parameters.h:27
Botan::XMSS_Signature
Definition: xmss_signature.h:21
Botan::XMSS_Signature::set_unused_leaf_idx
void set_unused_leaf_idx(size_t idx)
Definition: xmss_signature.h:63
Botan::XMSS_Signature::tree
XMSS_WOTS_PublicKey::TreeSignature & tree()
Definition: xmss_signature.h:90
Botan::XMSS_Signature::randomness
secure_vector< uint8_t > & randomness()
Definition: xmss_signature.h:70
Botan::XMSS_Signature::set_tree
void set_tree(const XMSS_WOTS_PublicKey::TreeSignature &tree_sig)
Definition: xmss_signature.h:95
Botan::XMSS_Signature::unused_leaf_index
size_t unused_leaf_index() const
Definition: xmss_signature.h:62
Botan::XMSS_Signature::XMSS_Signature
XMSS_Signature(size_t leaf_idx, secure_vector< uint8_t > &&randomness, XMSS_WOTS_PublicKey::TreeSignature &&tree_sig)
Definition: xmss_signature.h:56
Botan::XMSS_Signature::set_randomness
void set_randomness(const secure_vector< uint8_t > &randomness)
Definition: xmss_signature.h:75
Botan::XMSS_Signature::set_tree
void set_tree(XMSS_WOTS_PublicKey::TreeSignature &&tree_sig)
Definition: xmss_signature.h:100
Botan::XMSS_Signature::bytes
secure_vector< uint8_t > bytes() const
Definition: xmss_signature.cpp:62
Botan::XMSS_Signature::tree
const XMSS_WOTS_PublicKey::TreeSignature & tree() const
Definition: xmss_signature.h:85
Botan::XMSS_Signature::randomness
const secure_vector< uint8_t > randomness() const
Definition: xmss_signature.h:65
Botan::XMSS_Signature::XMSS_Signature
XMSS_Signature(XMSS_Parameters::xmss_algorithm_t oid, const secure_vector< uint8_t > &raw_sig)
Definition: xmss_signature.cpp:13
Botan::XMSS_Signature::set_randomness
void set_randomness(secure_vector< uint8_t > &&randomness)
Definition: xmss_signature.h:80
Botan::XMSS_Signature::XMSS_Signature
XMSS_Signature(size_t leaf_idx, const secure_vector< uint8_t > &randomness, const XMSS_WOTS_PublicKey::TreeSignature &tree_sig)
Definition: xmss_signature.h:42
Botan::XMSS_WOTS_PublicKey::TreeSignature
Definition: xmss_wots.h:138
final
int(* final)(unsigned char *, CTX *)
Definition: commoncrypto_hash.cpp:29
Botan
Definition: alg_id.cpp:13
Botan::secure_vector
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:65
std
Definition: bigint.h:1155