1 /* Copyright (c) 2023, Google Inc. 2 * 3 * Permission to use, copy, modify, and/or distribute this software for any 4 * purpose with or without fee is hereby granted, provided that the above 5 * copyright notice and this permission notice appear in all copies. 6 * 7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 10 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ 14 15 #ifndef OPENSSL_HEADER_CRYPTO_KECCAK_INTERNAL_H 16 #define OPENSSL_HEADER_CRYPTO_KECCAK_INTERNAL_H 17 18 #include <openssl/base.h> 19 20 #if defined(__cplusplus) 21 extern "C" { 22 #endif 23 24 25 enum boringssl_keccak_config_t { 26 boringssl_sha3_256, 27 boringssl_sha3_512, 28 boringssl_shake128, 29 boringssl_shake256, 30 }; 31 32 enum boringssl_keccak_phase_t { 33 boringssl_keccak_phase_absorb, 34 boringssl_keccak_phase_squeeze, 35 }; 36 37 struct BORINGSSL_keccak_st { 38 enum boringssl_keccak_config_t config; 39 enum boringssl_keccak_phase_t phase; 40 uint64_t state[25]; 41 size_t rate_bytes; 42 size_t absorb_offset; 43 size_t squeeze_offset; 44 }; 45 46 // BORINGSSL_keccak hashes |in_len| bytes from |in| and writes |out_len| bytes 47 // of output to |out|. If the |config| specifies a fixed-output function, like 48 // SHA3-256, then |out_len| must be the correct length for that function. 49 OPENSSL_EXPORT void BORINGSSL_keccak(uint8_t *out, size_t out_len, 50 const uint8_t *in, size_t in_len, 51 enum boringssl_keccak_config_t config); 52 53 // BORINGSSL_keccak_init prepares |ctx| for absorbing. The |config| must specify 54 // a SHAKE variant, otherwise callers should use |BORINGSSL_keccak|. 55 OPENSSL_EXPORT void BORINGSSL_keccak_init( 56 struct BORINGSSL_keccak_st *ctx, enum boringssl_keccak_config_t config); 57 58 // BORINGSSL_keccak_absorb absorbs |in_len| bytes from |in|. 59 OPENSSL_EXPORT void BORINGSSL_keccak_absorb(struct BORINGSSL_keccak_st *ctx, 60 const uint8_t *in, size_t in_len); 61 62 // BORINGSSL_keccak_squeeze writes |out_len| bytes to |out| from |ctx|. 63 OPENSSL_EXPORT void BORINGSSL_keccak_squeeze(struct BORINGSSL_keccak_st *ctx, 64 uint8_t *out, size_t out_len); 65 66 #if defined(__cplusplus) 67 } 68 #endif 69 70 #endif // OPENSSL_HEADER_CRYPTO_KECCAK_INTERNAL_H 71