Botan  2.7.0
Crypto and TLS for C++11
xmss_hash.cpp
Go to the documentation of this file.
1 /*
2  * XMSS Hash
3  * A collection of pseudorandom hash functions required for XMSS and WOTS
4  * computations.
5  * (C) 2016,2017 Matthias Gierlings
6  *
7  * Botan is released under the Simplified BSD License (see license.txt)
8  **/
9 
10 #include <botan/xmss_hash.h>
11 #include <botan/exceptn.h>
12 
13 namespace Botan {
14 
16  : XMSS_Hash(hash.m_hash_func_name)
17  {
18  }
19 
20 XMSS_Hash::XMSS_Hash(const std::string& h_func_name) :
21  m_hash(HashFunction::create(h_func_name)),
22  m_hash_func_name(h_func_name)
23  {
24  if(!m_hash)
25  throw Lookup_Error("XMSS cannot use hash " + h_func_name +
26  " because it is unavailable");
27 
28  m_output_length = m_hash->output_length();
29  BOTAN_ASSERT(m_output_length > 0, "Hash output length of zero is invalid.");
30 
31  m_zero_padding.resize(m_output_length - 1);
32  m_msg_hash.reset(m_hash->clone());
33  }
34 
35 void
37  const secure_vector<uint8_t>& key,
38  const secure_vector<uint8_t>& data)
39  {
40  m_hash->update(m_zero_padding);
41  m_hash->update(m_id_h);
42  m_hash->update(key);
43  m_hash->update(data);
44  m_hash->final(result);
45  }
46 
48  const secure_vector<uint8_t>& root,
49  const secure_vector<uint8_t>& index_bytes)
50  {
51  m_msg_hash->clear();
52  m_msg_hash->update(m_zero_padding);
53  m_msg_hash->update(m_id_hmsg);
54  m_msg_hash->update(randomness);
55  m_msg_hash->update(root);
56  m_msg_hash->update(index_bytes);
57  }
58 
59 void XMSS_Hash::h_msg_update(const uint8_t data[], size_t size)
60  {
61  m_msg_hash->update(data, size);
62  }
63 
65  {
66  return m_msg_hash->final();
67  }
68 
71  const secure_vector<uint8_t>& root,
72  const secure_vector<uint8_t>& index_bytes,
73  const secure_vector<uint8_t>& data)
74  {
75  h_msg_init(randomness, root, index_bytes);
76  m_msg_hash->update(data);
77  return m_msg_hash->final();
78  }
79 
80 }
secure_vector< uint8_t > h_msg_final()
Definition: xmss_hash.cpp:64
XMSS_Hash(const std::string &h_func_name)
Definition: xmss_hash.cpp:20
void h(secure_vector< uint8_t > &result, const secure_vector< uint8_t > &key, const secure_vector< uint8_t > &data)
Definition: xmss_hash.cpp:36
void h_msg_update(const uint8_t data[], size_t size)
Definition: xmss_hash.cpp:59
secure_vector< uint8_t > h_msg(const secure_vector< uint8_t > &randomness, const secure_vector< uint8_t > &root, const secure_vector< uint8_t > &index_bytes, const secure_vector< uint8_t > &data)
Definition: xmss_hash.cpp:70
#define BOTAN_ASSERT(expr, assertion_made)
Definition: assert.h:43
Definition: alg_id.cpp:13
void h_msg_init(const secure_vector< uint8_t > &randomness, const secure_vector< uint8_t > &root, const secure_vector< uint8_t > &index_bytes)
Definition: xmss_hash.cpp:47
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:88
MechanismType hash