summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/sha/sha3_internal.h
diff options
context:
space:
mode:
authorjsing <>2023-04-15 17:56:35 +0000
committerjsing <>2023-04-15 17:56:35 +0000
commit544e86ca593b5cf7552875599cd3e1d2581eeab0 (patch)
treeda1c7b16380eb3bb690343f812a5da0b42bc18d4 /src/lib/libcrypto/sha/sha3_internal.h
parent3e1ff76458200d603d89c1acf7741c1c31497902 (diff)
downloadopenbsd-544e86ca593b5cf7552875599cd3e1d2581eeab0.tar.gz
openbsd-544e86ca593b5cf7552875599cd3e1d2581eeab0.tar.bz2
openbsd-544e86ca593b5cf7552875599cd3e1d2581eeab0.zip
Import tiny_sha3
This is a minimal and readable SHA3 implementation. ok tb@
Diffstat (limited to 'src/lib/libcrypto/sha/sha3_internal.h')
-rw-r--r--src/lib/libcrypto/sha/sha3_internal.h47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/lib/libcrypto/sha/sha3_internal.h b/src/lib/libcrypto/sha/sha3_internal.h
new file mode 100644
index 0000000000..ba24f43478
--- /dev/null
+++ b/src/lib/libcrypto/sha/sha3_internal.h
@@ -0,0 +1,47 @@
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
19typedef 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.
28void sha3_keccakf(uint64_t st[25]);
29
30// OpenSSL - like interfece
31int sha3_init(sha3_ctx_t *c, int mdlen); // mdlen = hash output in bytes
32int sha3_update(sha3_ctx_t *c, const void *data, size_t len);
33int 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"
36void *sha3(const void *in, size_t inlen, void *md, int mdlen);
37
38// SHAKE128 and SHAKE256 extensible-output functions
39#define shake128_init(c) sha3_init(c, 16)
40#define shake256_init(c) sha3_init(c, 32)
41#define shake_update sha3_update
42
43void shake_xof(sha3_ctx_t *c);
44void shake_out(sha3_ctx_t *c, void *out, size_t len);
45
46#endif
47