Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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 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
15 XMSS_Hash::XMSS_Hash(const XMSS_Hash& hash)
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_func_name(h_func_name),
22 m_hash(HashFunction::create(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
36 XMSS_Hash::h(secure_vector<uint8_t>& result,
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
47 void XMSS_Hash::h_msg_init(const secure_vector<uint8_t>& randomness,
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 secure_vector<uint8_t>& data)
60 {
61 m_msg_hash->update(data);
62 }
63
64 void XMSS_Hash::h_msg_update(const uint8_t data[], size_t size)
65 {
66 m_msg_hash->update(data, size);
67 }
68
69 secure_vector<uint8_t> XMSS_Hash::h_msg_final()
70 {
71 return m_msg_hash->final();
72 }
73
74 secure_vector<uint8_t>
75 XMSS_Hash::h_msg(const secure_vector<uint8_t>& randomness,
76 const secure_vector<uint8_t>& root,
77 const secure_vector<uint8_t>& index_bytes,
78 const secure_vector<uint8_t>& data)
79 {
80 h_msg_init(randomness, root, index_bytes);
81 m_msg_hash->update(data);
82 return m_msg_hash->final();
83 }
84
85 }
Botan::XMSS_Hash::h_msg_final
secure_vector< uint8_t > h_msg_final()
Definition: xmss_hash.cpp:69
Botan::XMSS_Hash::XMSS_Hash
XMSS_Hash(const std::string &h_func_name)
Definition: xmss_hash.cpp:20
Botan::XMSS_Hash::h_msg_update
void h_msg_update(const secure_vector< uint8_t > &data)
Definition: xmss_hash.cpp:59
Botan::XMSS_Hash
Definition: xmss_hash.h:24
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_Hash::h_msg
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:75
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::Lookup_Error
Definition: exceptn.h:71
Botan
Definition: alg_id.cpp:13
Botan::XMSS_Hash::h_msg_init
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
Botan::HashFunction
Definition: hash.h:19
m_hash
std::unique_ptr< HashFunction > m_hash
Definition: tpm.cpp:439
hash
MechanismType hash
Definition: p11_mechanism.cpp:63