1 #ifndef SUNXI_HAL_TWI_H
2 #define SUNXI_HAL_TWI_H
3 
4 #include "hal_sem.h"
5 #include "hal_clk.h"
6 #include "sunxi_hal_common.h"
7 #include "hal_gpio.h"
8 #include "sunxi_hal_regulator.h"
9 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
14 #define CE_ALIGN_SIZE       (0x4)
15 #define CE_ROUND_UP(x,y)    ((((x) + ((y) - 1)) / (y)) * (y))
16 
17 #define AES_KEYSIZE_128         128
18 #define AES_KEYSIZE_192         192
19 #define AES_KEYSIZE_256         256
20 
21 #define AES_BLOCK_SIZE      (16)
22 
23 /*define the ctx for aes requtest*/
24 typedef struct {
25     uint8_t *src_buffer;
26     uint32_t src_length;
27     uint8_t *dst_buffer;
28     uint32_t dst_length;
29     uint8_t *iv;
30     uint8_t *iv_next;
31     uint8_t *key;
32     uint32_t key_length;
33     uint8_t padding[AES_BLOCK_SIZE];
34     uint32_t padding_len;
35     uint32_t dir;
36     uint32_t mode;
37     uint32_t bitwidth;
38 } crypto_aes_req_ctx_t;
39 
40 /*define the ctx for hash requtest*/
41 #define SHA_MAX_DIGEST_SIZE     (64)
42 #define MD5_DIGEST_SIZE         (16)
43 #define SHA1_DIGEST_SIZE        (20)
44 #define SHA224_DIGEST_SIZE      (28)
45 #define SHA256_DIGEST_SIZE      (32)
46 #define SHA384_DIGEST_SIZE      (48)
47 #define SHA512_DIGEST_SIZE      (64)
48 
49 #define MD5_BLOCK_SIZE          (64)
50 #define SHA1_BLOCK_SIZE         (64)
51 #define SHA224_BLOCK_SIZE       (64)
52 #define SHA256_BLOCK_SIZE       (64)
53 #define SHA384_BLOCK_SIZE       (128)
54 #define SHA512_BLOCK_SIZE       (128)
55 
56 typedef struct {
57     uint8_t *src_buffer;
58     uint32_t src_length;
59     uint8_t *dst_buffer;
60     uint32_t dst_length;
61     uint8_t md[SHA_MAX_DIGEST_SIZE];
62     uint32_t md_size;
63     uint8_t padding[SHA512_BLOCK_SIZE * 2];
64     uint32_t padding_len;
65     uint32_t type;
66     uint32_t dir;
67     uint32_t padding_mode;
68 } crypto_hash_req_ctx_t;
69 
70 typedef struct {
71     uint8_t *rng_buf;
72     uint32_t rng_len;
73     uint32_t mode;
74     uint8_t *key;
75     uint32_t key_len;
76 } crypto_rng_req_ctx_t;
77 
78 /*define the ctx for rsa requtest*/
79 typedef struct {
80     uint8_t *key_n;
81     uint32_t n_len;
82     uint8_t *key_e;
83     uint32_t e_len;
84     uint8_t *key_d;
85     uint32_t d_len;
86     uint8_t *src_buffer;
87     uint32_t src_length;
88     uint8_t *dst_buffer;
89     uint32_t dst_length;
90     uint32_t dir;
91     uint32_t type;
92     uint32_t bitwidth;
93 } crypto_rsa_req_ctx_t;
94 
95 int do_aes_crypto(crypto_aes_req_ctx_t *req_ctx);
96 int sunxi_ce_init(void);
97 int sunxi_ce_uninit(void);
98 int do_hash_crypto(crypto_hash_req_ctx_t *req_ctx);
99 int do_rsa_crypto(crypto_rsa_req_ctx_t *req_ctx);
100 int do_rsa_crypto_new(crypto_rsa_req_ctx_t *req_ctx);
101 int do_rng_gen(crypto_rng_req_ctx_t *req_ctx);
102 
103 #ifdef __cplusplus
104 }
105 #endif
106 
107 #endif
108