xref: /openbsd-src/lib/libcrypto/sha/sha3_internal.h (revision e967e4e7ab8d009ee5de60ff7bf94e6754fdd150)
1 /*	$OpenBSD: sha3_internal.h,v 1.4 2023/04/15 18:14:21 jsing Exp $	*/
2 /*
3  * The MIT License (MIT)
4  *
5  * Copyright (c) 2015 Markku-Juhani O. Saarinen
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy
8  * of this software and associated documentation files (the "Software"), to deal
9  * in the Software without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in all
15  * copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24  */
25 
26 #ifndef SHA3_H
27 #define SHA3_H
28 
29 #include <stddef.h>
30 #include <stdint.h>
31 
32 #ifndef KECCAKF_ROUNDS
33 #define KECCAKF_ROUNDS 24
34 #endif
35 
36 #ifndef ROTL64
37 #define ROTL64(x, y) (((x) << (y)) | ((x) >> (64 - (y))))
38 #endif
39 
40 typedef struct {
41 	union {
42 		uint8_t b[200];		/* State as 8 bit bytes. */
43 		uint64_t q[25];		/* State as 64 bit words. */
44 	} st;
45 	int pt, rsiz, mdlen;
46 } sha3_ctx_t;
47 
48 void sha3_keccakf(uint64_t st[25]);
49 
50 int sha3_init(sha3_ctx_t *c, int mdlen);
51 int sha3_update(sha3_ctx_t *c, const void *data, size_t len);
52 int sha3_final(void *md, sha3_ctx_t *c);
53 
54 void *sha3(const void *in, size_t inlen, void *md, int mdlen);
55 
56 /* SHAKE128 and SHAKE256 extensible-output functions. */
57 #define shake128_init(c) sha3_init(c, 16)
58 #define shake256_init(c) sha3_init(c, 32)
59 #define shake_update sha3_update
60 
61 void shake_xof(sha3_ctx_t *c);
62 void shake_out(sha3_ctx_t *c, void *out, size_t len);
63 
64 #endif
65