1 /* $OpenBSD: sha3_internal.h,v 1.6 2023/04/15 18:29:26 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 #include <stddef.h> 27 #include <stdint.h> 28 29 #ifndef HEADER_SHA3_INTERNAL_H 30 #define HEADER_SHA3_INTERNAL_H 31 32 typedef struct { 33 union { 34 uint8_t b[200]; /* State as 8 bit bytes. */ 35 uint64_t q[25]; /* State as 64 bit words. */ 36 } st; 37 int pt, rsiz, mdlen; 38 } sha3_ctx_t; 39 40 void sha3_keccakf(uint64_t st[25]); 41 42 int sha3_init(sha3_ctx_t *c, int mdlen); 43 int sha3_update(sha3_ctx_t *c, const void *data, size_t len); 44 int sha3_final(void *md, sha3_ctx_t *c); 45 46 void *sha3(const void *in, size_t inlen, void *md, int mdlen); 47 48 /* SHAKE128 and SHAKE256 extensible-output functions. */ 49 #define shake128_init(c) sha3_init(c, 16) 50 #define shake256_init(c) sha3_init(c, 32) 51 #define shake_update sha3_update 52 53 void shake_xof(sha3_ctx_t *c); 54 void shake_out(sha3_ctx_t *c, void *out, size_t len); 55 56 #endif 57