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