Botan  2.18.1
Crypto and TLS for C++11
xmss_common_ops.cpp
Go to the documentation of this file.
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 
11 namespace Botan {
12 
13 void
15  const secure_vector<uint8_t>& left,
16  const secure_vector<uint8_t>& right,
17  XMSS_Address& adrs,
18  const secure_vector<uint8_t>& seed,
19  XMSS_Hash& hash,
20  const XMSS_Parameters& params)
21  {
23  secure_vector<uint8_t> key { hash.prf(seed, adrs.bytes()) };
24 
26  secure_vector<uint8_t> bitmask_l { hash.prf(seed, adrs.bytes()) };
27 
29  secure_vector<uint8_t> bitmask_r { hash.prf(seed, adrs.bytes()) };
30 
31  BOTAN_ASSERT(bitmask_l.size() == left.size() &&
32  bitmask_r.size() == right.size(),
33  "Bitmask size doesn't match node size.");
34 
35  secure_vector<uint8_t> concat_xor(params.element_size() * 2);
36  for(size_t i = 0; i < left.size(); i++)
37  {
38  concat_xor[i] = left[i] ^ bitmask_l[i];
39  concat_xor[i + left.size()] = right[i] ^ bitmask_r[i];
40  }
41 
42  hash.h(result, key, concat_xor);
43  }
44 
45 
46 void
48  wots_keysig_t pk,
49  XMSS_Address& adrs,
50  const secure_vector<uint8_t>& seed,
51  XMSS_Hash& hash,
52  const XMSS_Parameters& params)
53  {
54  size_t l = params.len();
55  adrs.set_tree_height(0);
56 
57  while(l > 1)
58  {
59  for(size_t i = 0; i < l >> 1; i++)
60  {
61  adrs.set_tree_index(static_cast<uint32_t>(i));
62  randomize_tree_hash(pk[i], pk[2 * i], pk[2 * i + 1], adrs, seed, hash, params);
63  }
64  if(l & 0x01)
65  {
66  pk[l >> 1] = pk[l - 1];
67  }
68  l = (l >> 1) + (l & 0x01);
69  adrs.set_tree_height(adrs.get_tree_height() + 1);
70  }
71  result = pk[0];
72  }
73 
74 }
void set_tree_height(uint32_t value)
Definition: xmss_address.h:251
static void create_l_tree(secure_vector< uint8_t > &result, wots_keysig_t pk, XMSS_Address &adrs, const secure_vector< uint8_t > &seed, XMSS_Hash &hash, const XMSS_Parameters &params)
const secure_vector< uint8_t > & bytes() const
Definition: xmss_address.h:322
#define BOTAN_ASSERT(expr, assertion_made)
Definition: assert.h:55
uint32_t get_tree_height() const
Definition: xmss_address.h:235
Definition: alg_id.cpp:13
std::vector< secure_vector< uint8_t > > wots_keysig_t
static void randomize_tree_hash(secure_vector< uint8_t > &result, const secure_vector< uint8_t > &left, const secure_vector< uint8_t > &right, XMSS_Address &adrs, const secure_vector< uint8_t > &seed, XMSS_Hash &hash, const XMSS_Parameters &params)
void set_key_mask_mode(Key_Mask value)
Definition: xmss_address.h:134
size_t element_size() const
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:65
void set_tree_index(uint32_t value)
Definition: xmss_address.h:313
MechanismType hash