Coverage Report

Created: 2020-03-26 13:53

/src/botan/build/include/botan/xmss_common_ops.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * XMSS Common Ops
3
 * (C) 2016,2017 Matthias Gierlings
4
 *
5
 * Botan is released under the Simplified BSD License (see license.txt)
6
 **/
7
8
#ifndef BOTAN_XMSS_COMMON_OPS_H_
9
#define BOTAN_XMSS_COMMON_OPS_H_
10
11
#include <vector>
12
#include <botan/secmem.h>
13
#include <botan/xmss_parameters.h>
14
#include <botan/xmss_address.h>
15
#include <botan/xmss_hash.h>
16
17
//BOTAN_FUTURE_INTERNAL_HEADER(xmss_common_ops.h)
18
19
namespace Botan {
20
21
typedef std::vector<secure_vector<uint8_t>> wots_keysig_t;
22
23
/**
24
 * Operations shared by XMSS signature generation and verification operations.
25
 **/
26
class XMSS_Common_Ops
27
   {
28
   public:
29
      XMSS_Common_Ops(XMSS_Parameters::xmss_algorithm_t oid)
30
0
         : m_xmss_params(oid), m_hash(m_xmss_params.hash_function_name()) {}
31
32
   protected:
33
      /**
34
        * Algorithm 7: "RAND_HASH"
35
        *
36
        * Generates a randomized hash.
37
        *
38
        * This overload is used in multithreaded scenarios, where it is
39
        * required to provide seperate instances of XMSS_Hash to each
40
        * thread.
41
        *
42
        * @param[out] result The resulting randomized hash.
43
        * @param[in] left Left half of the hash function input.
44
        * @param[in] right Right half of the hash function input.
45
        * @param[in] adrs Adress of the hash function call.
46
        * @param[in] seed The seed for G.
47
        * @param[in] hash Instance of XMSS_Hash, that may only by the thead
48
        *            executing generate_public_key.
49
        **/
50
      void randomize_tree_hash(
51
         secure_vector<uint8_t>& result,
52
         const secure_vector<uint8_t>& left,
53
         const secure_vector<uint8_t>& right,
54
         XMSS_Address& adrs,
55
         const secure_vector<uint8_t>& seed,
56
         XMSS_Hash& hash);
57
58
      /**
59
        * Algorithm 7: "RAND_HASH"
60
        *
61
        * Generates a randomized hash.
62
        *
63
        * @param[out] result The resulting randomized hash.
64
        * @param[in] left Left half of the hash function input.
65
        * @param[in] right Right half of the hash function input.
66
        * @param[in] adrs Adress of the hash function call.
67
        * @param[in] seed The seed for G.
68
        **/
69
      inline void randomize_tree_hash(
70
         secure_vector<uint8_t>& result,
71
         const secure_vector<uint8_t>& left,
72
         const secure_vector<uint8_t>& right,
73
         XMSS_Address& adrs,
74
         const secure_vector<uint8_t>& seed)
75
0
         {
76
0
         randomize_tree_hash(result, left, right, adrs, seed, m_hash);
77
0
         }
78
79
      /**
80
       * Algorithm 8: "ltree"
81
       * Create an L-tree used to compute the leaves of the binary hash tree.
82
       * Takes a WOTS+ public key and compresses it to a single n-byte value.
83
       *
84
       * This overload is used in multithreaded scenarios, where it is
85
       * required to provide seperate instances of XMSS_Hash to each thread.
86
       *
87
       * @param[out] result Public key compressed to a single n-byte value
88
       *             pk[0].
89
       * @param[in] pk Winternitz One Time Signatures+ public key.
90
       * @param[in] adrs Address encoding the address of the L-Tree
91
       * @param[in] seed The seed generated during the public key generation.
92
       * @param[in] hash Instance of XMSS_Hash, that may only be used by the
93
       *            thead executing create_l_tree.
94
      **/
95
      void create_l_tree(secure_vector<uint8_t>& result,
96
                         wots_keysig_t pk,
97
                         XMSS_Address& adrs,
98
                         const secure_vector<uint8_t>& seed,
99
                         XMSS_Hash& hash);
100
101
      /**
102
       * Algorithm 8: "ltree"
103
       * Create an L-tree used to compute the leaves of the binary hash tree.
104
       * Takes a WOTS+ public key and compresses it to a single n-byte value.
105
       *
106
       * @param[out] result Public key compressed to a single n-byte value
107
       *             pk[0].
108
       * @param[in] pk Winternitz One Time Signatures+ public key.
109
       * @param[in] adrs Address encoding the address of the L-Tree
110
       * @param[in] seed The seed generated during the public key generation.
111
       **/
112
      inline void create_l_tree(secure_vector<uint8_t>& result,
113
                                wots_keysig_t pk,
114
                                XMSS_Address& adrs,
115
                                const secure_vector<uint8_t>& seed)
116
0
         {
117
0
         create_l_tree(result, pk, adrs, seed, m_hash);
118
0
         }
119
120
   protected:
121
      XMSS_Parameters m_xmss_params;
122
      XMSS_Hash m_hash;
123
124
   };
125
126
}
127
128
#endif