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