Botan  2.4.0
Crypto and TLS for C++11
xmss_wots_publickey.cpp
Go to the documentation of this file.
1 /*
2  * XMSS WOTS Public Key
3  * A Winternitz One Time Signature public key for use with Extended Hash-Based
4  * Signatures.
5  *
6  * (C) 2016,2017 Matthias Gierlings
7  *
8  * Botan is released under the Simplified BSD License (see license.txt)
9  **/
10 
11 #include <botan/xmss_wots_publickey.h>
12 
13 namespace Botan {
14 
15 void
17  size_t start_idx,
18  size_t steps,
19  XMSS_Address& adrs,
20  const secure_vector<uint8_t>& seed,
21  XMSS_Hash& hash)
22  {
23  for(size_t i = start_idx;
24  i < (start_idx + steps) && i < m_wots_params.wots_parameter();
25  i++)
26  {
27  adrs.set_hash_address(i);
28 
29  //Calculate tmp XOR bitmask
31  xor_buf(result, hash.prf(seed, adrs.bytes()), result.size());
32 
33  // Calculate key
35 
36  //Calculate f(key, tmp XOR bitmask)
37  hash.f(result, hash.prf(seed, adrs.bytes()), result);
38  }
39  }
40 
42 XMSS_WOTS_PublicKey::pub_key_from_signature(const secure_vector<uint8_t>& msg,
43  const wots_keysig_t& sig,
44  XMSS_Address& adrs,
45  const secure_vector<uint8_t>& seed)
46  {
47  secure_vector<uint8_t> msg_digest
48  {
50  };
51 
52  m_wots_params.append_checksum(msg_digest);
53  wots_keysig_t result(sig);
54 
55  for(size_t i = 0; i < m_wots_params.len(); i++)
56  {
57  adrs.set_chain_address(i);
58  chain(result[i],
59  msg_digest[i],
60  m_wots_params.wots_parameter() - 1 - msg_digest[i],
61  adrs,
62  seed);
63  }
64  return result;
65  }
66 
67 }
secure_vector< uint8_t > base_w(const secure_vector< uint8_t > &msg, size_t out_size) const
void f(secure_vector< uint8_t > &result, const secure_vector< uint8_t > &key, const secure_vector< uint8_t > &data)
Definition: xmss_hash.h:69
void chain(secure_vector< uint8_t > &x, size_t start_idx, size_t steps, XMSS_Address &adrs, const secure_vector< uint8_t > &public_seed, XMSS_Hash &hash)
const secure_vector< uint8_t > & bytes() const
Definition: xmss_address.h:322
void xor_buf(uint8_t out[], const uint8_t in[], size_t length)
Definition: mem_ops.h:163
void prf(secure_vector< uint8_t > &result, const secure_vector< uint8_t > &key, const secure_vector< uint8_t > &data)
Definition: xmss_hash.h:33
Definition: alg_id.cpp:13
void set_chain_address(uint32_t value)
Definition: xmss_address.h:220
std::vector< secure_vector< uint8_t > > wots_keysig_t
void append_checksum(secure_vector< uint8_t > &data)
void set_key_mask_mode(Key_Mask value)
Definition: xmss_address.h:134
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:88
void set_hash_address(uint32_t value)
Definition: xmss_address.h:282
MechanismType hash
XMSS_WOTS_Parameters m_wots_params