/ external / libecc / src / examples / hash / md2.h
md2.h
 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  #ifndef __MD2_H__
12  #define __MD2_H__
13  
14  /* Include libec for useful types and macros */
15  #include <libecc/libec.h>
16  
17  #define MD2_STATE_SIZE   16
18  #define MD2_BLOCK_SIZE   16
19  #define MD2_DIGEST_SIZE  16
20  #define MD2_DIGEST_SIZE_BITS  128
21  
22  #define MD2_HASH_MAGIC ((word_t)(0x8432927137264770ULL))
23  #define MD2_HASH_CHECK_INITIALIZED(A, ret, err) \
24  	MUST_HAVE((((void *)(A)) != NULL) && ((A)->magic == MD2_HASH_MAGIC), ret, err)
25  
26  typedef struct {
27  	/* Number of bytes processed */
28  	u64 md2_total;
29  	/* Internal state */
30  	u8 md2_state[MD2_STATE_SIZE];
31  	/* Internal buffer to handle updates in a block */
32  	u8 md2_buffer[MD2_BLOCK_SIZE];
33  	/* Internal buffer to hold the checksum */
34  	u8 md2_checksum[MD2_BLOCK_SIZE];
35  	/* Initialization magic value */
36  	word_t magic;
37  } md2_context;
38  
39  
40  /* Init hash function. Returns 0 on success, -1 on error. */
41  ATTRIBUTE_WARN_UNUSED_RET int md2_init(md2_context *ctx);
42  
43  ATTRIBUTE_WARN_UNUSED_RET int md2_update(md2_context *ctx, const u8 *input, u32 ilen);
44  
45  /* Finalize. Returns 0 on success, -1 on error.*/
46  ATTRIBUTE_WARN_UNUSED_RET int md2_final(md2_context *ctx, u8 output[MD2_DIGEST_SIZE]);
47  
48  /*
49   * Scattered version performing init/update/finalize on a vector of buffers
50   * 'inputs' with the length of each buffer passed via 'ilens'. The function
51   * loops on pointers in 'inputs' until it finds a NULL pointer. The function
52   * returns 0 on success, -1 on error.
53   */
54  ATTRIBUTE_WARN_UNUSED_RET int md2_scattered(const u8 **inputs, const u32 *ilens,
55  		      u8 output[MD2_DIGEST_SIZE]);
56  
57  /*
58   * Single call version performing init/update/final on given input.
59   * Returns 0 on success, -1 on error.
60   */
61  ATTRIBUTE_WARN_UNUSED_RET int md2(const u8 *input, u32 ilen, u8 output[MD2_DIGEST_SIZE]);
62  
63  #endif /* __MD2_H__ */