14 0x0000000000000001ULL, 0x0000000000008082ULL,
15 0x800000000000808AULL, 0x8000000080008000ULL,
16 0x000000000000808BULL, 0x0000000080000001ULL,
17 0x8000000080008081ULL, 0x8000000000008009ULL,
18 0x000000000000008AULL, 0x0000000000000088ULL,
19 0x0000000080008009ULL, 0x000000008000000AULL,
20 0x000000008000808BULL, 0x800000000000008BULL,
21 0x8000000000008089ULL, 0x8000000000008003ULL,
22 0x8000000000008002ULL, 0x8000000000000080ULL,
23 0x000000000000800AULL, 0x800000008000000AULL,
24 0x8000000080008081ULL, 0x8000000000008080ULL,
25 0x0000000080000001ULL, 0x8000000080008008ULL,
45 unsigned int round, x, y;
49 for (x = 0U; x < 5U; x++) {
50 C[x] = st[x] ^ st[x + 5U] ^ st[x + 10U] ^ st[x + 15U] ^ st[x + 20U];
52 for (x = 0U; x < 5U; x++) {
53 D[x] = C[(x + 4U) % 5U] ^
rot64(C[(x + 1U) % 5U], 1U);
55 for (x = 0U; x < 5U; x++) {
56 for (y = 0U; y < 5U; y++) {
57 st[x + 5U * y] ^= D[x];
62 for (x = 0U; x < 5U; x++) {
63 for (y = 0U; y < 5U; y++) {
64 unsigned int src = x + 5U * y;
65 unsigned int dst_x = y;
66 unsigned int dst_y = (2U * x + 3U * y) % 5U;
67 B[dst_x + 5U * dst_y] =
rot64(st[src],
kRHO[src]);
72 for (x = 0U; x < 5U; x++) {
73 for (y = 0U; y < 5U; y++) {
74 st[x + 5U * y] = B[x + 5U * y] ^
75 ((~B[(x + 1U) % 5U + 5U * y]) &
76 B[(x + 2U) % 5U + 5U * y]);
85void keccak256(
const uint8_t *input,
size_t length, uint8_t digest[32])
88 uint8_t *sb = (uint8_t *)state;
92 (void)memset(state, 0,
sizeof(state));
97 sb[i] ^= input[offset + i];
104 size_t rem = length - offset;
105 for (i = 0U; i < rem; i++) {
106 sb[i] ^= input[offset + i];
116 (void)memcpy(digest, sb, 32U);