19 static const uint8_t
rho[24] = \
20 { 1, 3, 6, 10, 15, 21,
21 28, 36, 45, 55, 2, 14,
22 27, 41, 56, 8, 25, 43,
23 62, 18, 39, 61, 20, 44};
24 static const uint8_t pi[24] = \
25 {10, 7, 11, 17, 18, 3,
27 15, 23, 19, 13, 12, 2,
29 static const uint64_t RC[24] = \
30 {1ULL, 0x8082ULL, 0x800000000000808aULL, 0x8000000080008000ULL,
31 0x808bULL, 0x80000001ULL, 0x8000000080008081ULL, 0x8000000000008009ULL,
32 0x8aULL, 0x88ULL, 0x80008009ULL, 0x8000000aULL,
33 0x8000808bULL, 0x800000000000008bULL, 0x8000000000008089ULL, 0x8000000000008003ULL,
34 0x8000000000008002ULL, 0x8000000000000080ULL, 0x800aULL, 0x800000008000000aULL,
35 0x8000000080008081ULL, 0x8000000000008080ULL, 0x80000001ULL, 0x8000000080008008ULL};
38 #define rol(x, s) (((x) << s) | ((x) >> (64 - s))) 39 #define REPEAT6(e) e e e e e e 40 #define REPEAT24(e) REPEAT6(e e e e) 41 #define REPEAT5(e) e e e e e 42 #define FOR5(v, s, e) \ 47 static inline void keccakf(
void* state) {
48 uint64_t*
a = (uint64_t*)state;
53 for (
int i = 0; i < 24; i++) {
61 a[y + x] ^= b[(x + 4) % 5] ^
rol(b[(x + 1) % 5], 1); ))
75 a[y + x] = b[x] ^ ((~b[(x + 1) % 5]) & b[(x + 2) % 5]); ))
85 #define _(S) do { S } while (0) 86 #define FOR(i, ST, L, S) \ 87 _(for (size_t i = 0; i < L; i += ST) { S; }) 88 #define mkapply_ds(NAME, S) \ 89 static inline void NAME(uint8_t* dst, \ 94 #define mkapply_sd(NAME, S) \ 95 static inline void NAME(const uint8_t* src, \ 108 #define foldP(I, L, F) \ 109 while (L >= rate) { \ 117 static inline int hash(uint8_t* out,
size_t outlen,
118 const uint8_t* in,
size_t inlen,
119 size_t rate, uint8_t delim) {
120 if ((out == NULL) || ((in == NULL) && inlen != 0) || (rate >=
Plen)) {
123 uint8_t
a[
Plen] = {0};
125 foldP(in, inlen, xorin);
134 foldP(out, outlen, setout);
135 setout(a, out, outlen);
140 #define defsha3(bits) \ 141 int sha3_##bits(uint8_t* out, size_t outlen, \ 142 const uint8_t* in, size_t inlen) { \ 143 if (outlen > (bits/8)) { \ 146 return hash(out, outlen, in, inlen, 200 - (bits / 4), 0x01); \
#define mkapply_ds(NAME, S)
#define mkapply_sd(NAME, S)