1 /* 2 * Copyright (C) 2021 - 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 * 8 * This software is licensed under a dual BSD and GPL v2 license. 9 * See LICENSE file at the root folder of the project. 10 */ 11 #include <libecc/lib_ecc_config.h> 12 #ifdef WITH_HASH_STREEBOG512 13 14 #ifndef __STREEBOG512_H__ 15 #define __STREEBOG512_H__ 16 17 #include <libecc/words/words.h> 18 #include <libecc/utils/utils.h> 19 #include <libecc/hash/streebog.h> 20 21 #define STREEBOG512_BLOCK_SIZE STREEBOG_BLOCK_SIZE 22 #define STREEBOG512_DIGEST_SIZE 64 23 #define STREEBOG512_DIGEST_SIZE_BITS 512 24 25 /* Compute max hash digest and block sizes */ 26 #ifndef MAX_DIGEST_SIZE 27 #define MAX_DIGEST_SIZE 0 28 #endif 29 #if (MAX_DIGEST_SIZE < STREEBOG512_DIGEST_SIZE) 30 #undef MAX_DIGEST_SIZE 31 #define MAX_DIGEST_SIZE STREEBOG512_DIGEST_SIZE 32 #endif 33 34 #ifndef MAX_DIGEST_SIZE_BITS 35 #define MAX_DIGEST_SIZE_BITS 0 36 #endif 37 #if (MAX_DIGEST_SIZE_BITS < STREEBOG512_DIGEST_SIZE_BITS) 38 #undef MAX_DIGEST_SIZE_BITS 39 #define MAX_DIGEST_SIZE_BITS STREEBOG512_DIGEST_SIZE_BITS 40 #endif 41 42 #ifndef MAX_BLOCK_SIZE 43 #define MAX_BLOCK_SIZE 0 44 #endif 45 #if (MAX_BLOCK_SIZE < STREEBOG512_BLOCK_SIZE) 46 #undef MAX_BLOCK_SIZE 47 #define MAX_BLOCK_SIZE STREEBOG512_BLOCK_SIZE 48 #endif 49 50 #define STREEBOG512_HASH_MAGIC ((word_t)(0x3293187509128364ULL)) 51 #define STREEBOG512_HASH_CHECK_INITIALIZED(A, ret, err) \ 52 MUST_HAVE((((void *)(A)) != NULL) && ((A)->magic == STREEBOG512_HASH_MAGIC) && \ 53 ((A)->streebog_digest_size == STREEBOG512_DIGEST_SIZE) && ((A)->streebog_block_size == STREEBOG512_BLOCK_SIZE), ret, err) 54 55 typedef streebog_context streebog512_context; 56 57 ATTRIBUTE_WARN_UNUSED_RET int streebog512_init(streebog512_context *ctx); 58 ATTRIBUTE_WARN_UNUSED_RET int streebog512_update(streebog512_context *ctx, const u8 *input, u32 ilen); 59 ATTRIBUTE_WARN_UNUSED_RET int streebog512_final(streebog512_context *ctx, u8 output[STREEBOG512_DIGEST_SIZE]); 60 ATTRIBUTE_WARN_UNUSED_RET int streebog512_scattered(const u8 **inputs, const u32 *ilens, 61 u8 output[STREEBOG512_DIGEST_SIZE]); 62 ATTRIBUTE_WARN_UNUSED_RET int streebog512(const u8 *input, u32 ilen, u8 output[STREEBOG512_DIGEST_SIZE]); 63 64 #endif /* __STREEBOG512_H__ */ 65 #endif /* WITH_HASH_STREEBOG512 */ 66