18uint64_t Rotl(uint64_t x,
int n) {
19 return (x << n) | (x >> (64 - n));
24 static constexpr uint64_t RNDC[24] = {
25 0x0000000000000001, 0x0000000000008082, 0x800000000000808a,
26 0x8000000080008000, 0x000000000000808b, 0x0000000080000001,
27 0x8000000080008081, 0x8000000000008009, 0x000000000000008a,
28 0x0000000000000088, 0x0000000080008009, 0x000000008000000a,
29 0x000000008000808b, 0x800000000000008b, 0x8000000000008089,
30 0x8000000000008003, 0x8000000000008002, 0x8000000000000080,
31 0x000000000000800a, 0x800000008000000a, 0x8000000080008081,
32 0x8000000000008080, 0x0000000080000001, 0x8000000080008008};
33 static constexpr int ROUNDS = 24;
35 for (
int round = 0; round < ROUNDS; ++round) {
36 uint64_t bc0, bc1, bc2, bc3, bc4, t;
39 bc0 = st[0] ^ st[5] ^ st[10] ^ st[15] ^ st[20];
40 bc1 = st[1] ^ st[6] ^ st[11] ^ st[16] ^ st[21];
41 bc2 = st[2] ^ st[7] ^ st[12] ^ st[17] ^ st[22];
42 bc3 = st[3] ^ st[8] ^ st[13] ^ st[18] ^ st[23];
43 bc4 = st[4] ^ st[9] ^ st[14] ^ st[19] ^ st[24];
44 t = bc4 ^ Rotl(bc1, 1);
50 t = bc0 ^ Rotl(bc2, 1);
56 t = bc1 ^ Rotl(bc3, 1);
62 t = bc2 ^ Rotl(bc4, 1);
68 t = bc3 ^ Rotl(bc0, 1);
105 st[21] = Rotl(t, 55);
114 st[15] = Rotl(t, 27);
117 st[23] = Rotl(t, 41);
120 st[19] = Rotl(t, 56);
126 st[12] = Rotl(t, 25);
132 st[20] = Rotl(t, 62);
135 st[14] = Rotl(t, 18);
138 st[22] = Rotl(t, 39);
154 st[0] = bc0 ^ (~bc1 & bc2) ^ RNDC[round];
155 st[1] = bc1 ^ (~bc2 & bc3);
156 st[2] = bc2 ^ (~bc3 & bc4);
157 st[3] = bc3 ^ (~bc4 & bc0);
158 st[4] = bc4 ^ (~bc0 & bc1);
164 st[5] = bc0 ^ (~bc1 & bc2);
165 st[6] = bc1 ^ (~bc2 & bc3);
166 st[7] = bc2 ^ (~bc3 & bc4);
167 st[8] = bc3 ^ (~bc4 & bc0);
168 st[9] = bc4 ^ (~bc0 & bc1);
174 st[10] = bc0 ^ (~bc1 & bc2);
175 st[11] = bc1 ^ (~bc2 & bc3);
176 st[12] = bc2 ^ (~bc3 & bc4);
177 st[13] = bc3 ^ (~bc4 & bc0);
178 st[14] = bc4 ^ (~bc0 & bc1);
184 st[15] = bc0 ^ (~bc1 & bc2);
185 st[16] = bc1 ^ (~bc2 & bc3);
186 st[17] = bc2 ^ (~bc3 & bc4);
187 st[18] = bc3 ^ (~bc4 & bc0);
188 st[19] = bc4 ^ (~bc0 & bc1);
194 st[20] = bc0 ^ (~bc1 & bc2);
195 st[21] = bc1 ^ (~bc2 & bc3);
196 st[22] = bc2 ^ (~bc3 & bc4);
197 st[23] = bc3 ^ (~bc4 & bc0);
198 st[24] = bc4 ^ (~bc0 & bc1);
239 for (
unsigned i = 0; i < 4; ++i) {
SHA3_256 & Finalize(Span< uint8_t > output)
static constexpr unsigned RATE_BUFFERS
Sponge rate expressed as a multiple of the buffer size.
SHA3_256 & Write(Span< const uint8_t > data)
static constexpr size_t OUTPUT_SIZE
constexpr std::size_t size() const noexcept
CONSTEXPR_IF_NOT_DEBUG Span< C > subspan(std::size_t offset) const noexcept
constexpr C * data() const noexcept
constexpr C * begin() const noexcept
constexpr C * end() const noexcept
static uint64_t ReadLE64(const uint8_t *ptr)
static void WriteLE64(uint8_t *ptr, uint64_t x)
void KeccakF(uint64_t(&st)[25])
The Keccak-f[1600] transform.