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