blob: 19021122719177a99fb9d4696d2130ccf5221ad2 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001#ifndef _ASR_HASH_H_
2#define _ASR_HASH_H_
3
4#define ROUND_UP_TO_WORD_CNT(x) ((x + 0x3) >> 2)
5#define HASH_ALIGN_BUF_SIZE 4096
6#define BLOCK_ALGIN_SIZE 64
7
8typedef enum {
9 HASH_INIT = 0x1,
10 HASH_UPDATE = 0x2,
11 HASH_FINAL = 0x3,
12} HASH_OP_MODE_T;
13
14typedef enum {
15 HASH_LEN_SHA1 = 20,
16 HASH_LEN_SHA256 = 32,
17 HASH_LEN_SHA224 = 28,
18 HASH_LEN_MD5 = 16,
19 HASH_LEN_SHA512 = 64,
20 HASH_LEN_SHA384 = 48,
21} HASH_LEN_T;
22
23typedef enum {
24 HASH_SIMPLE = 0,
25 HASH_HMAC,
26} HASH_MODE_T;
27
28typedef enum {
29 HASH_SHA1 = 0x0,
30 HASH_SHA256 = 0x1,
31 HASH_SHA224 = 0X2,
32 HASH_MD5 = 0x3,
33 HASH_SHA512 = 0x4,
34 HASH_SHA384 = 0X5,
35} HASH_ALGO_T;
36
37struct sha512_state {
38 unsigned int state[16];
39};
40
41struct sha256_state {
42 unsigned int state[8];
43};
44
45struct sha1_state {
46 unsigned int state[5];
47};
48
49struct md5_state {
50 unsigned int state[4];
51};
52
53typedef struct {
54 uint64_t length;
55 unsigned int curlen;
56 unsigned char buf[BLOCK_ALGIN_SIZE] __attribute__((aligned(4)));
57 uint32_t block_size;
58
59 struct sha512_state sha512;
60 struct sha256_state sha256;
61 struct sha1_state sha1;
62 struct md5_state md5;
63} hash_state;
64
65#endif