Coverage Report

Created: 2021-04-07 06:07

/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
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
0
           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
0
           m_tree_sig(std::move(tree_sig)) {}
61
62
0
      size_t unused_leaf_index() const { return m_leaf_idx; }
63
0
      void set_unused_leaf_idx(size_t idx) { m_leaf_idx = idx; }
64
65
      const secure_vector<uint8_t> randomness() const
66
0
         {
67
0
         return m_randomness;
68
0
         }
69
70
      secure_vector<uint8_t>& randomness()
71
0
         {
72
0
         return m_randomness;
73
0
         }
74
75
      void set_randomness(const secure_vector<uint8_t>& randomness)
76
0
         {
77
0
         m_randomness = randomness;
78
0
         }
79
80
      void set_randomness(secure_vector<uint8_t>&& randomness)
81
0
         {
82
0
         m_randomness = std::move(randomness);
83
0
         }
84
85
      const XMSS_WOTS_PublicKey::TreeSignature& tree() const
86
0
         {
87
0
         return m_tree_sig;
88
0
         }
89
90
      XMSS_WOTS_PublicKey::TreeSignature& tree()
91
0
         {
92
0
         return m_tree_sig;
93
0
         }
94
95
      void set_tree(const XMSS_WOTS_PublicKey::TreeSignature& tree_sig)
96
0
         {
97
0
         m_tree_sig = tree_sig;
98
0
         }
99
100
      void set_tree(XMSS_WOTS_PublicKey::TreeSignature&& tree_sig)
101
0
         {
102
0
         m_tree_sig = std::move(tree_sig);
103
0
         }
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