Bitcoin Core  31.0.0
P2P Digital Currency
sha3.h
Go to the documentation of this file.
1 // Copyright (c) 2020-present The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef BITCOIN_CRYPTO_SHA3_H
6 #define BITCOIN_CRYPTO_SHA3_H
7 
8 #include <cstdint>
9 #include <cstdlib>
10 #include <span>
11 
13 void KeccakF(uint64_t (&st)[25]);
14 
15 class SHA3_256
16 {
17 private:
18  uint64_t m_state[25] = {0};
19  unsigned char m_buffer[8];
20  unsigned m_bufsize = 0;
21  unsigned m_pos = 0;
22 
24  static constexpr unsigned RATE_BITS = 1088;
25 
27  static constexpr unsigned RATE_BUFFERS = RATE_BITS / (8 * sizeof(m_buffer));
28 
29  static_assert(RATE_BITS % (8 * sizeof(m_buffer)) == 0, "Rate must be a multiple of 8 bytes");
30 
31 public:
32  static constexpr size_t OUTPUT_SIZE = 32;
33 
34  SHA3_256() = default;
35  SHA3_256& Write(std::span<const unsigned char> data);
36  SHA3_256& Finalize(std::span<unsigned char> output);
37  SHA3_256& Reset();
38 };
39 
40 #endif // BITCOIN_CRYPTO_SHA3_H
SHA3_256 & Write(std::span< const unsigned char > data)
Definition: sha3.cpp:105
Definition: sha3.h:15
static constexpr size_t OUTPUT_SIZE
Definition: sha3.h:32
static constexpr unsigned RATE_BITS
Sponge rate in bits.
Definition: sha3.h:24
uint64_t m_state[25]
Definition: sha3.h:18
SHA3_256 & Finalize(std::span< unsigned char > output)
Definition: sha3.cpp:135
void KeccakF(uint64_t(&st)[25])
The Keccak-f[1600] transform.
Definition: sha3.cpp:17
unsigned char m_buffer[8]
Definition: sha3.h:19
unsigned m_bufsize
Definition: sha3.h:20
SHA3_256()=default
SHA3_256 & Reset()
Definition: sha3.cpp:149
unsigned m_pos
Definition: sha3.h:21
static constexpr unsigned RATE_BUFFERS
Sponge rate expressed as a multiple of the buffer size.
Definition: sha3.h:27