1*f0865ec9SKyle Evans /* 2*f0865ec9SKyle Evans * Copyright (C) 2021 - This file is part of libecc project 3*f0865ec9SKyle Evans * 4*f0865ec9SKyle Evans * Authors: 5*f0865ec9SKyle Evans * Ryad BENADJILA <ryadbenadjila@gmail.com> 6*f0865ec9SKyle Evans * Arnaud EBALARD <arnaud.ebalard@ssi.gouv.fr> 7*f0865ec9SKyle Evans * 8*f0865ec9SKyle Evans * This software is licensed under a dual BSD and GPL v2 license. 9*f0865ec9SKyle Evans * See LICENSE file at the root folder of the project. 10*f0865ec9SKyle Evans */ 11*f0865ec9SKyle Evans #ifndef __HASH_HASH_H__ 12*f0865ec9SKyle Evans #define __HASH_HASH_H__ 13*f0865ec9SKyle Evans 14*f0865ec9SKyle Evans 15*f0865ec9SKyle Evans /* 16*f0865ec9SKyle Evans * NOTE: we include libsig for the libecc 17*f0865ec9SKyle Evans * hash algorithms. 18*f0865ec9SKyle Evans */ 19*f0865ec9SKyle Evans #include <libecc/libec.h> 20*f0865ec9SKyle Evans 21*f0865ec9SKyle Evans /* MD-2 */ 22*f0865ec9SKyle Evans #include "md2.h" 23*f0865ec9SKyle Evans /* MD-4 */ 24*f0865ec9SKyle Evans #include "md4.h" 25*f0865ec9SKyle Evans /* MD-5 */ 26*f0865ec9SKyle Evans #include "md5.h" 27*f0865ec9SKyle Evans /* SHA-0 */ 28*f0865ec9SKyle Evans #include "sha0.h" 29*f0865ec9SKyle Evans /* SHA-1 */ 30*f0865ec9SKyle Evans #include "sha1.h" 31*f0865ec9SKyle Evans /* MDC-2 */ 32*f0865ec9SKyle Evans #include "mdc2.h" 33*f0865ec9SKyle Evans /* GOSTR34-11-94 source code */ 34*f0865ec9SKyle Evans #include "gostr34_11_94.h" 35*f0865ec9SKyle Evans 36*f0865ec9SKyle Evans /****************************************************/ 37*f0865ec9SKyle Evans /****************************************************/ 38*f0865ec9SKyle Evans /****************************************************/ 39*f0865ec9SKyle Evans typedef enum { 40*f0865ec9SKyle Evans /* libecc native hashes: we map our enum on them */ 41*f0865ec9SKyle Evans HASH_UNKNOWN_HASH_ALG = UNKNOWN_HASH_ALG, 42*f0865ec9SKyle Evans HASH_SHA224 = SHA224, 43*f0865ec9SKyle Evans HASH_SHA256 = SHA256, 44*f0865ec9SKyle Evans HASH_SHA384 = SHA384, 45*f0865ec9SKyle Evans HASH_SHA512 = SHA512, 46*f0865ec9SKyle Evans HASH_SHA512_224 = SHA512_224, 47*f0865ec9SKyle Evans HASH_SHA512_256 = SHA512_256, 48*f0865ec9SKyle Evans HASH_SHA3_224 = SHA3_224, 49*f0865ec9SKyle Evans HASH_SHA3_256 = SHA3_256, 50*f0865ec9SKyle Evans HASH_SHA3_384 = SHA3_384, 51*f0865ec9SKyle Evans HASH_SHA3_512 = SHA3_512, 52*f0865ec9SKyle Evans HASH_SM3 = SM3, 53*f0865ec9SKyle Evans HASH_STREEBOG256 = STREEBOG256, 54*f0865ec9SKyle Evans HASH_STREEBOG512 = STREEBOG512, 55*f0865ec9SKyle Evans HASH_SHAKE256 = SHAKE256, 56*f0865ec9SKyle Evans HASH_RIPEMD160 = RIPEMD160, 57*f0865ec9SKyle Evans HASH_BELT_HASH = BELT_HASH, 58*f0865ec9SKyle Evans HASH_BASH224 = BASH224, 59*f0865ec9SKyle Evans HASH_BASH256 = BASH256, 60*f0865ec9SKyle Evans HASH_BASH384 = BASH384, 61*f0865ec9SKyle Evans HASH_BASH512 = BASH512, 62*f0865ec9SKyle Evans /* Deprecated hash algorithms not supported by libecc 63*f0865ec9SKyle Evans * (for security reasons). 64*f0865ec9SKyle Evans * XXX: NOTE: These algorithms are here as a playground e.g. 65*f0865ec9SKyle Evans * to test some backward compatibility of cryptographic cipher suites, 66*f0865ec9SKyle Evans * please DO NOT use them in production code! 67*f0865ec9SKyle Evans */ 68*f0865ec9SKyle Evans HASH_MD2, 69*f0865ec9SKyle Evans HASH_MD4, 70*f0865ec9SKyle Evans HASH_MD5, 71*f0865ec9SKyle Evans HASH_SHA0, 72*f0865ec9SKyle Evans HASH_SHA1, 73*f0865ec9SKyle Evans HASH_MDC2_PADDING1, 74*f0865ec9SKyle Evans HASH_MDC2_PADDING2, 75*f0865ec9SKyle Evans HASH_GOST34_11_94_NORM, 76*f0865ec9SKyle Evans HASH_GOST34_11_94_RFC4357, 77*f0865ec9SKyle Evans } gen_hash_alg_type; 78*f0865ec9SKyle Evans 79*f0865ec9SKyle Evans /* Our generic hash context */ 80*f0865ec9SKyle Evans typedef union { 81*f0865ec9SKyle Evans /* libecc native hashes */ 82*f0865ec9SKyle Evans hash_context hctx; 83*f0865ec9SKyle Evans /* MD2 */ 84*f0865ec9SKyle Evans md2_context md2ctx; 85*f0865ec9SKyle Evans /* MD4 */ 86*f0865ec9SKyle Evans md4_context md4ctx; 87*f0865ec9SKyle Evans /* MD5 */ 88*f0865ec9SKyle Evans md5_context md5ctx; 89*f0865ec9SKyle Evans /* SHA-0 */ 90*f0865ec9SKyle Evans sha0_context sha0ctx; 91*f0865ec9SKyle Evans /* SHA-1 */ 92*f0865ec9SKyle Evans sha1_context sha1ctx; 93*f0865ec9SKyle Evans /* MDC2 */ 94*f0865ec9SKyle Evans mdc2_context mdc2ctx; 95*f0865ec9SKyle Evans /* GOSTR34-11-94 */ 96*f0865ec9SKyle Evans gostr34_11_94_context gostr34_11_94ctx; 97*f0865ec9SKyle Evans } gen_hash_context; 98*f0865ec9SKyle Evans 99*f0865ec9SKyle Evans ATTRIBUTE_WARN_UNUSED_RET int gen_hash_get_hash_sizes(gen_hash_alg_type gen_hash_type, u8 *hlen, u8 *block_size); 100*f0865ec9SKyle Evans ATTRIBUTE_WARN_UNUSED_RET int gen_hash_init(gen_hash_context *ctx, gen_hash_alg_type gen_hash_type); 101*f0865ec9SKyle Evans ATTRIBUTE_WARN_UNUSED_RET int gen_hash_update(gen_hash_context *ctx, const u8 *chunk, u32 chunklen, gen_hash_alg_type gen_hash_type); 102*f0865ec9SKyle Evans ATTRIBUTE_WARN_UNUSED_RET int gen_hash_final(gen_hash_context *ctx, u8 *output, gen_hash_alg_type gen_hash_type); 103*f0865ec9SKyle Evans ATTRIBUTE_WARN_UNUSED_RET int gen_hash_hfunc(const u8 *input, u32 ilen, u8 *digest, gen_hash_alg_type gen_hash_type); 104*f0865ec9SKyle Evans ATTRIBUTE_WARN_UNUSED_RET int gen_hash_hfunc_scattered(const u8 **input, const u32 *ilen, u8 *digest, gen_hash_alg_type gen_hash_type); 105*f0865ec9SKyle Evans 106*f0865ec9SKyle Evans #endif /* __HASH_HASH_H__ */ 107