1 /**
2   ******************************************************************************
3   * @file    rtl_8721d_crypto_api.h
4   * @author
5   * @version V1.0.0
6   * @date    2017-10-26
7   * @brief   This file provides firmware functions to manage the following
8   *          functionalities of the HW crypto:
9   *           - Initialization
10   *           - MD5
11   *           - SHA1/SHA2
12   *           - HMAC
13   *           - AES CBC/ECB/CFB/OFB/CTR/GCM
14   *           - 3DES CBC/ECB/CFB/OFB/CTR
15   *           - DES CBC/ECB/CFB/OFB/CTR
16   *           - Chacha20-poly1305
17   *           - Sequential hash
18   *           - CRC
19   ******************************************************************************
20   * @attention
21   *
22   * This module is a confidential and proprietary property of RealTek and
23   * possession or use of this module requires written permission of RealTek.
24   *
25   * Copyright(c) 2017, Realtek Semiconductor Corporation. All rights reserved.
26   ******************************************************************************
27   */
28 
29 #ifndef __RTL8721D_CRYPTO_API_H__
30 #define __RTL8721D_CRYPTO_API_H__
31 #include "rtl8721d_crypto.h"
32 /** @addtogroup AmebaD_Periph_Driver
33   * @{
34   */
35 
36 /** @defgroup CRYPTO
37   * @brief CRYPTO driver modules
38   * @{
39   */
40 
41 /** @addtogroup CRYPTO
42   * @verbatim
43   *****************************************************************************************
44   * Method 2 (use upper level API, for user use)
45   *****************************************************************************************
46   *	-call rtl_cryptoEngine_init to open IPSEC function & clock
47   *
48   *	-call following API for set key:
49   *		-rtl_crypto_xxx_init
50   *
51   *	-call following API for authentication/encrypt/decrypt:
52   *		authentication		-rtl_crypto_xxx_process or
53   *		sequential hash		-rtl_crypto_xxx_update and
54   *						-rtl_crypto_xxx_final
55   *
56   *		encrypt			-rtl_crypto_xxx_encrypt
57   *		decrypt			-rtl_crypto_xxx_decrypt
58   *
59   *****************************************************************************************
60   * @endverbatim
61   */
62 
63 /* Exported constants --------------------------------------------------------*/
64 
65 /** @defgroup CRYPTO_Exported_Constants CRYPTO Exported Constants
66   * @{
67   */
68 
69 /** @defgroup CRYPTO_Process_Status_definitions
70   * @{
71   */
72 #define _ERRNO_CRYPTO_DESC_NUM_SET_OutRange 	-2
73 #define _ERRNO_CRYPTO_BURST_NUM_SET_OutRange	-3
74 #define _ERRNO_CRYPTO_NULL_POINTER				-4
75 #define _ERRNO_CRYPTO_ENGINE_NOT_INIT			-5
76 #define _ERRNO_CRYPTO_ADDR_NOT_4Byte_Aligned	-6
77 #define _ERRNO_CRYPTO_KEY_OutRange				-7
78 #define _ERRNO_CRYPTO_MSG_OutRange				-8
79 #define _ERRNO_CRYPTO_IV_OutRange				-9
80 #define _ERRNO_CRYPTO_AUTH_TYPE_NOT_MATCH		-10
81 #define _ERRNO_CRYPTO_CIPHER_TYPE_NOT_MATCH 	-11
82 #define _ERRNO_CRYPTO_KEY_IV_LEN_DIFF			-12
83 #define _ERRNO_CRYPTO_HASH_FINAL_NO_UPDATE		-13
84 /**
85   * @}
86   */
87 
88 /**
89   * @}
90   */
91 
92 /* Exported functions --------------------------------------------------------*/
93 /**************************************************************************//**
94  * @defgroup CRYPTO_Exported_Functions CRYPTO Exported Functions
95  * @{
96  *****************************************************************************/
97 
98 /** @defgroup Authentication_Functions
99   * @{
100   */
101 _LONG_CALL_ int rtl_crypto_md5(IN const u8* message, IN const u32 msglen, OUT u8* pDigest);
102 _LONG_CALL_ int rtl_crypto_md5_init(void);
103 _LONG_CALL_ int rtl_crypto_md5_process(IN const u8* message, const IN u32 msglen, OUT u8* pDigest);
104 _LONG_CALL_ int rtl_crypto_md5_update(IN const u8* message, IN const u32 msglen);
105 _LONG_CALL_ int rtl_crypto_md5_final(OUT u8* pDigest);
106 
107 _LONG_CALL_ int rtl_crypto_sha1(IN const u8* message, IN const u32 msglen, OUT u8* pDigest);
108 _LONG_CALL_ int rtl_crypto_sha1_init(void);
109 _LONG_CALL_ int rtl_crypto_sha1_process(IN const u8* message, IN const u32 msglen, OUT u8* pDigest);
110 _LONG_CALL_ int rtl_crypto_sha1_update(IN const u8* message, IN const u32 msglen);
111 _LONG_CALL_ int rtl_crypto_sha1_final(OUT u8* pDigest);
112 
113 _LONG_CALL_ int rtl_crypto_sha2(IN const SHA2_TYPE sha2type, IN const u8* message, IN const u32 msglen, OUT u8* pDigest);
114 _LONG_CALL_ int rtl_crypto_sha2_init(IN const SHA2_TYPE sha2type);
115 _LONG_CALL_ int rtl_crypto_sha2_process(IN const u8* message, IN const u32 msglen, OUT u8* pDigest);
116 _LONG_CALL_ int rtl_crypto_sha2_update(IN const u8* message, IN const u32 msglen);
117 _LONG_CALL_ int rtl_crypto_sha2_final(OUT u8* pDigest);
118 
119 _LONG_CALL_ int rtl_crypto_hmac_md5(IN const u8* message, IN const u32 msglen, IN const u8* key, IN const u32 keylen, OUT u8* pDigest);
120 _LONG_CALL_ int rtl_crypto_hmac_md5_init(IN const u8* key, IN const u32 keylen);
121 _LONG_CALL_ int rtl_crypto_hmac_md5_process(IN const u8* message, IN const u32 msglen, OUT u8* pDigest);
122 _LONG_CALL_ int rtl_crypto_hmac_md5_update(IN const u8* message, IN const u32 msglen);
123 _LONG_CALL_ int rtl_crypto_hmac_md5_final(OUT u8* pDigest);
124 
125 _LONG_CALL_ int rtl_crypto_hmac_sha1(IN const u8* message, IN const u32 msglen, IN const u8* key, IN const u32 keylen, OUT u8* pDigest);
126 _LONG_CALL_ int rtl_crypto_hmac_sha1_start(IN const u8* key, IN const u32 keylen);
127 _LONG_CALL_ int rtl_crypto_hmac_sha1_init(IN const u8* key, IN const u32 keylen);
128 _LONG_CALL_ int rtl_crypto_hmac_sha1_process(IN const u8* message, IN const u32 msglen, OUT u8* pDigest);
129 _LONG_CALL_ int rtl_crypto_hmac_sha1_update(IN const u8* message, IN const u32 msglen);
130 _LONG_CALL_ int rtl_crypto_hmac_sha1_final(OUT u8* pDigest);
131 
132 _LONG_CALL_ int rtl_crypto_hmac_sha2(IN const SHA2_TYPE sha2type, IN const u8* message, IN const u32 msglen, IN const u8* key, IN const u32 keylen, OUT u8* pDigest);
133 _LONG_CALL_ int rtl_crypto_hmac_sha2_start(IN const u8* key, IN const u32 keylen);
134 _LONG_CALL_ int rtl_crypto_hmac_sha2_init(IN const SHA2_TYPE sha2type, IN const u8* key, IN const u32 keylen);
135 _LONG_CALL_ int rtl_crypto_hmac_sha2_process(IN const u8* message, IN const u32 msglen, OUT u8* pDigest);
136 _LONG_CALL_ int rtl_crypto_hmac_sha2_update(IN const u8* message, IN const u32 msglen);
137 _LONG_CALL_ int rtl_crypto_hmac_sha2_final(OUT u8* pDigest);
138 /**
139   * @}
140   */
141 
142 /** @defgroup Cipher_Functions
143   * @{
144   */
145 _LONG_CALL_ int rtl_crypto_aes_cbc_init(IN const u8* key, IN const u32 keylen);
146 _LONG_CALL_ int rtl_crypto_aes_cbc_encrypt(IN const u8* message, IN const u32 msglen, IN const u8* iv, IN const u32 ivlen, OUT u8* pResult);
147 _LONG_CALL_ int rtl_crypto_aes_cbc_decrypt(IN const u8* message, IN const u32 msglen, IN const u8* iv, IN const u32 ivlen, OUT u8* pResult);
148 
149 _LONG_CALL_ int rtl_crypto_aes_ecb_init(IN const u8* key, IN const u32 keylen);
150 _LONG_CALL_ int rtl_crypto_aes_ecb_encrypt(IN const u8* message, IN const u32 msglen, IN const u8* iv, IN const u32 ivlen, OUT u8* pResult);
151 _LONG_CALL_ int rtl_crypto_aes_ecb_decrypt(IN const u8* message, IN const u32 msglen, IN const u8* iv, IN const u32 ivlen, OUT u8* pResult);
152 
153 _LONG_CALL_ int rtl_crypto_aes_ctr_init(IN const u8* key, IN const u32 keylen);
154 _LONG_CALL_ int rtl_crypto_aes_ctr_encrypt(IN const u8* message, IN const u32 msglen, IN const u8* iv, IN const u32 ivlen, OUT u8* pResult);
155 _LONG_CALL_ int rtl_crypto_aes_ctr_decrypt(IN const u8* message, IN const u32 msglen, IN const u8* iv, IN const u32 ivlen, OUT u8* pResult);
156 
157 _LONG_CALL_ int rtl_crypto_aes_cfb_init(IN const u8* key, IN const u32 keylen);
158 _LONG_CALL_ int rtl_crypto_aes_cfb_encrypt(IN const u8* message, IN const u32 msglen, IN const u8* iv, IN const u32 ivlen, OUT u8* pResult);
159 _LONG_CALL_ int rtl_crypto_aes_cfb_decrypt(IN const u8* message, IN const u32 msglen, IN const u8* iv, IN const u32 ivlen, OUT u8* pResult);
160 
161 _LONG_CALL_ int rtl_crypto_aes_ofb_init(IN const u8* key, IN const u32 keylen);
162 _LONG_CALL_ int rtl_crypto_aes_ofb_encrypt(IN const u8* message, IN const u32 msglen, IN const u8* iv, IN const u32 ivlen, OUT u8* pResult);
163 _LONG_CALL_ int rtl_crypto_aes_ofb_decrypt(IN const u8* message, IN const u32 msglen, IN const u8* iv, IN const u32 ivlen, OUT u8* pResult);
164 
165 _LONG_CALL_ int rtl_crypto_aes_gcm_init(IN const u8* key, IN const u32 keylen);
166 _LONG_CALL_ int rtl_crypto_aes_gcm_encrypt(IN const u8* message, IN const u32 msglen, IN const u8* iv, IN const u8* aad, IN const u32 aadlen, OUT u8* pResult, OUT u8* pTag);
167 _LONG_CALL_ int rtl_crypto_aes_gcm_decrypt(IN const u8* message, IN const u32 msglen, IN const u8* iv, IN const u8* aad, IN const u32 aadlen, OUT u8* pResult, OUT u8* pTag);
168 
169 _LONG_CALL_ int rtl_crypto_3des_cbc_init(IN const u8* key, IN const u32 keylen);
170 _LONG_CALL_ int rtl_crypto_3des_cbc_encrypt(IN const u8* message, IN const u32 msglen, IN const u8* iv, IN const u32 ivlen, OUT u8* pResult);
171 _LONG_CALL_ int rtl_crypto_3des_cbc_decrypt(IN const u8* message, IN const u32 msglen, IN const u8* iv, IN const u32 ivlen, OUT u8* pResult);
172 
173 _LONG_CALL_ int rtl_crypto_3des_ecb_init(IN const u8* key, IN const u32 keylen);
174 _LONG_CALL_ int rtl_crypto_3des_ecb_encrypt(IN const u8* message, IN const u32 msglen, IN const u8* iv, IN const u32 ivlen, OUT u8* pResult);
175 _LONG_CALL_ int rtl_crypto_3des_ecb_decrypt(IN const u8* message, IN const u32 msglen, IN const u8* iv, IN const u32 ivlen, OUT u8* pResult);
176 
177 _LONG_CALL_ int rtl_crypto_3des_ctr_init(IN const u8* key, IN const u32 keylen);
178 _LONG_CALL_ int rtl_crypto_3des_ctr_encrypt(IN const u8* message, IN const u32 msglen, IN const u8* iv, IN const u32 ivlen, OUT u8* pResult);
179 _LONG_CALL_ int rtl_crypto_3des_ctr_decrypt(IN const u8* message, IN const u32 msglen, IN const u8* iv, IN const u32 ivlen, OUT u8* pResult);
180 
181 _LONG_CALL_ int rtl_crypto_3des_cfb_init(IN const u8* key, IN const u32 keylen);
182 _LONG_CALL_ int rtl_crypto_3des_cfb_encrypt(IN const u8* message, IN const u32 msglen, IN const u8* iv, IN const u32 ivlen, OUT u8* pResult);
183 _LONG_CALL_ int rtl_crypto_3des_cfb_decrypt(IN const u8* message, IN const u32 msglen, IN const u8* iv, IN const u32 ivlen, OUT u8* pResult);
184 
185 _LONG_CALL_ int rtl_crypto_3des_ofb_init(IN const u8* key, IN const u32 keylen);
186 _LONG_CALL_ int rtl_crypto_3des_ofb_encrypt(IN const u8* message, IN const u32 msglen, IN const u8* iv, IN const u32 ivlen, OUT u8* pResult);
187 _LONG_CALL_ int rtl_crypto_3des_ofb_decrypt(IN const u8* message, IN const u32 msglen, IN const u8* iv, IN const u32 ivlen, OUT u8* pResult);
188 
189 _LONG_CALL_ int rtl_crypto_des_cbc_init(IN const u8* key, IN const u32 keylen);
190 _LONG_CALL_ int rtl_crypto_des_cbc_encrypt(IN const u8* message, IN const u32 msglen, IN const u8* iv, IN const u32 ivlen, OUT u8* pResult);
191 _LONG_CALL_ int rtl_crypto_des_cbc_decrypt(IN const u8* message, IN const u32 msglen, IN const u8* iv, IN const u32 ivlen, OUT u8* pResult);
192 
193 _LONG_CALL_ int rtl_crypto_des_ecb_init(IN const u8* key, IN const u32 keylen);
194 _LONG_CALL_ int rtl_crypto_des_ecb_encrypt(IN const u8* message, IN const u32 msglen, IN const u8* iv, IN const u32 ivlen, OUT u8* pResult);
195 _LONG_CALL_ int rtl_crypto_des_ecb_decrypt(IN const u8* message, IN const u32 msglen, IN const u8* iv, IN const u32 ivlen, OUT u8* pResult);
196 
197 _LONG_CALL_ int rtl_crypto_des_ctr_init(IN const u8* key, IN const u32 keylen);
198 _LONG_CALL_ int rtl_crypto_des_ctr_encrypt(IN const u8* message, IN const u32 msglen, IN const u8* iv, IN const u32 ivlen, OUT u8* pResult);
199 _LONG_CALL_ int rtl_crypto_des_ctr_decrypt(IN const u8* message, IN const u32 msglen, IN const u8* iv, IN const u32 ivlen, OUT u8* pResult);
200 
201 _LONG_CALL_ int rtl_crypto_des_cfb_init(IN const u8* key, IN const u32 keylen);
202 _LONG_CALL_ int rtl_crypto_des_cfb_encrypt(IN const u8* message, IN const u32 msglen, IN const u8* iv, IN const u32 ivlen, OUT u8* pResult);
203 _LONG_CALL_ int rtl_crypto_des_cfb_decrypt(IN const u8* message, IN const u32 msglen, IN const u8* iv, IN const u32 ivlen, OUT u8* pResult);
204 
205 _LONG_CALL_ int rtl_crypto_des_ofb_init(IN const u8* key, IN const u32 keylen);
206 _LONG_CALL_ int rtl_crypto_des_ofb_encrypt(IN const u8* message, IN const u32 msglen, IN const u8* iv, IN const u32 ivlen, OUT u8* pResult);
207 _LONG_CALL_ int rtl_crypto_des_ofb_decrypt(IN const u8* message, IN const u32 msglen, IN const u8* iv, IN const u32 ivlen, OUT u8* pResult);
208 
209 _LONG_CALL_ int rtl_crypto_poly1305_init(IN const u8 *key);
210 _LONG_CALL_ int rtl_crypto_poly1305_process(IN const u8 *message, IN const u32 msglen, OUT u8 *pDigest);
211 _LONG_CALL_ int rtl_crypto_poly1305(IN const u8* message, IN const u32 msglen, IN const u8* key, OUT u8* pDigest);
212 
213 _LONG_CALL_ int rtl_crypto_chacha_init(IN const u8* key);
214 _LONG_CALL_ int rtl_crypto_chacha_encrypt(IN const u8* message, IN const u32 msglen, IN const u8* iv, IN const u32 count, OUT u8* pResult);
215 _LONG_CALL_ int rtl_crypto_chacha_decrypt(IN const u8* message, IN const u32 msglen, IN const u8* iv, IN const u32 count, OUT u8* pResult);
216 
217 _LONG_CALL_ int rtl_crypto_chacha_poly1305_init(IN const u8* key);
218 _LONG_CALL_ int rtl_crypto_chacha_poly1305_encrypt(IN const u8* message, 	IN const u32 msglen, IN const u8* nonce, IN const u8* aad, IN const u32 aadlen, OUT u8* pResult, OUT u8 *pTag);
219 _LONG_CALL_ int rtl_crypto_chacha_poly1305_decrypt(IN const u8* message, 	IN const u32 msglen, IN const u8* nonce, IN const u8* aad, IN const u32 aadlen, OUT u8* pResult, OUT u8 *pTag);
220 /**
221   * @}
222   */
223 
224 /**
225   * @}
226   */
227 
228 /**
229   * @}
230   */
231 
232 /**
233   * @}
234   */
235 
236 #endif /* __RTL8721D_CRYPTO_API_H__ */
237 
238 /******************* (C) COPYRIGHT 2017 Realtek Semiconductor *****END OF FILE****/
239 
240