Path: blob/main/crypto/libecc/src/examples/hash/md2.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 __MD2_H__11#define __MD2_H__1213/* Include libec for useful types and macros */14#include <libecc/libec.h>1516#define MD2_STATE_SIZE 1617#define MD2_BLOCK_SIZE 1618#define MD2_DIGEST_SIZE 1619#define MD2_DIGEST_SIZE_BITS 1282021#define MD2_HASH_MAGIC ((word_t)(0x8432927137264770ULL))22#define MD2_HASH_CHECK_INITIALIZED(A, ret, err) \23MUST_HAVE((((void *)(A)) != NULL) && ((A)->magic == MD2_HASH_MAGIC), ret, err)2425typedef struct {26/* Number of bytes processed */27u64 md2_total;28/* Internal state */29u8 md2_state[MD2_STATE_SIZE];30/* Internal buffer to handle updates in a block */31u8 md2_buffer[MD2_BLOCK_SIZE];32/* Internal buffer to hold the checksum */33u8 md2_checksum[MD2_BLOCK_SIZE];34/* Initialization magic value */35word_t magic;36} md2_context;373839/* Init hash function. Returns 0 on success, -1 on error. */40ATTRIBUTE_WARN_UNUSED_RET int md2_init(md2_context *ctx);4142ATTRIBUTE_WARN_UNUSED_RET int md2_update(md2_context *ctx, const u8 *input, u32 ilen);4344/* Finalize. Returns 0 on success, -1 on error.*/45ATTRIBUTE_WARN_UNUSED_RET int md2_final(md2_context *ctx, u8 output[MD2_DIGEST_SIZE]);4647/*48* Scattered version performing init/update/finalize on a vector of buffers49* 'inputs' with the length of each buffer passed via 'ilens'. The function50* loops on pointers in 'inputs' until it finds a NULL pointer. The function51* returns 0 on success, -1 on error.52*/53ATTRIBUTE_WARN_UNUSED_RET int md2_scattered(const u8 **inputs, const u32 *ilens,54u8 output[MD2_DIGEST_SIZE]);5556/*57* Single call version performing init/update/final on given input.58* Returns 0 on success, -1 on error.59*/60ATTRIBUTE_WARN_UNUSED_RET int md2(const u8 *input, u32 ilen, u8 output[MD2_DIGEST_SIZE]);6162#endif /* __MD2_H__ */636465