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 #include <libecc/lib_ecc_config.h> 17 #ifdef WITH_HASH_SHA224 18 19 #ifndef __SHA224_H__ 20 #define __SHA224_H__ 21 22 #include <libecc/words/words.h> 23 #include <libecc/utils/utils.h> 24 #include <libecc/hash/sha2.h> 25 26 #define SHA224_STATE_SIZE 8 27 #define SHA224_BLOCK_SIZE 64 28 #define SHA224_DIGEST_SIZE 28 29 #define SHA224_DIGEST_SIZE_BITS 224 30 31 /* Compute max hash digest and block sizes */ 32 #ifndef MAX_DIGEST_SIZE 33 #define MAX_DIGEST_SIZE 0 34 #endif 35 #if (MAX_DIGEST_SIZE < SHA224_DIGEST_SIZE) 36 #undef MAX_DIGEST_SIZE 37 #define MAX_DIGEST_SIZE SHA224_DIGEST_SIZE 38 #endif 39 40 #ifndef MAX_DIGEST_SIZE_BITS 41 #define MAX_DIGEST_SIZE_BITS 0 42 #endif 43 #if (MAX_DIGEST_SIZE_BITS < SHA224_DIGEST_SIZE_BITS) 44 #undef MAX_DIGEST_SIZE_BITS 45 #define MAX_DIGEST_SIZE_BITS SHA224_DIGEST_SIZE_BITS 46 #endif 47 48 #ifndef MAX_BLOCK_SIZE 49 #define MAX_BLOCK_SIZE 0 50 #endif 51 #if (MAX_BLOCK_SIZE < SHA224_BLOCK_SIZE) 52 #undef MAX_BLOCK_SIZE 53 #define MAX_BLOCK_SIZE SHA224_BLOCK_SIZE 54 #endif 55 56 #define SHA224_HASH_MAGIC ((word_t)(0x1120323b32342910ULL)) 57 #define SHA224_HASH_CHECK_INITIALIZED(A, ret, err) \ 58 MUST_HAVE((((void *)(A)) != NULL) && ((A)->magic == SHA224_HASH_MAGIC), ret, err) 59 60 typedef struct { 61 /* Number of bytes processed */ 62 u64 sha224_total; 63 /* Internal state */ 64 u32 sha224_state[SHA224_STATE_SIZE]; 65 /* Internal buffer to handle updates in a block */ 66 u8 sha224_buffer[SHA224_BLOCK_SIZE]; 67 /* Initialization magic value */ 68 word_t magic; 69 } sha224_context; 70 71 ATTRIBUTE_WARN_UNUSED_RET int sha224_init(sha224_context *ctx); 72 ATTRIBUTE_WARN_UNUSED_RET int sha224_update(sha224_context *ctx, const u8 *input, u32 ilen); 73 ATTRIBUTE_WARN_UNUSED_RET int sha224_final(sha224_context *ctx, u8 output[SHA224_DIGEST_SIZE]); 74 ATTRIBUTE_WARN_UNUSED_RET int sha224_scattered(const u8 **inputs, const u32 *ilens, 75 u8 output[SHA224_DIGEST_SIZE]); 76 ATTRIBUTE_WARN_UNUSED_RET int sha224(const u8 *input, u32 ilen, u8 output[SHA224_DIGEST_SIZE]); 77 78 #endif /* __SHA224_H__ */ 79 #endif /* WITH_HASH_SHA224 */ 80