SemiDrive SSDK Appication Program Interface PTG3.0
hash_basic.h
Go to the documentation of this file.
1
9#ifndef HASH_BASIC_H
10#define HASH_BASIC_H
11
12#include "register_base_addr.h"
13#include "sdrv_crypto_utility.h"
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
19#define SUPPORT_HASH_SM3
20#define SUPPORT_HASH_MD5
21#define SUPPORT_HASH_SHA256
22#define SUPPORT_HASH_SHA384
23#define SUPPORT_HASH_SHA512
24#define SUPPORT_HASH_SHA1
25#define SUPPORT_HASH_SHA224
26#define SUPPORT_HASH_SHA512_224
27#define SUPPORT_HASH_SHA512_256
28#define SUPPORT_HASH_SHA3_224
29#define SUPPORT_HASH_SHA3_256
30#define SUPPORT_HASH_SHA3_384
31#define SUPPORT_HASH_SHA3_512
32
33#define HASH_DMA_FUNCTION
34
35#define HMAC_SECURE_PORT_FUNCTION
36#ifdef HMAC_SECURE_PORT_FUNCTION
37#define HMAC_MAX_KEY_IDX \
38 (8) /* if key is from secure port, the max key index(or the number of \
39 keys) */
40#define HMAC_MAX_SP_KEY_SIZE \
41 (64) /* for secure port key, max bytes of one key */
42#endif
43
44/* some register offset */
45#define HASH_HMAC_OFFSET (4)
46#define HASH_REVERSE_BYTE_ORDER_IN_WORD_OFFSET (8)
47#define HASH_LAST_BLOCK_OFFSET (16)
48#define HASH_DMA_OFFSET (16)
49
50/* HASH register struct */
51typedef struct hash_reg {
52 uint32_t hash_ctrl; /* Offset: 0x000 (R/W) Control register */
53 uint32_t hash_cfg; /* Offset: 0x004 (R/W) Config register */
54 uint32_t rev_1[2];
55 uint32_t hash_risr; /* Offset: 0x010 (W0C) Resource of Interrupt Status
56 register */
57 uint32_t hash_imcr; /* Offset: 0x014 (R/W) Interrupt Management and Control
58 register */
59 uint32_t
60 hash_misr; /* Offset: 0x018 (R) Multiple Interrupt Status register */
61 uint32_t rev_2[5];
62 uint32_t hash_msg_len[4]; /* Offset: 0x030 (R/W) message total length
63 register */
64 uint32_t hash_msg_cnt[4]; /* Offset: 0x040 (R/W) message been handled
65 length register */
66 uint32_t rev_3[4];
67 uint32_t
68 hash_key_len; /* Offset: 0x060 (R/W) HMAC KEY total length register */
69 uint32_t rev_4[3];
70 uint32_t hash_key_cnt; /* Offset: 0x070 (R/W) HMAC KEY been handled length
71 register */
72 uint32_t rev_5[15];
73 uint32_t hash_mdin_cr; /* Offset: 0x0B0 (R/W) Data flag register */
74 uint32_t rev_6[3];
75 uint32_t hash_m_din; /* Offset: 0x0C0 (W) Hash message Input register */
76 uint32_t rev_7[14];
77 uint32_t hash_version; /* Offset: 0x0FC (R) Version register */
78 uint32_t
79 hash_in[50]; /* Offset: 0x100 (W) Hash iterator Input register */
80 uint32_t rev_8[14];
81 uint32_t hash_out[50]; /* Offset: 0x200 (R) Output register */
82 uint32_t rev_9[14];
83 uint32_t dma_cr; /* Offset: 0x300 (R) DMA config register */
84 uint32_t dma_sr; /* Offset: 0x304 (R/W) DMA Status register */
85 uint32_t dma_to; /* Offset: 0x308 (R/W) DMA Status register */
86 uint32_t rev_10[1];
87 uint32_t dma_sa_l; /* Offset: 0x310 (R/W) DMA Source Address Low part
88 register */
89 uint32_t dma_sa_h; /* Offset: 0x314 (R/W) DMA Source Address High part
90 register */
91 uint32_t rev_11[2];
92 uint32_t dma_da_l; /* Offset: 0x320 (R/W) DMA Destination Address Low part
93 register */
94 uint32_t dma_da_h; /* Offset: 0x324 (R/W) DMA Destination Address High part
95 register */
96 uint32_t rev_12[2];
97 uint32_t dma_rlen; /* Offset: 0x330 (R/W) DMA read data length register */
98 uint32_t dma_wlen; /* Offset: 0x334 (R/W) DMA write data length register */
100
101/* HASH max length */
102#if (defined(SUPPORT_HASH_SHA3_224) || defined(SUPPORT_HASH_SHA3_256) || \
103 defined(SUPPORT_HASH_SHA3_384) || defined(SUPPORT_HASH_SHA3_512))
104#define HASH_DIGEST_MAX_WORD_LEN (16)
105#define HASH_BLOCK_MAX_WORD_LEN (36)
106#elif (defined(SUPPORT_HASH_SHA384) || defined(SUPPORT_HASH_SHA512) || \
107 defined(SUPPORT_HASH_SHA512_224) || defined(SUPPORT_HASH_SHA512_256))
108#define HASH_DIGEST_MAX_WORD_LEN (16)
109#define HASH_BLOCK_MAX_WORD_LEN (32)
110#else
111#define HASH_DIGEST_MAX_WORD_LEN (8)
112#define HASH_BLOCK_MAX_WORD_LEN (16)
113#endif
115#define HASH_BLOCK_MAX_BYTE_LEN (HASH_BLOCK_MAX_WORD_LEN << 2)
116
117#if (defined(SUPPORT_HASH_SHA3_224) || defined(SUPPORT_HASH_SHA3_256) || \
118 defined(SUPPORT_HASH_SHA3_384) || defined(SUPPORT_HASH_SHA3_512))
119#define HASH_ITERATOR_MAX_WORD_LEN (50)
120#else
121#define HASH_ITERATOR_MAX_WORD_LEN HASH_DIGEST_MAX_WORD_LEN
122#endif
123
124#if (defined(SUPPORT_HASH_SHA384) || defined(SUPPORT_HASH_SHA512) || \
125 defined(SUPPORT_HASH_SHA512_224) || defined(SUPPORT_HASH_SHA512_256))
126#define HASH_TOTAL_LEN_MAX_WORD_LEN (4)
127#else
128#define HASH_TOTAL_LEN_MAX_WORD_LEN (2)
129#endif
130
131/* HASH algorithm definition */
132typedef enum {
133#ifdef SUPPORT_HASH_SM3
134 HASH_SM3 = 0,
135#endif
136
137#ifdef SUPPORT_HASH_MD5
138 HASH_MD5 = 1,
139#endif
140
141#ifdef SUPPORT_HASH_SHA256
142 HASH_SHA256 = 2,
143#endif
144
145#ifdef SUPPORT_HASH_SHA384
146 HASH_SHA384 = 3,
147#endif
148
149#ifdef SUPPORT_HASH_SHA512
150 HASH_SHA512 = 4,
151#endif
152
153#ifdef SUPPORT_HASH_SHA1
154 HASH_SHA1 = 5,
155#endif
156
157#ifdef SUPPORT_HASH_SHA224
158 HASH_SHA224 = 6,
159#endif
160
161#ifdef SUPPORT_HASH_SHA512_224
162 HASH_SHA512_224 = 7,
163#endif
164
165#ifdef SUPPORT_HASH_SHA512_256
166 HASH_SHA512_256 = 8,
167#endif
168
169#ifdef SUPPORT_HASH_SHA3_224
170 HASH_SHA3_224 = 9,
171#endif
172
173#ifdef SUPPORT_HASH_SHA3_256
174 HASH_SHA3_256 = 10,
175#endif
176
177#ifdef SUPPORT_HASH_SHA3_384
178 HASH_SHA3_384 = 11,
179#endif
180
181#ifdef SUPPORT_HASH_SHA3_512
182 HASH_SHA3_512 = 12,
183#endif
184} HASH_ALG;
185
186/* HASH return code */
194};
196typedef void (*HASH_CALLBACK)(void);
198uint32_t hash_get_version(void);
200void hash_set_cpu_mode(void);
202void hash_set_dma_mode(void);
204void hash_set_hash_mode(void);
206void hash_set_hmac_mode(void);
208void hash_set_hmac_key_mode(void);
210void hash_clear_hmac_key_mode(void);
212void hash_clear_risp(void);
214void hash_set_hmac_key_cnt(uint32_t bitlen);
216void hash_set_hmac_key_len(uint32_t bitlen);
218void hash_hmac_key_opr_one_block(uint32_t *key, uint32_t block_byte_len);
220void hash_hmac_key_opr(uint8_t *key, uint32_t key_bytes);
224void hash_hmac_enable_secure_port(uint16_t sp_key_idx);
226void hash_hmac_sp_key_opr(uint32_t key_bits);
228void hash_set_alg(HASH_ALG hash_alg);
230uint32_t hash_check_whether_sha3_alg(HASH_ALG hash_alg);
232void hash_update_config(void);
242void hash_clear_dma_ch_en(void);
244void hash_set_last_block(uint8_t tag);
246void hash_set_endian_uint32(void);
248void hash_get_iterator(uint8_t *iterator, uint8_t hash_iterator_words);
250void hash_set_iterator(uint32_t *iterator, uint8_t hash_iterator_words);
252void hash_clear_msg_len(void);
254void hash_set_msg_len(uint32_t bytelen);
256void hash_set_msg_total_bit_len(uint32_t *msg_total_bits,
257 uint32_t block_byte_len);
259void hash_start(void);
261void hash_wait_till_done(void);
263void hash_input_msg(uint8_t *msg, uint32_t msg_words);
265void hash_input_msg_u8(uint8_t *msg, uint32_t msg_bytes);
267void hash_set_dma_ctl0(uint32_t ctl0);
269void hash_set_dma_ctl1(uint32_t ctl1);
271void hash_set_dma_ch_ctl(uint32_t ch_ctl);
273void hash_set_dma_sublen(uint32_t sublen);
275void hash_set_dma_ch_rctl(uint32_t ch_rctl);
277void hash_set_dma_ch_wctl(uint32_t ch_wctl);
279void hash_set_dma_wlen(uint32_t wlen);
281void hash_clear_dma_sa_da(void);
282
283#ifdef HASH_DMA_FUNCTION
284void hash_dma_operate(uint32_t *msg, uint32_t *iterator, uint32_t msgBitLen,
285 HASH_CALLBACK callback);
286#endif
287
288#ifdef __cplusplus
289}
290#endif
291
292#endif
HASH_ALG
Definition: hash_basic.h:131
@ HASH_SHA224
Definition: hash_basic.h:157
@ HASH_SHA1
Definition: hash_basic.h:153
@ HASH_SHA512_224
Definition: hash_basic.h:161
@ HASH_SHA256
Definition: hash_basic.h:141
@ HASH_MD5
Definition: hash_basic.h:137
@ HASH_SM3
Definition: hash_basic.h:133
@ HASH_SHA512
Definition: hash_basic.h:149
@ HASH_SHA3_224
Definition: hash_basic.h:169
@ HASH_SHA3_384
Definition: hash_basic.h:177
@ HASH_SHA3_512
Definition: hash_basic.h:181
@ HASH_SHA384
Definition: hash_basic.h:145
@ HASH_SHA3_256
Definition: hash_basic.h:173
@ HASH_SHA512_256
Definition: hash_basic.h:165
void hash_set_hmac_key_mode(void)
void hash_enable_cpu_interruption(void)
HASH_RET_CODE
Definition: hash_basic.h:186
@ HASH_ERROR
Definition: hash_basic.h:192
@ HASH_CONFIG_INVALID
Definition: hash_basic.h:189
@ HASH_LEN_OVERFLOW
Definition: hash_basic.h:191
@ HASH_SUCCESS
Definition: hash_basic.h:187
@ HASH_BUFFER_NULL
Definition: hash_basic.h:188
@ HASH_INPUT_INVALID
Definition: hash_basic.h:190
void hash_enable_dma_interruption(void)
void hash_set_dma_wlen(uint32_t wlen)
void hash_hmac_key_opr(uint8_t *key, uint32_t key_bytes)
void hash_clear_risp(void)
void hash_input_msg(uint8_t *msg, uint32_t msg_words)
void hash_set_cpu_mode(void)
void hash_set_hmac_mode(void)
void(* HASH_CALLBACK)(void)
Definition: hash_basic.h:195
void hash_set_hash_mode(void)
void hash_start(void)
void hash_disable_cpu_interruption(void)
uint32_t hash_check_whether_sha3_alg(HASH_ALG hash_alg)
void hash_clear_msg_len(void)
void hash_set_iterator(uint32_t *iterator, uint8_t hash_iterator_words)
void hash_set_dma_ch_ctl(uint32_t ch_ctl)
void hash_set_hmac_key_cnt(uint32_t bitlen)
void hash_set_dma_ch_wctl(uint32_t ch_wctl)
struct hash_reg hash_reg_t
uint32_t hash_get_version(void)
void hash_set_dma_mode(void)
void hash_disable_dma_interruption(void)
void hash_set_msg_total_bit_len(uint32_t *msg_total_bits, uint32_t block_byte_len)
void hash_set_hmac_key_len(uint32_t bitlen)
void hash_hmac_enable_secure_port(uint16_t sp_key_idx)
void hash_set_msg_len(uint32_t bytelen)
void hash_set_last_block(uint8_t tag)
void hash_dma_operate(uint32_t *msg, uint32_t *iterator, uint32_t msgBitLen, HASH_CALLBACK callback)
void hash_clear_dma_ch_en(void)
void hash_set_alg(HASH_ALG hash_alg)
void hash_hmac_key_opr_one_block(uint32_t *key, uint32_t block_byte_len)
void hash_input_msg_u8(uint8_t *msg, uint32_t msg_bytes)
void hash_set_dma_sublen(uint32_t sublen)
void hash_clear_dma_sa_da(void)
void hash_hmac_disable_secure_port(void)
void hash_set_dma_ch_rctl(uint32_t ch_rctl)
void hash_hmac_sp_key_opr(uint32_t key_bits)
void hash_wait_till_done(void)
void hash_clear_hmac_key_mode(void)
void hash_get_iterator(uint8_t *iterator, uint8_t hash_iterator_words)
void hash_set_dma_ctl1(uint32_t ctl1)
void hash_set_endian_uint32(void)
void hash_update_config(void)
void hash_set_dma_ctl0(uint32_t ctl0)
crypto utility api
Definition: hash_basic.h:50
uint32_t rev_2[5]
Definition: hash_basic.h:60
uint32_t dma_sr
Definition: hash_basic.h:83
uint32_t rev_8[14]
Definition: hash_basic.h:79
uint32_t rev_9[14]
Definition: hash_basic.h:81
uint32_t dma_da_l
Definition: hash_basic.h:91
uint32_t rev_6[3]
Definition: hash_basic.h:73
uint32_t dma_da_h
Definition: hash_basic.h:93
uint32_t hash_misr
Definition: hash_basic.h:59
uint32_t rev_4[3]
Definition: hash_basic.h:68
uint32_t hash_out[50]
Definition: hash_basic.h:80
uint32_t hash_mdin_cr
Definition: hash_basic.h:72
uint32_t dma_to
Definition: hash_basic.h:84
uint32_t rev_5[15]
Definition: hash_basic.h:71
uint32_t hash_version
Definition: hash_basic.h:76
uint32_t rev_1[2]
Definition: hash_basic.h:53
uint32_t hash_m_din
Definition: hash_basic.h:74
uint32_t hash_msg_cnt[4]
Definition: hash_basic.h:63
uint32_t dma_rlen
Definition: hash_basic.h:96
uint32_t hash_key_len
Definition: hash_basic.h:67
uint32_t dma_cr
Definition: hash_basic.h:82
uint32_t hash_ctrl
Definition: hash_basic.h:51
uint32_t hash_risr
Definition: hash_basic.h:54
uint32_t hash_imcr
Definition: hash_basic.h:56
uint32_t hash_msg_len[4]
Definition: hash_basic.h:61
uint32_t rev_11[2]
Definition: hash_basic.h:90
uint32_t rev_3[4]
Definition: hash_basic.h:65
uint32_t hash_in[50]
Definition: hash_basic.h:78
uint32_t hash_cfg
Definition: hash_basic.h:52
uint32_t rev_7[14]
Definition: hash_basic.h:75
uint32_t dma_sa_l
Definition: hash_basic.h:86
uint32_t dma_wlen
Definition: hash_basic.h:97
uint32_t rev_10[1]
Definition: hash_basic.h:85
uint32_t dma_sa_h
Definition: hash_basic.h:88
uint32_t rev_12[2]
Definition: hash_basic.h:95
uint32_t hash_key_cnt
Definition: hash_basic.h:69