1 /* 2 * Copyright (C) 2017 - This file is part of libecc project 3 * 4 * Authors: 5 * Ryad BENADJILA <ryadbenadjila@gmail.com> 6 * Arnaud EBALARD <arnaud.ebalard@ssi.gouv.fr> 7 * Jean-Pierre FLORI <jean-pierre.flori@ssi.gouv.fr> 8 * 9 * Contributors: 10 * Nicolas VIVET <nicolas.vivet@ssi.gouv.fr> 11 * Karim KHALFALLAH <karim.khalfallah@ssi.gouv.fr> 12 * 13 * This software is licensed under a dual BSD and GPL v2 license. 14 * See LICENSE file at the root folder of the project. 15 */ 16 #ifndef __SHA3_H__ 17 #define __SHA3_H__ 18 19 #include <libecc/hash/keccak.h> 20 21 typedef enum { 22 SHA3_LITTLE = 0, 23 SHA3_BIG = 1, 24 } sha3_endianness; 25 /* 26 * Generic context for all SHA3 instances. Only difference is digest size 27 * value, initialized in init() call and used in finalize(). 28 */ 29 typedef struct sha3_context_ { 30 u8 sha3_digest_size; 31 u8 sha3_block_size; 32 sha3_endianness sha3_endian; 33 /* Local index, useful for the absorbing phase */ 34 u64 sha3_idx; 35 /* Keccak's state, viewed as a bi-dimensional array */ 36 u64 sha3_state[KECCAK_SLICES * KECCAK_SLICES]; 37 /* Initialization magic value */ 38 word_t magic; 39 } sha3_context; 40 41 42 ATTRIBUTE_WARN_UNUSED_RET int _sha3_init(sha3_context *ctx, u8 digest_size); 43 ATTRIBUTE_WARN_UNUSED_RET int _sha3_update(sha3_context *ctx, const u8 *buf, u32 buflen); 44 ATTRIBUTE_WARN_UNUSED_RET int _sha3_finalize(sha3_context *ctx, u8 *output); 45 46 #endif /* __SHA3_H__ */ 47