Botan 3.3.0
Crypto and TLS for C&
sp_hash_shake.h
Go to the documentation of this file.
1/*
2 * SPHINCS+ Hash Implementation for SHA-256
3 * (C) 2023 Jack Lloyd
4 * 2023 Fabian Albert, René Meusel, Amos Treiber - Rohde & Schwarz Cybersecurity
5 *
6 * Botan is released under the Simplified BSD License (see license.txt)
7 */
8
9#ifndef BOTAN_SP_HASH_SHAKE_H_
10#define BOTAN_SP_HASH_SHAKE_H_
11
12#include <botan/internal/sp_hash.h>
13
14#include <botan/internal/shake.h>
15
16namespace Botan {
17
18/**
19 * Implementation of SPHINCS+ hash function abstraction for SHAKE256
20 */
22 private:
23 HashFunction& tweak_hash(const Sphincs_Address& address, size_t input_length) override {
24 BOTAN_UNUSED(input_length);
25 m_hash.update(m_pub_seed);
26 m_hash.update(address.to_bytes());
27 return m_hash;
28 }
29
30 std::vector<uint8_t> H_msg_digest(StrongSpan<const SphincsMessageRandomness> r,
31 const SphincsTreeNode& root,
32 std::span<const uint8_t> message) override {
33 m_h_msg_hash.update(r);
34 m_h_msg_hash.update(m_pub_seed);
35 m_h_msg_hash.update(root);
36 m_h_msg_hash.update(message);
37
38 return m_h_msg_hash.final_stdvec();
39 }
40
41 public:
42 Sphincs_Hash_Functions_Shake(const Sphincs_Parameters& sphincs_params, const SphincsPublicSeed& pub_seed) :
43 Sphincs_Hash_Functions(sphincs_params, pub_seed),
44 m_seeded_hash(sphincs_params.n() * 8),
45 m_hash(sphincs_params.n() * 8),
46 m_h_msg_hash(8 * sphincs_params.h_msg_digest_bytes()) {
47 m_seeded_hash.update(m_pub_seed);
48 }
49
51 const SphincsSecretPRF& sk_prf,
52 const SphincsOptionalRandomness& opt_rand,
53 std::span<const uint8_t> in) override {
54 m_hash.update(sk_prf);
55 m_hash.update(opt_rand);
56 m_hash.update(in);
57 m_hash.final(out);
58 }
59
60 std::string msg_hash_function_name() const override { return m_h_msg_hash.name(); }
61
62 private:
63 SHAKE_256 m_seeded_hash;
64 SHAKE_256 m_hash;
65 SHAKE_256 m_h_msg_hash;
66};
67
68} // namespace Botan
69
70#endif
#define BOTAN_UNUSED
Definition assert.h:118
void update(const uint8_t in[], size_t length)
Definition buf_comp.h:35
std::vector< uint8_t > final_stdvec()
Definition buf_comp.h:84
void final(uint8_t out[])
Definition buf_comp.h:70
std::string name() const override
Definition shake.cpp:49
std::array< uint8_t, 32 > to_bytes() const
Definition sp_address.h:134
Sphincs_Hash_Functions_Shake(const Sphincs_Parameters &sphincs_params, const SphincsPublicSeed &pub_seed)
std::string msg_hash_function_name() const override
void PRF_msg(StrongSpan< SphincsMessageRandomness > out, const SphincsSecretPRF &sk_prf, const SphincsOptionalRandomness &opt_rand, std::span< const uint8_t > in) override
const SphincsPublicSeed & m_pub_seed
Definition sp_hash.h:102