-
-
Notifications
You must be signed in to change notification settings - Fork 286
/
sha3.h
43 lines (34 loc) · 1.2 KB
/
sha3.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* Canonical implementation of Init/Update/Finalize for SHA-3 byte input.
* Based on code from https://github.com/brainhub/SHA3IUF/
*
* This work is released into the public domain with CC0 1.0.
*
* Copyright (c) 2015. Andrey Jivsov <crypto@brainhub.org>
* Copyright (c) 2023 Tino Reichardt <milky-7zip@mcmilk.de>
*/
#ifndef SHA3_H
#define SHA3_H
#include <stdint.h>
#define SHA3_256_DIGEST_LENGTH 32
#define SHA3_384_DIGEST_LENGTH 48
#define SHA3_512_DIGEST_LENGTH 64
/* 'Words' here refers to uint64_t */
#define SHA3_KECCAK_SPONGE_WORDS (200 / sizeof(uint64_t))
typedef struct sha3_context_ {
/* the portion of the input message that we didn't consume yet */
uint64_t saved;
uint64_t byteIndex; /* 0..7--the next byte after the set one */
uint64_t wordIndex; /* 0..24--the next word to integrate input */
uint64_t capacityWords; /* the double size of the hash output in words */
/* Keccak's state */
union {
uint64_t s[SHA3_KECCAK_SPONGE_WORDS];
uint8_t sb[SHA3_KECCAK_SPONGE_WORDS * 8];
} u;
unsigned digest_length;
} SHA3_CTX;
void SHA3_Init(SHA3_CTX * ctx, unsigned bitSize);
void SHA3_Update(SHA3_CTX * ctx, void const *bufIn, size_t len);
void SHA3_Final(void *, SHA3_CTX * ctx);
#endif