Coverage Report

Created: 2021-02-21 07:20

/src/botan/src/lib/pubkey/xmss/xmss_common_ops.cpp
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * XMSS Common Ops
3
 * Operations shared by XMSS signature generation and verification operations.
4
 * (C) 2016,2017 Matthias Gierlings
5
 *
6
 * Botan is released under the Simplified BSD License (see license.txt)
7
 **/
8
9
#include <botan/internal/xmss_common_ops.h>
10
#include <botan/xmss_hash.h>
11
12
namespace Botan {
13
14
void
15
XMSS_Common_Ops::randomize_tree_hash(secure_vector<uint8_t>& result,
16
                                     const secure_vector<uint8_t>& left,
17
                                     const secure_vector<uint8_t>& right,
18
                                     XMSS_Address& adrs,
19
                                     const secure_vector<uint8_t>& seed,
20
                                     XMSS_Hash& hash,
21
                                     const XMSS_Parameters& params)
22
0
   {
23
0
   adrs.set_key_mask_mode(XMSS_Address::Key_Mask::Key_Mode);
24
0
   secure_vector<uint8_t> key { hash.prf(seed, adrs.bytes()) };
25
26
0
   adrs.set_key_mask_mode(XMSS_Address::Key_Mask::Mask_MSB_Mode);
27
0
   secure_vector<uint8_t> bitmask_l { hash.prf(seed, adrs.bytes()) };
28
29
0
   adrs.set_key_mask_mode(XMSS_Address::Key_Mask::Mask_LSB_Mode);
30
0
   secure_vector<uint8_t> bitmask_r { hash.prf(seed, adrs.bytes()) };
31
32
0
   BOTAN_ASSERT(bitmask_l.size() == left.size() &&
33
0
                bitmask_r.size() == right.size(),
34
0
                "Bitmask size doesn't match node size.");
35
36
0
   secure_vector<uint8_t> concat_xor(params.element_size() * 2);
37
0
   for(size_t i = 0; i < left.size(); i++)
38
0
      {
39
0
      concat_xor[i] = left[i] ^ bitmask_l[i];
40
0
      concat_xor[i + left.size()] = right[i] ^ bitmask_r[i];
41
0
      }
42
43
0
   hash.h(result, key, concat_xor);
44
0
   }
45
46
47
void
48
XMSS_Common_Ops::create_l_tree(secure_vector<uint8_t>& result,
49
                               wots_keysig_t pk,
50
                               XMSS_Address& adrs,
51
                               const secure_vector<uint8_t>& seed,
52
                               XMSS_Hash& hash,
53
                               const XMSS_Parameters& params)
54
0
   {
55
0
   size_t l = params.len();
56
0
   adrs.set_tree_height(0);
57
58
0
   while(l > 1)
59
0
      {
60
0
      for(size_t i = 0; i < l >> 1; i++)
61
0
         {
62
0
         adrs.set_tree_index(static_cast<uint32_t>(i));
63
0
         randomize_tree_hash(pk[i], pk[2 * i], pk[2 * i + 1], adrs, seed, hash, params);
64
0
         }
65
0
      if(l & 0x01)
66
0
         {
67
0
         pk[l >> 1] = pk[l - 1];
68
0
         }
69
0
      l = (l >> 1) + (l & 0x01);
70
0
      adrs.set_tree_height(adrs.get_tree_height() + 1);
71
0
      }
72
0
   result = pk[0];
73
0
   }
74
75
}