Botan  2.4.0
Crypto and TLS for C++11
xmss_wots_privatekey.cpp
Go to the documentation of this file.
1 /*
2  * XMSS WOTS Private Key
3  * A Winternitz One Time Signature private 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_privatekey.h>
12 
13 namespace Botan {
14 
16 XMSS_WOTS_PrivateKey::generate(const secure_vector<uint8_t>& priv_seed,
17  XMSS_Hash& hash)
18  {
19  wots_keysig_t priv_key(m_wots_params.len(),
20  secure_vector<uint8_t>(0));
21 
22  for(size_t i = 0; i < m_wots_params.len(); i++)
23  {
24  XMSS_Tools::concat<size_t>(priv_key[i], i, 32);
25  hash.prf(priv_key[i], priv_seed, priv_key[i]);
26  }
27  return priv_key;
28  }
29 
30 
33  {
35  public_seed());
36  generate_public_key(pub_key, wots_keysig_t((*this)[adrs]), adrs);
37  return pub_key;
38  }
39 
40 void
42  wots_keysig_t&& in_key_data,
43  XMSS_Address& adrs,
44  XMSS_Hash& hash)
45  {
47  public_seed() == pub_key.public_seed(),
48  "Conflicting public key data.");
49 
50  pub_key.set_key_data(std::move(in_key_data));
51  for(size_t i = 0; i < m_wots_params.len(); i++)
52  {
53  adrs.set_chain_address(i);
54  chain(pub_key[i], 0, m_wots_params.wots_parameter() - 1, adrs,
55  public_seed(), hash);
56  }
57  }
58 
61  XMSS_Address& adrs,
62  XMSS_Hash& hash)
63 
64  {
65  secure_vector<uint8_t> msg_digest
66  {
68  };
69 
70  m_wots_params.append_checksum(msg_digest);
71  wots_keysig_t sig(this->at(adrs, hash));
72 
73  for(size_t i = 0; i < m_wots_params.len(); i++)
74  {
75  adrs.set_chain_address(i);
76  chain(sig[i], 0 , msg_digest[i], adrs, m_public_seed, hash);
77  }
78 
79  return sig;
80  }
81 
82 }
const secure_vector< uint8_t > & public_seed() const
secure_vector< uint8_t > base_w(const secure_vector< uint8_t > &msg, size_t out_size) const
wots_keysig_t sign(const secure_vector< uint8_t > &msg, XMSS_Address &adrs)
secure_vector< uint8_t > m_public_seed
wots_keysig_t at(size_t i, XMSS_Hash &hash)
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)
#define BOTAN_ASSERT(expr, assertion_made)
Definition: assert.h:29
XMSS_WOTS_PublicKey(XMSS_WOTS_Parameters::ots_algorithm_t oid)
XMSS_WOTS_PublicKey generate_public_key(XMSS_Address &adrs)
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
const XMSS_WOTS_Parameters & wots_parameters() const
void set_key_data(const wots_keysig_t &key_data)
void append_checksum(secure_vector< uint8_t > &data)
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:88
MechanismType hash
XMSS_WOTS_Parameters m_wots_params
ots_algorithm_t oid() const