WS63 SDK 文档 7021f4f@fbb_ws63
ws63 和 ws63e 解决方案的 SDK 文档
载入中...
搜索中...
未找到
crypto_hash_struct.h
浏览该文件的文档.
1
9#ifndef CRYPTO_HASH_STRUCT_H
10#define CRYPTO_HASH_STRUCT_H
11
13
14/*
15 * Component of crypto_hash_type.
16 * is_hmac(4 bits) | alg(4 bits) | mode(4 bits) | max_message_length(4 bits) | block_size(4 bits) | result_size(12 bits)
17 * is_hmac: h'0 - hash
18 * h'1 - hmac
19 * alg: h'0 - sha1
20 * h'1 - sha2
21 * h'2 - sm3
22 * mode: h'0 - 224
23 * h'1 - 256
24 * h'2 - 384
25 * h'3 - 512
26 * max_message_length:
27 * h'6 - 2**6 -> 64, 最大消息 2**64 Bits. For SHA256.
28 * h'7 - 2**7 -> 128, 最大消息 2**128 Bits. For SHA384/SHA512.
29 * block_size:
30 * h'9 - 2**9 -> 512, Block Size 为 512 Bits. For SHA256.
31 * h'a - 2**10 -> 1024, Block Size 为 1024 Bits. For SHA384/SHA512.
32 * result_size:
33 * h'100 - 256, Result Size 为 256 Bits. For SHA256.
34 * h'180 - 384, Result Size 为 384 Bits. For SHA384.
35 * h'200 - 512, Result Size 为 512 Bits. For SHA512.
36 */
37#define compat_hash_type(is_hmac, alg, mode, max_message_length, block_size, result_size) \
38 ((((is_hmac) & 0xF) << 28) | (((alg) & 0xF) << 24) | (((mode) & 0xF) << 20) | \
39 (((max_message_length) & 0xF) << 16) | (((block_size) & 0xF) << 12) | ((result_size) & 0xFFF))
40
41#define CRYPTO_HASH_TYPE 0
42#define CRYPTO_HMAC_TYPE 1
43#define CRYPTO_IS_HMAC_MASK 0xF0000000
44#define CRYPTO_IS_HMAC_SHIFT 28
45
46#define CRYPTO_HASH_ALG_SHA1 0
47#define CRYPTO_HASH_ALG_SHA2 1
48#define CRYPTO_HASH_ALG_SM3 2
49#define CRYPTO_HASH_ALG_MASK 0x0F000000
50#define CRYPTO_HASH_ALG_SHIFT 24
51
52#define CRYPTO_HASH_MODE_224 0
53#define CRYPTO_HASH_MODE_256 1
54#define CRYPTO_HASH_MODE_384 2
55#define CRYPTO_HASH_MODE_512 3
56#define CRYPTO_HASH_MODE_UNDEF 0xf
57#define CRYPTO_HASH_MODE_MASK 0x00F00000
58#define CRYPTO_HASH_MODE_SHIFT 20
59
60#define CRYPTO_HASH_MAX_MESSAGE_LEN_64BIT 0x6
61#define CRYPTO_HASH_MAX_MESSAGE_LEN_128BIT 0x7
62#define CRYPTO_HASH_MAX_MESSAGE_LEN_MASK 0x000F0000
63#define CRYPTO_HASH_MAX_MESSAGE_LEN_SHIFT 16
64
65#define CRYPTO_HASH_BLOCK_SIZE_512BIT 0x9
66#define CRYPTO_HASH_BLOCK_SIZE_1024BIT 0xa
67#define CRYPTO_HASH_BLOCK_SIZE_MASK 0x0000F000
68#define CRYPTO_HASH_BLOCK_SIZE_SHIFT 12
69
70#define CRYPTO_HASH_RESULT_SIZE_160BIT 0xa0
71#define CRYPTO_HASH_RESULT_SIZE_224BIT 0xe0
72#define CRYPTO_HASH_RESULT_SIZE_256BIT 0x100
73#define CRYPTO_HASH_RESULT_SIZE_384BIT 0x180
74#define CRYPTO_HASH_RESULT_SIZE_512BIT 0x200
75#define CRYPTO_HASH_RESULT_SIZE_MASK 0x00000FFF
76#define CRYPTO_HASH_RESULT_SIZE_SHIFT 0
77
78#define CRYPTO_HASH_BLOCK_SIZE_20BYTE 0x14
79#define CRYPTO_HASH_BLOCK_SIZE_32BYTE 0x20
80#define CRYPTO_HASH_BLOCK_SIZE_64BYTE 0x40
81
82#define crypto_hash_get_attr(value, mask, shift) (((td_u32)(value) & (td_u32)(mask)) >> (shift))
83#define crypto_hash_macth(value, mask, target, shift) (crypto_hash_get_attr(value, mask, shift) == (target))
84
85#define crypto_hash_get_alg(hash_type) \
86 crypto_hash_get_attr(hash_type, CRYPTO_HASH_ALG_MASK, CRYPTO_HASH_ALG_SHIFT)
87#define crypto_hash_get_mode(hash_type) \
88 crypto_hash_get_attr(hash_type, CRYPTO_HASH_MODE_MASK, CRYPTO_HASH_MODE_SHIFT)
89#define crypto_hash_is_hmac(hash_type) \
90 crypto_hash_macth(hash_type, CRYPTO_IS_HMAC_MASK, CRYPTO_HMAC_TYPE, CRYPTO_IS_HMAC_SHIFT)
91#define crypto_hash_get_message_len(hash_type) \
92 (1 << crypto_hash_get_attr(hash_type, CRYPTO_HASH_MAX_MESSAGE_LEN_MASK, CRYPTO_HASH_MAX_MESSAGE_LEN_SHIFT))
93#define crypto_hash_get_block_size(hash_type) \
94 (1 << crypto_hash_get_attr(hash_type, CRYPTO_HASH_BLOCK_SIZE_MASK, CRYPTO_HASH_BLOCK_SIZE_SHIFT))
95#define crypto_hash_get_result_size(hash_type) \
96 crypto_hash_get_attr(hash_type, CRYPTO_HASH_RESULT_SIZE_MASK, CRYPTO_HASH_RESULT_SIZE_SHIFT)
97
98typedef enum {
99 /* Hash. */
103 ),
107 ),
111 ),
115 ),
119 ),
123 ),
124
125 /* HMAC. */
129 ),
133 ),
137 ),
141 ),
145 ),
149 ),
150
153
162
163/* Structure for HASH. */
164#define CRYPTO_HASH_RESULT_SIZE_MAX 64 // for SHA-512
165#define CRYPTO_HASH_RESULT_SIZE_MAX_IN_WORD 16 // for SHA-512
166#define CRYPTO_HASH_BLOCK_SIZE_MAX 128 // for SHA-512
167
179
187
195
205
206#endif
#define CRYPTO_HASH_RESULT_SIZE_512BIT
Definition crypto_hash_struct.h:74
#define CRYPTO_HASH_BLOCK_SIZE_512BIT
Definition crypto_hash_struct.h:65
#define CRYPTO_HMAC_TYPE
Definition crypto_hash_struct.h:42
#define CRYPTO_HASH_BLOCK_SIZE_1024BIT
Definition crypto_hash_struct.h:66
#define CRYPTO_HASH_RESULT_SIZE_384BIT
Definition crypto_hash_struct.h:73
#define CRYPTO_HASH_MODE_224
Definition crypto_hash_struct.h:52
#define CRYPTO_HASH_ALG_SM3
Definition crypto_hash_struct.h:48
#define CRYPTO_HASH_ALG_SHA1
Definition crypto_hash_struct.h:46
#define CRYPTO_HASH_MODE_512
Definition crypto_hash_struct.h:55
#define CRYPTO_HASH_RESULT_SIZE_MAX_IN_WORD
Definition crypto_hash_struct.h:165
#define CRYPTO_HASH_MODE_UNDEF
Definition crypto_hash_struct.h:56
#define CRYPTO_HASH_TYPE
Definition crypto_hash_struct.h:41
#define CRYPTO_HASH_RESULT_SIZE_224BIT
Definition crypto_hash_struct.h:71
#define CRYPTO_HASH_MAX_MESSAGE_LEN_64BIT
Definition crypto_hash_struct.h:60
#define CRYPTO_HASH_RESULT_SIZE_256BIT
Definition crypto_hash_struct.h:72
#define CRYPTO_HASH_MODE_384
Definition crypto_hash_struct.h:54
crypto_hash_type
Definition crypto_hash_struct.h:98
@ CRYPTO_HASH_TYPE_HMAC_SHA224
Definition crypto_hash_struct.h:130
@ CRYPTO_HASH_TYPE_HMAC_SHA256
Definition crypto_hash_struct.h:134
@ CRYPTO_HASH_TYPE_HMAC_SHA512
Definition crypto_hash_struct.h:142
@ CRYPTO_HASH_TYPE_SHA1
Definition crypto_hash_struct.h:100
@ CRYPTO_HASH_TYPE_SHA256
Definition crypto_hash_struct.h:108
@ CRYPTO_HASH_TYPE_HMAC_SHA384
Definition crypto_hash_struct.h:138
@ CRYPTO_HASH_TYPE_HMAC_SM3
Definition crypto_hash_struct.h:146
@ CRYPTO_HASH_TYPE_SHA384
Definition crypto_hash_struct.h:112
@ CRYPTO_HASH_TYPE_INVALID
Definition crypto_hash_struct.h:151
@ CRYPTO_HASH_TYPE_SHA224
Definition crypto_hash_struct.h:104
@ CRYPTO_HASH_TYPE_HMAC_SHA1
Definition crypto_hash_struct.h:126
@ CRYPTO_HASH_TYPE_SM3
Definition crypto_hash_struct.h:120
@ CRYPTO_HASH_TYPE_SHA512
Definition crypto_hash_struct.h:116
#define compat_hash_type(is_hmac, alg, mode, max_message_length, block_size, result_size)
Definition crypto_hash_struct.h:37
#define CRYPTO_HASH_ALG_SHA2
Definition crypto_hash_struct.h:47
#define CRYPTO_HASH_MODE_256
Definition crypto_hash_struct.h:53
#define CRYPTO_HASH_BLOCK_SIZE_MAX
Definition crypto_hash_struct.h:166
#define CRYPTO_HASH_MAX_MESSAGE_LEN_128BIT
Definition crypto_hash_struct.h:61
#define CRYPTO_HASH_RESULT_SIZE_160BIT
Definition crypto_hash_struct.h:70
Definition crypto_hash_struct.h:154
td_u32 key_len
Definition crypto_hash_struct.h:156
td_handle drv_keyslot_handle
Definition crypto_hash_struct.h:157
td_bool is_keyslot
Definition crypto_hash_struct.h:159
td_bool is_long_term
Definition crypto_hash_struct.h:160
td_u8 * key
Definition crypto_hash_struct.h:155
crypto_hash_type hash_type
Definition crypto_hash_struct.h:158
Definition crypto_hash_struct.h:168
td_u32 tail_len
Definition crypto_hash_struct.h:171
crypto_hash_type hash_type
Definition crypto_hash_struct.h:172
Definition crypto_hash_struct.h:188
td_u32 prk_length
Definition crypto_hash_struct.h:191
td_u32 info_length
Definition crypto_hash_struct.h:193
crypto_hash_type hmac_type
Definition crypto_hash_struct.h:189
td_u8 * info
Definition crypto_hash_struct.h:192
td_u8 * prk
Definition crypto_hash_struct.h:190
Definition crypto_hash_struct.h:180
td_u32 salt_length
Definition crypto_hash_struct.h:183
td_u8 * ikm
Definition crypto_hash_struct.h:184
td_u8 * salt
Definition crypto_hash_struct.h:182
crypto_hash_type hmac_type
Definition crypto_hash_struct.h:181
td_u32 ikm_length
Definition crypto_hash_struct.h:185
Definition crypto_hash_struct.h:196
td_u8 * ikm
Definition crypto_hash_struct.h:200
td_u8 * salt
Definition crypto_hash_struct.h:198
td_u32 ikm_length
Definition crypto_hash_struct.h:201
td_u8 * info
Definition crypto_hash_struct.h:202
td_u32 salt_length
Definition crypto_hash_struct.h:199
crypto_hash_type hmac_type
Definition crypto_hash_struct.h:197
td_u32 info_length
Definition crypto_hash_struct.h:203
td_u32 td_handle
Definition td_type.h:51
unsigned char td_u8
Definition td_type.h:36
td_u8 td_bool
Definition td_type.h:50
unsigned int td_u32
Definition td_type.h:38