Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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 Matthias Gierlings
5 *
6 * Botan is released under the Simplified BSD License (see license.txt)
7 **/
8
9 #include <botan/xmss_common_ops.h>
10
11 namespace Botan {
12
13 void
14 XMSS_Common_Ops::randomize_tree_hash(secure_vector<uint8_t>& result,
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 {
20 adrs.set_key_mask_mode(XMSS_Address::Key_Mask::Key_Mode);
21 secure_vector<uint8_t> key { m_hash.prf(seed, adrs.bytes()) };
22
23 adrs.set_key_mask_mode(XMSS_Address::Key_Mask::Mask_MSB_Mode);
24 secure_vector<uint8_t> bitmask_l { m_hash.prf(seed, adrs.bytes()) };
25
26 adrs.set_key_mask_mode(XMSS_Address::Key_Mask::Mask_LSB_Mode);
27 secure_vector<uint8_t> bitmask_r { m_hash.prf(seed, adrs.bytes()) };
28
29 BOTAN_ASSERT(bitmask_l.size() == left.size() &&
30 bitmask_r.size() == right.size(),
31 "Bitmask size doesn't match node size.");
32
33 secure_vector<uint8_t> concat_xor(m_xmss_params.element_size() * 2);
34 for(size_t i = 0; i < left.size(); i++)
35 {
36 concat_xor[i] = left[i] ^ bitmask_l[i];
37 concat_xor[i + left.size()] = right[i] ^ bitmask_r[i];
38 }
39
40 m_hash.h(result, key, concat_xor);
41 }
42
43
44 void
45 XMSS_Common_Ops::create_l_tree(secure_vector<uint8_t>& result,
46 wots_keysig_t pk,
47 XMSS_Address& adrs,
48 const secure_vector<uint8_t>& seed)
49 {
50 size_t l = m_xmss_params.len();
51 adrs.set_tree_height(0);
52
53 while(l > 1)
54 {
55 for(size_t i = 0; i < l >> 1; i++)
56 {
57 adrs.set_tree_index(i);
58 randomize_tree_hash(pk[i], pk[2 * i], pk[2 * i + 1], adrs, seed);
59 }
60 if(l & 0x01)
61 {
62 pk[l >> 1] = pk[l - 1];
63 }
64 l = (l >> 1) + (l & 0x01);
65 adrs.set_tree_height(adrs.get_tree_height() + 1);
66 }
67 result = pk[0];
68 }
69
70 }
Botan::XMSS_Address::Key_Mask::Mask_MSB_Mode
Botan::XMSS_Parameters::element_size
size_t element_size() const
Definition: xmss_parameters.h:72
Botan::XMSS_Common_Ops::create_l_tree
void create_l_tree(secure_vector< uint8_t > &result, wots_keysig_t pk, XMSS_Address &adrs, const secure_vector< uint8_t > &seed)
Definition: xmss_common_ops.cpp:45
Botan::XMSS_Hash::h
void h(secure_vector< uint8_t > &result, const secure_vector< uint8_t > &key, const secure_vector< uint8_t > &data)
Definition: xmss_hash.cpp:36
Botan::XMSS_Address::set_tree_height
void set_tree_height(uint32_t value)
Definition: xmss_address.h:255
Botan::XMSS_Address
Definition: xmss_address.h:23
BOTAN_ASSERT
#define BOTAN_ASSERT(expr, assertion_made)
Definition: assert.h:27
Botan::secure_vector
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:121
Botan::XMSS_Hash::prf
void prf(secure_vector< uint8_t > &result, const secure_vector< uint8_t > &key, const secure_vector< uint8_t > &data)
Definition: xmss_hash.h:38
Botan::XMSS_Common_Ops::m_xmss_params
XMSS_Parameters m_xmss_params
Definition: xmss_common_ops.h:68
Botan::XMSS_Common_Ops::randomize_tree_hash
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)
Definition: xmss_common_ops.cpp:14
Botan::XMSS_Common_Ops::m_hash
XMSS_Hash m_hash
Definition: xmss_common_ops.h:69
Botan
Definition: alg_id.cpp:13
Botan::wots_keysig_t
std::vector< secure_vector< uint8_t > > wots_keysig_t
Definition: xmss_common_ops.h:20
Botan::XMSS_Address::Key_Mask::Mask_LSB_Mode
Botan::XMSS_Parameters::len
size_t len() const
Definition: xmss_parameters.h:87
Botan::XMSS_Address::set_key_mask_mode
void set_key_mask_mode(Key_Mask value)
Definition: xmss_address.h:136
Botan::XMSS_Address::bytes
const secure_vector< uint8_t > & bytes() const
Definition: xmss_address.h:326
Botan::XMSS_Address::set_tree_index
void set_tree_index(uint32_t value)
Definition: xmss_address.h:317
Botan::XMSS_Address::get_tree_height
uint32_t get_tree_height() const
Definition: xmss_address.h:239
Botan::XMSS_Address::Key_Mask::Key_Mode