Botan 3.6.1
Crypto and TLS for C&
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/internal/xmss_hash.h>
11
12#include <botan/exceptn.h>
13#include <botan/xmss_parameters.h>
14#include <botan/internal/fmt.h>
15
16namespace Botan {
17
19 m_hash(hash.m_hash->new_object()),
20 m_msg_hash(hash.m_msg_hash->new_object()),
21 m_zero_padding(hash.m_zero_padding) {}
22
24 m_hash(HashFunction::create(params.hash_function_name())),
25 m_msg_hash(HashFunction::create(params.hash_function_name())),
26 m_zero_padding(params.hash_id_size() - 1 /* hash IDs are a single uint8_t */) {
27 if(!m_hash || !m_msg_hash) {
28 throw Lookup_Error(fmt("XMSS cannot use hash {} because it is unavailable", params.hash_function_name()));
29 }
30
31 BOTAN_ASSERT(m_hash->output_length() > 0, "Hash output length of zero is invalid.");
32}
33
34void XMSS_Hash::h_msg_init(std::span<const uint8_t> randomness,
35 std::span<const uint8_t> root,
36 std::span<const uint8_t> index_bytes) {
37 m_msg_hash->clear();
38 m_msg_hash->update(m_zero_padding);
39 m_msg_hash->update(0x02);
40 m_msg_hash->update(randomness.data(), randomness.size());
41 m_msg_hash->update(root.data(), root.size());
42 m_msg_hash->update(index_bytes.data(), index_bytes.size());
43}
44
45void XMSS_Hash::h_msg_update(std::span<const uint8_t> data) {
46 m_msg_hash->update(data.data(), data.size());
47}
48
50 return m_msg_hash->final();
51}
52
53} // namespace Botan
#define BOTAN_ASSERT(expr, assertion_made)
Definition assert.h:50
secure_vector< uint8_t > h_msg_final()
Definition xmss_hash.cpp:49
void h_msg_update(std::span< const uint8_t > data)
Definition xmss_hash.cpp:45
XMSS_Hash(const XMSS_Parameters &params)
Definition xmss_hash.cpp:23
void h_msg_init(std::span< const uint8_t > randomness, std::span< const uint8_t > root, std::span< const uint8_t > index_bytes)
Definition xmss_hash.cpp:34
const std::string & hash_function_name() const
Gf448Elem root(const Gf448Elem &elem)
Compute the root of elem in the field.
std::string fmt(std::string_view format, const T &... args)
Definition fmt.h:53
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:61