/src/botan/build/include/botan/internal/xmss_signature.h
Line | Count | Source (jump to first uncovered line) |
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 | | /** |
21 | | * Helper class for marshalling an XMSS signature |
22 | | */ |
23 | | class XMSS_Signature final |
24 | | { |
25 | | public: |
26 | | /** |
27 | | * Creates a signature from an XMSS signature method and a uint8_t sequence |
28 | | * representing a raw signature. |
29 | | * |
30 | | * @param oid XMSS signature method |
31 | | * @param raw_sig An XMSS signature serialized using |
32 | | * XMSS_Signature::bytes(). |
33 | | **/ |
34 | | XMSS_Signature(XMSS_Parameters::xmss_algorithm_t oid, |
35 | | const secure_vector<uint8_t>& raw_sig); |
36 | | |
37 | | /** |
38 | | * Creates an XMSS Signature from a leaf index used for signature |
39 | | * generation, a random value and a tree signature. |
40 | | * |
41 | | * @param leaf_idx Leaf index used to generate the signature. |
42 | | * @param randomness A random value. |
43 | | * @param tree_sig A tree signature. |
44 | | **/ |
45 | | XMSS_Signature(size_t leaf_idx, |
46 | | secure_vector<uint8_t> randomness, |
47 | | XMSS_WOTS_PublicKey::TreeSignature tree_sig) |
48 | | : m_leaf_idx(leaf_idx), m_randomness(std::move(randomness)), |
49 | 0 | m_tree_sig(std::move(tree_sig)) {} |
50 | | |
51 | 0 | size_t unused_leaf_index() const { return m_leaf_idx; } |
52 | 0 | void set_unused_leaf_idx(size_t idx) { m_leaf_idx = idx; } |
53 | | |
54 | | const secure_vector<uint8_t> randomness() const |
55 | 0 | { |
56 | 0 | return m_randomness; |
57 | 0 | } |
58 | | |
59 | | secure_vector<uint8_t>& randomness() |
60 | 0 | { |
61 | 0 | return m_randomness; |
62 | 0 | } |
63 | | |
64 | | void set_randomness(secure_vector<uint8_t> randomness) |
65 | 0 | { |
66 | 0 | m_randomness = std::move(randomness); |
67 | 0 | } |
68 | | |
69 | | const XMSS_WOTS_PublicKey::TreeSignature& tree() const |
70 | 0 | { |
71 | 0 | return m_tree_sig; |
72 | 0 | } |
73 | | |
74 | | XMSS_WOTS_PublicKey::TreeSignature& tree() |
75 | 0 | { |
76 | 0 | return m_tree_sig; |
77 | 0 | } |
78 | | |
79 | | void set_tree(XMSS_WOTS_PublicKey::TreeSignature tree_sig) |
80 | 0 | { |
81 | 0 | m_tree_sig = std::move(tree_sig); |
82 | 0 | } |
83 | | |
84 | | /** |
85 | | * Generates a serialized representation of XMSS Signature by |
86 | | * concatenating the following elements in order: |
87 | | * 4-byte leaf index, n-bytes randomness, ots_signature, |
88 | | * authentication path. |
89 | | * |
90 | | * n is the element_size(), len equal to len(), h the tree height |
91 | | * defined by the chosen XMSS signature method. |
92 | | * |
93 | | * @return serialized signature, a sequence of |
94 | | * 4+(len + h + 1)n bytes. |
95 | | **/ |
96 | | secure_vector<uint8_t> bytes() const; |
97 | | |
98 | | private: |
99 | | size_t m_leaf_idx; |
100 | | secure_vector<uint8_t> m_randomness; |
101 | | XMSS_WOTS_PublicKey::TreeSignature m_tree_sig; |
102 | | }; |
103 | | |
104 | | } |
105 | | |
106 | | #endif |