1 // sha3.h
2 // 19-Nov-11 Markku-Juhani O. Saarinen <mjos@iki.fi>
3
4 #ifndef SHA3_H
5 #define SHA3_H
6
7 #include <stddef.h>
8 #include <stdint.h>
9
10 #ifndef KECCAKF_ROUNDS
11 #define KECCAKF_ROUNDS 24
12 #endif
13
14 #ifndef ROTL64
15 #define ROTL64(x, y) (((x) << (y)) | ((x) >> (64 - (y))))
16 #endif
17
18 // state context
19 typedef struct {
20 union { // state:
21 uint8_t b[200]; // 8-bit bytes
22 uint64_t q[25]; // 64-bit words
23 } st;
24 int pt, rsiz, mdlen; // these don't overflow
25 } sha3_ctx_t;
26
27 // Compression function.
28 static void sha3_keccakf(uint64_t st[25]);
29
30 // OpenSSL - like interfece
31 static int sha3_init(sha3_ctx_t *c, int mdlen); // mdlen = hash output in bytes
32 static int sha3_update(sha3_ctx_t *c, const void *data, size_t len);
33 static int sha3_final(void *md, sha3_ctx_t *c); // digest goes to md
34
35 // compute a sha3 hash (md) of given byte length from "in"
36 #if 0
37 static void *sha3(const void *in, size_t inlen, void *md, int mdlen);
38 #endif
39
40 // SHAKE128 and SHAKE256 extensible-output functions
41 #define shake128_init(c) sha3_init(c, 16)
42 #define shake256_init(c) sha3_init(c, 32)
43 #define shake_update sha3_update
44
45 static void shake_xof(sha3_ctx_t *c);
46 static void shake_out(sha3_ctx_t *c, void *out, size_t len);
47
48 #endif
49