Kagome
Polkadot Runtime Engine in C++17
keccak.h
Go to the documentation of this file.
1 
6 #ifndef CORE_KECCAK_H
7 #define CORE_KECCAK_H
8 
9 #if defined(__cplusplus)
10 extern "C" {
11 #endif
12 
13 /* 'Words' here refers to uint64_t */
14 #define SHA3_KECCAK_SPONGE_WORDS \
15  (((1600) / 8 /*bits to byte*/) / sizeof(uint64_t))
16 typedef struct sha3_context_ {
17  uint64_t saved; /* the portion of the input message that we
18  * didn't consume yet */
19  union { /* Keccak's state */
20  uint64_t s[SHA3_KECCAK_SPONGE_WORDS];
21  uint8_t sb[SHA3_KECCAK_SPONGE_WORDS * 8];
22  };
23  unsigned byteIndex; /* 0..7--the next byte after the set one
24  * (starts from 0; 0--none are buffered) */
25  unsigned wordIndex; /* 0..24--the next word to integrate input
26  * (starts from 0) */
27  unsigned capacityWords; /* the double size of the hash output in
28  * words (e.g. 16 for Keccak 512) */
29 } sha3_context;
30 
32 
35 
36 /* For Init or Reset call these: */
37 sha3_return_t sha3_Init(void *priv, unsigned bitSize);
38 void keccakf(uint64_t s[25]);
39 
40 void sha3_Init256(void *priv);
41 void sha3_Init384(void *priv);
42 void sha3_Init512(void *priv);
43 
44 enum SHA3_FLAGS sha3_SetFlags(void *priv, enum SHA3_FLAGS);
45 
46 void sha3_Update(void *priv, void const *bufIn, size_t len);
47 
48 void const *sha3_Finalize(void *priv);
49 
50 /* Single-call hashing */
51 sha3_return_t sha3_HashBuffer(
52  unsigned bitSize, /* 256, 384, 512 */
53  enum SHA3_FLAGS flags, /* SHA3_FLAGS_NONE or SHA3_FLAGS_KECCAK */
54  const void *in,
55  unsigned inBytes,
56  void *out,
57  unsigned outBytes); /* up to bitSize/8; truncation OK */
58 
59 #if defined(__cplusplus)
60 }
61 #endif
62 
63 #endif
sha3_return_t sha3_Init(void *priv, unsigned bitSize)
Definition: keccak.c:114
unsigned byteIndex
Definition: keccak.h:23
void sha3_Init256(void *priv)
Definition: keccak.c:123
#define SHA3_KECCAK_SPONGE_WORDS
Definition: keccak.h:14
void keccakf(uint64_t s[25])
Definition: keccak.c:64
sha3_return_t sha3_HashBuffer(unsigned bitSize, enum SHA3_FLAGS flags, const void *in, unsigned inBytes, void *out, unsigned outBytes)
Definition: keccak.c:286
unsigned capacityWords
Definition: keccak.h:27
struct sha3_context_ sha3_context
enum SHA3_FLAGS sha3_SetFlags(void *priv, enum SHA3_FLAGS)
Definition: keccak.c:135
void sha3_Update(void *priv, void const *bufIn, size_t len)
Definition: keccak.c:142
enum SHA3_RETURN sha3_return_t
Definition: keccak.h:34
SHA3_FLAGS
Definition: keccak.h:31
SHA3_RETURN
Definition: keccak.h:33
unsigned wordIndex
Definition: keccak.h:25
uint64_t saved
Definition: keccak.h:17
void sha3_Init384(void *priv)
Definition: keccak.c:127
void sha3_Init512(void *priv)
Definition: keccak.c:131
void const * sha3_Finalize(void *priv)
Definition: keccak.c:232