Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
sha3.h
Go to the documentation of this file.
1// Copyright (c) 2020 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 <span.h>
9
10#include <cstdint>
11#include <cstdlib>
12
14void KeccakF(uint64_t (&st)[25]);
15
16class SHA3_256 {
17private:
18 uint64_t m_state[25] = {0};
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,
30 "Rate must be a multiple of 8 bytes");
31
32public:
33 static constexpr size_t OUTPUT_SIZE = 32;
34
38 SHA3_256 &Reset();
39};
40
41#endif // BITCOIN_CRYPTO_SHA3_H
SHA3_256 & Finalize(Span< uint8_t > output)
Definition sha3.cpp:232
unsigned m_bufsize
Definition sha3.h:20
uint8_t m_buffer[8]
Definition sha3.h:19
static constexpr unsigned RATE_BUFFERS
Sponge rate expressed as a multiple of the buffer size.
Definition sha3.h:27
SHA3_256 & Reset()
Definition sha3.cpp:245
SHA3_256()
Definition sha3.h:35
SHA3_256 & Write(Span< const uint8_t > data)
Definition sha3.cpp:202
unsigned m_pos
Definition sha3.h:21
uint64_t m_state[25]
Definition sha3.h:18
static constexpr size_t OUTPUT_SIZE
Definition sha3.h:33
static constexpr unsigned RATE_BITS
Sponge rate in bits.
Definition sha3.h:24
A Span is an object that can refer to a contiguous sequence of objects.
Definition span.h:93
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85
void KeccakF(uint64_t(&st)[25])
The Keccak-f[1600] transform.
Definition sha3.cpp:23