This repository has been archived by the owner on Jan 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathmd2.h
63 lines (52 loc) · 1.99 KB
/
md2.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* Copyright (C) 2021 - This file is part of libecc project
*
* Authors:
* Ryad BENADJILA <[email protected]>
* Arnaud EBALARD <[email protected]>
*
* This software is licensed under a dual BSD and GPL v2 license.
* See LICENSE file at the root folder of the project.
*/
#ifndef __MD2_H__
#define __MD2_H__
/* Include libec for useful types and macros */
#include "libec.h"
#define MD2_STATE_SIZE 16
#define MD2_BLOCK_SIZE 16
#define MD2_DIGEST_SIZE 16
#define MD2_DIGEST_SIZE_BITS 128
#define MD2_HASH_MAGIC ((word_t)(0x8432927137264770ULL))
#define MD2_HASH_CHECK_INITIALIZED(A, ret, err) \
MUST_HAVE((((void *)(A)) != NULL) && ((A)->magic == MD2_HASH_MAGIC), ret, err)
typedef struct {
/* Number of bytes processed */
u64 md2_total;
/* Internal state */
u8 md2_state[MD2_STATE_SIZE];
/* Internal buffer to handle updates in a block */
u8 md2_buffer[MD2_BLOCK_SIZE];
/* Internal buffer to hold the checksum */
u8 md2_checksum[MD2_BLOCK_SIZE];
/* Initialization magic value */
word_t magic;
} md2_context;
/* Init hash function. Returns 0 on success, -1 on error. */
ATTRIBUTE_WARN_UNUSED_RET int md2_init(md2_context *ctx);
ATTRIBUTE_WARN_UNUSED_RET int md2_update(md2_context *ctx, const u8 *input, u32 ilen);
/* Finalize. Returns 0 on success, -1 on error.*/
ATTRIBUTE_WARN_UNUSED_RET int md2_final(md2_context *ctx, u8 output[MD2_DIGEST_SIZE]);
/*
* Scattered version performing init/update/finalize on a vector of buffers
* 'inputs' with the length of each buffer passed via 'ilens'. The function
* loops on pointers in 'inputs' until it finds a NULL pointer. The function
* returns 0 on success, -1 on error.
*/
ATTRIBUTE_WARN_UNUSED_RET int md2_scattered(const u8 **inputs, const u32 *ilens,
u8 output[MD2_DIGEST_SIZE]);
/*
* Single call version performing init/update/final on given input.
* Returns 0 on success, -1 on error.
*/
ATTRIBUTE_WARN_UNUSED_RET int md2(const u8 *input, u32 ilen, u8 output[MD2_DIGEST_SIZE]);
#endif /* __MD2_H__ */