Botan 3.6.1
Crypto and TLS for C&
sp_hash_shake.h
Go to the documentation of this file.
1/*
2 * SLH-DSA 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 SLH-DSA 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 const SphincsMessageInternal& 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.prefix);
37 m_h_msg_hash.update(message.message);
38
39 return m_h_msg_hash.final_stdvec();
40 }
41
42 public:
43 Sphincs_Hash_Functions_Shake(const Sphincs_Parameters& sphincs_params, const SphincsPublicSeed& pub_seed) :
44 Sphincs_Hash_Functions(sphincs_params, pub_seed),
45 m_seeded_hash(sphincs_params.n() * 8),
46 m_hash(sphincs_params.n() * 8),
47 m_h_msg_hash(8 * sphincs_params.h_msg_digest_bytes()) {
48 m_seeded_hash.update(m_pub_seed);
49 }
50
54 const SphincsMessageInternal& msg) override {
55 m_hash.update(sk_prf);
56 m_hash.update(opt_rand);
57 m_hash.update(msg.prefix);
58 m_hash.update(msg.message);
59 m_hash.final(out);
60 }
61
62 std::string msg_hash_function_name() const override { return m_h_msg_hash.name(); }
63
64 private:
65 SHAKE_256 m_seeded_hash;
66 SHAKE_256 m_hash;
67 SHAKE_256 m_h_msg_hash;
68};
69
70} // namespace Botan
71
72#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:139
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, StrongSpan< const SphincsSecretPRF > sk_prf, StrongSpan< const SphincsOptionalRandomness > opt_rand, const SphincsMessageInternal &msg) override
const SphincsPublicSeed & m_pub_seed
Definition sp_hash.h:103
Gf448Elem root(const Gf448Elem &elem)
Compute the root of elem in the field.
M' representation of FIPS 205 (the input to slh_sign_internal and slh_verify_internal)
Definition sp_types.h:52
SphincsInputMessage message
Definition sp_types.h:54
SphincsMessagePrefix prefix
Definition sp_types.h:53