14 fprintf(stderr,
"%s\n", msg);
24 0x0000000000000001, 0x0000000000008082, 0x800000000000808a,
25 0x8000000080008000, 0x000000000000808b, 0x0000000080000001,
26 0x8000000080008081, 0x8000000000008009, 0x000000000000008a,
27 0x0000000000000088, 0x0000000080008009, 0x000000008000000a,
28 0x000000008000808b, 0x800000000000008b, 0x8000000000008089,
29 0x8000000000008003, 0x8000000000008002, 0x8000000000000080,
30 0x000000000000800a, 0x800000008000000a, 0x8000000080008081,
31 0x8000000000008080, 0x0000000080000001, 0x8000000080008008
43 bc[0] = st[0] ^ st[5] ^ st[10] ^ st[15] ^ st[20];
44 bc[1] = st[1] ^ st[6] ^ st[11] ^ st[16] ^ st[21];
45 bc[2] = st[2] ^ st[7] ^ st[12] ^ st[17] ^ st[22];
46 bc[3] = st[3] ^ st[8] ^ st[13] ^ st[18] ^ st[23];
47 bc[4] = st[4] ^ st[9] ^ st[14] ^ st[19] ^ st[24];
50 t = bc[(i + 4) % 5] ^ ROTL64(bc[(i + 1) % 5], 1); \
66 st[ 1] =
ROTL64(st[ 6], 44);
67 st[ 6] =
ROTL64(st[ 9], 20);
68 st[ 9] =
ROTL64(st[22], 61);
69 st[22] =
ROTL64(st[14], 39);
70 st[14] =
ROTL64(st[20], 18);
71 st[20] =
ROTL64(st[ 2], 62);
72 st[ 2] =
ROTL64(st[12], 43);
73 st[12] =
ROTL64(st[13], 25);
74 st[13] =
ROTL64(st[19], 8);
75 st[19] =
ROTL64(st[23], 56);
76 st[23] =
ROTL64(st[15], 41);
77 st[15] =
ROTL64(st[ 4], 27);
78 st[ 4] =
ROTL64(st[24], 14);
79 st[24] =
ROTL64(st[21], 2);
80 st[21] =
ROTL64(st[ 8], 55);
81 st[ 8] =
ROTL64(st[16], 45);
82 st[16] =
ROTL64(st[ 5], 36);
83 st[ 5] =
ROTL64(st[ 3], 28);
84 st[ 3] =
ROTL64(st[18], 21);
85 st[18] =
ROTL64(st[17], 15);
86 st[17] =
ROTL64(st[11], 10);
87 st[11] =
ROTL64(st[ 7], 6);
88 st[ 7] =
ROTL64(st[10], 3);
93 const uint64_t st0 = st[j ]; \
94 const uint64_t st1 = st[j + 1]; \
95 const uint64_t st2 = st[j + 2]; \
96 const uint64_t st3 = st[j + 3]; \
97 const uint64_t st4 = st[j + 4]; \
98 st[j ] ^= ~st1 & st2; \
99 st[j + 1] ^= ~st2 & st3; \
100 st[j + 2] ^= ~st3 & st4; \
101 st[j + 3] ^= ~st4 & st0; \
102 st[j + 4] ^= ~st0 & st1; \
123 size_t i, rsiz, rsizw;
125 static_assert(
HASH_DATA_AREA <=
sizeof(temp),
"Bad keccak preconditions");
126 if (mdlen <= 0 || (mdlen > 100 &&
sizeof(st) != (
size_t)mdlen))
134 memset(st, 0,
sizeof(st));
136 for ( ; inlen >= rsiz; inlen -= rsiz, in += rsiz) {
137 for (i = 0; i < rsizw; i++) {
139 memcpy(&ina, in + i * 8, 8);
146 if (inlen + 1 >=
sizeof(temp) || inlen > rsiz || rsiz - inlen + inlen + 1 >=
sizeof(temp) || rsiz == 0 || rsiz - 1 >=
sizeof(temp) || rsizw * 8 >
sizeof(temp))
154 memset(temp + inlen, 0, rsiz - inlen);
155 temp[rsiz - 1] |= 0x80;
157 for (i = 0; i < rsizw; i++)
162 if (((
size_t)mdlen %
sizeof(
uint64_t)) != 0)
174#define KECCAK_FINALIZED 0x80000000
175#define KECCAK_BLOCKLEN 136
176#define KECCAK_WORDS 17
177#define KECCAK_DIGESTSIZE 32
178#define KECCAK_PROCESS_BLOCK(st, block) { \
179 for (int i_ = 0; i_ < KECCAK_WORDS; i_++){ \
180 ((st))[i_] ^= swap64le(((block))[i_]); \
182 keccakf(st, KECCAK_ROUNDS); }
194 const size_t idx = ctx->
rest;
200 memcpy((
char*)ctx->
message + idx, in, (inlen < left ? inlen : left));
201 if (inlen < left)
return;
#define round(rm, y, x, k)
Definition aesb.c:52
void * memcpy(void *a, const void *b, size_t c)
Definition glibc_compat.cpp:16
@ HASH_DATA_AREA
Definition hash-ops.h:78
#define KECCAK_BLOCKLEN
Definition hmac-keccak.c:32
#define memcpy_swap64le
Definition int-util.h:291
#define swap64le
Definition int-util.h:287
uint64_t state_t[25]
Definition keccak.c:117
void keccak(const uint8_t *in, size_t inlen, uint8_t *md, int mdlen)
Definition keccak.c:119
void keccak_finish(KECCAK_CTX *ctx, uint8_t *md)
Definition keccak.c:221
void keccak1600(const uint8_t *in, size_t inlen, uint8_t *md)
Definition keccak.c:169
void keccak_update(KECCAK_CTX *ctx, const uint8_t *in, size_t inlen)
Definition keccak.c:189
#define KECCAK_FINALIZED
Definition keccak.c:174
const uint64_t keccakf_rndc[24]
Definition keccak.c:22
void keccakf(uint64_t st[25], int rounds)
Definition keccak.c:36
#define KECCAK_PROCESS_BLOCK(st, block)
Definition keccak.c:178
#define KECCAK_DIGESTSIZE
Definition keccak.c:177
static void local_abort(const char *msg)
Definition keccak.c:12
void keccak_init(KECCAK_CTX *ctx)
Definition keccak.c:185
#define ROTL64(x, y)
Definition keccak.h:15
#define KECCAK_ROUNDS
Definition keccak.h:11
unsigned char uint8_t
Definition stdint.h:124
unsigned __int64 uint64_t
Definition stdint.h:136
size_t rest
Definition keccak.h:26
uint64_t hash[25]
Definition keccak.h:22
uint64_t message[17]
Definition keccak.h:24