app_aes.h
Go to the documentation of this file.
1 /**
2 ****************************************************************************************
3 *
4 * @file app_aes.h
5 * @author BLE Driver Team
6 * @brief Header file containing functions prototypes of AES app library.
7 *
8 ****************************************************************************************
9 * @attention
10 #####Copyright (c) 2019 GOODIX
11 All rights reserved.
12
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions are met:
15 * Redistributions of source code must retain the above copyright
16 notice, this list of conditions and the following disclaimer.
17 * Redistributions in binary form must reproduce the above copyright
18 notice, this list of conditions and the following disclaimer in the
19 documentation and/or other materials provided with the distribution.
20 * Neither the name of GOODIX nor the names of its contributors may be used
21 to endorse or promote products derived from this software without
22 specific prior written permission.
23
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
28 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 POSSIBILITY OF SUCH DAMAGE.
35 ****************************************************************************************
36 */
37
38 /** @addtogroup PERIPHERAL Peripheral Driver
39 * @{
40 */
41
42 /** @addtogroup APP_DRIVER APP DRIVER
43 * @{
44 */
45
46 /** @addtogroup APP_AES AES
47 * @brief AES APP module driver.
48 * @{
49 */
50
51
52 #ifndef _APP_AES_H_
53 #define _APP_AES_H_
54
55 #include "grx_hal.h"
56 #include "app_drv_error.h"
57 #include "app_drv_config.h"
58 #include "stdbool.h"
59 #ifdef __cplusplus
60 extern "C" {
61 #endif
62
63 #ifdef HAL_AES_MODULE_ENABLED
64
65 /** @addtogroup APP_AES_ENUM Enumerations
66 * @{
67 */
68
69 /**
70 * @brief AES encryption and decryption mode Enumerations definition
71 */
72 typedef enum
73 {
74 APP_AES_MODE_ECB, /**< ECB encryption mode. */
75 APP_AES_MODE_CBC, /**< CBC encryption mode. */
76 APP_AES_MODE_MAX /**< Only for check parameter, not used as input parameters. */
77 } app_aes_mode_t;
78
79 /**
80 * @brief AES event Enumerations definition
81 */
82 typedef enum
83 {
84 APP_AES_EVT_ERROR, /**< Error reported by AES peripheral. */
85 APP_AES_EVT_DONE /**< Encryption and decryption completed. */
86 } app_aes_evt_type_t;
87
88 /**@brief App aes state types. */
89 typedef enum
90 {
91 APP_AES_INVALID = 0,
92 APP_AES_ACTIVITY,
93 #ifdef APP_DRIVER_WAKEUP_CALL_FUN
94 APP_AES_SLEEP,
95 #endif
96 } app_aes_state_t;
97 /** @} */
98
99 /** @addtogroup APP_AES_STRUCT Structures
100 * @{
101 */
102
103 /**
104 * @brief AES event structure definition
105 */
106 typedef struct
107 {
108 app_aes_evt_type_t type; /**< Type of event. */
109 uint32_t error_code; /**< Error Code. */
110 } app_aes_evt_t;
111 /** @} */
112
113 /** @addtogroup APP_AES_TYPEDEFS Type definitions
114 * @{
115 */
116
117 /**
118 * @brief AES event callback definition
119 */
120 typedef void (*app_aes_evt_handler_t)(app_aes_evt_t *p_evt);
121
122 /** @} */
123
124 /** @addtogroup APP_AES_STRUCT Structures
125 * @{
126 */
127
128 /**
129 * @brief AES event structure definition
130 */
131 typedef struct
132 {
133 app_aes_evt_handler_t evt_handler; /**< AES event callback. */
134 aes_handle_t handle; /**< AES handle Structure.*/
135 app_aes_mode_t use_mode; /**< AES encryption mode. */
136 app_aes_state_t aes_state; /**< App aes state types. */
137 bool start_flag; /**< AES start flag. */
138 } aes_env_t;
139
140 /**
141 * @brief AES parameters structure definition
142 */
143 typedef struct
144 {
145 app_aes_mode_t use_mode; /**< AES encryption mode. */
146 aes_init_t init; /**< AES operation parameters. */
147 aes_env_t aes_env; /**< AES event structure. */
148 } app_aes_params_t;
149
150 /** @} */
151
152 /* Exported functions -----2---------------------------------------------------*/
153 /** @addtogroup APP_AES_DRIVER_FUNCTIONS Functions
154 * @{
155 */
156
157 /**
158 ****************************************************************************************
159 * @brief Initialize the APP AES DRIVER according to the specified parameters
160 * in the app_aes_params_t and app_aes_evt_handler_t.
161 * @note If interrupt mode is set, you can use blocking mode. Conversely, if blocking mode
162 * is set, you can't use interrupt mode.
163 *
164 * @param[in] p_params: Pointer to app_aes_params_t parameter which contains the
165 * configuration information for the specified AES module.
166 * @param[in] evt_handler: AES user callback function.
167 *
168 * @return Result of initialization.
169 ****************************************************************************************
170 */
171 uint16_t app_aes_init(app_aes_params_t *p_params, app_aes_evt_handler_t evt_handler);
172
173 /**
174 ****************************************************************************************
175 * @brief De-initialize the APP AES DRIVER peripheral.
176 *
177 * @return Result of De-initialization.
178 ****************************************************************************************
179 */
180 uint16_t app_aes_deinit(void);
181
182 /**
183 ****************************************************************************************
184 * @brief Encrypted an amount of data in blocking mode.
185 *
186 * @param[in] p_plain_data: Pointer to plain data buffer.
187 * @param[in] number: Amount of data to be Encrypted in bytes
188 * @param[out] p_cypher_data: Pointer to cypher data buffer
189 * @param[in] timeout: Timeout duration
190 *
191 * @return Result of operation.
192 ****************************************************************************************
193 */
194 uint16_t app_aes_encrypt_sync(uint32_t *p_plain_data, uint32_t number, uint32_t *p_cypher_data, uint32_t timeout);
195
196 /**
197 ****************************************************************************************
198 * @brief Decrypted an amount of data in blocking mode.
199 *
200 * @param[in] p_cypher_data: Pointer to cypher data buffer.
201 * @param[in] number: Amount of data to be decrypted in bytes
202 * @param[out] p_plain_data: Pointer to plain data buffer
203 * @param[in] timeout: Timeout duration
204 *
205 * @return Result of operation.
206 ****************************************************************************************
207 */
208 uint16_t app_aes_decrypt_sync(uint32_t *p_cypher_data, uint32_t number, uint32_t *p_plain_data, uint32_t timeout);
209
210 /**
211 ****************************************************************************************
212 * @brief Encrypted an amount of data in non-blocking mode.
213 *
214 * @param[in] p_cypher_data: Pointer to cypher data buffer.
215 * @param[in] number: Amount of data to be decrypted in bytes
216 * @param[out] p_plain_data: Pointer to plain data buffer
217 *
218 * @return Result of operation.
219 ****************************************************************************************
220 */
221 uint16_t app_aes_encrypt_async(uint32_t *p_plain_data, uint32_t number, uint32_t *p_cypher_data);
222
223 /**
224 ****************************************************************************************
225 * @brief Decrypted an amount of data in non-blocking mode.
226 *
227 * @param[in] p_cypher_data: Pointer to cypher data buffer.
228 * @param[in] number: Amount of data to be decrypted in bytes
229 * @param[out] p_plain_data: Pointer to plain data buffer
230 *
231 * @return Result of operation.
232 ****************************************************************************************
233 */
234 uint16_t app_aes_decrypt_async(uint32_t *p_cypher_data, uint32_t number, uint32_t *p_plain_data);
235
236 /**
237 ****************************************************************************************
238 * @brief Return the AES handle.
239 *
240 * @return Pointer to the AES handle.
241 ****************************************************************************************
242 */
243 aes_handle_t *app_aes_get_handle(void);
244
245 /** @} */
246
247 #endif
248
249 #ifdef __cplusplus
250 }
251 #endif
252
253 #endif
254
255 /** @} */
256 /** @} */
257 /** @} */
258
app_aes_mode_t
app_aes_mode_t
AES encryption and decryption mode Enumerations definition.
Definition: app_aes.h:73
app_aes_params_t
AES parameters structure definition.
Definition: app_aes.h:144
app_aes_state_t
app_aes_state_t
App aes state types.
Definition: app_aes.h:90
APP_AES_INVALID
@ APP_AES_INVALID
Definition: app_aes.h:91
app_aes_evt_t
AES event structure definition.
Definition: app_aes.h:107
APP_AES_EVT_DONE
@ APP_AES_EVT_DONE
Encryption and decryption completed.
Definition: app_aes.h:85
app_aes_encrypt_sync
uint16_t app_aes_encrypt_sync(uint32_t *p_plain_data, uint32_t number, uint32_t *p_cypher_data, uint32_t timeout)
Encrypted an amount of data in blocking mode.
aes_env_t
AES event structure definition.
Definition: app_aes.h:132
_aes_init
AES Init Structure definition.
Definition: gr55xx_hal_aes.h:101
app_aes_get_handle
aes_handle_t * app_aes_get_handle(void)
Return the AES handle.
app_aes_params_t::init
aes_init_t init
AES operation parameters.
Definition: app_aes.h:146
app_aes_decrypt_async
uint16_t app_aes_decrypt_async(uint32_t *p_cypher_data, uint32_t number, uint32_t *p_plain_data)
Decrypted an amount of data in non-blocking mode.
app_aes_params_t::aes_env
aes_env_t aes_env
AES event structure.
Definition: app_aes.h:147
app_aes_decrypt_sync
uint16_t app_aes_decrypt_sync(uint32_t *p_cypher_data, uint32_t number, uint32_t *p_plain_data, uint32_t timeout)
Decrypted an amount of data in blocking mode.
aes_env_t::evt_handler
app_aes_evt_handler_t evt_handler
AES event callback.
Definition: app_aes.h:133
grx_hal.h
This file contains all the functions prototypes for the HAL module driver.
aes_env_t::start_flag
bool start_flag
AES start flag.
Definition: app_aes.h:137
APP_AES_MODE_MAX
@ APP_AES_MODE_MAX
Only for check parameter, not used as input parameters.
Definition: app_aes.h:76
app_aes_evt_t::type
app_aes_evt_type_t type
Type of event.
Definition: app_aes.h:108
app_aes_init
uint16_t app_aes_init(app_aes_params_t *p_params, app_aes_evt_handler_t evt_handler)
Initialize the APP AES DRIVER according to the specified parameters in the app_aes_params_t and app_a...
app_aes_deinit
uint16_t app_aes_deinit(void)
De-initialize the APP AES DRIVER peripheral.
app_aes_evt_type_t
app_aes_evt_type_t
AES event Enumerations definition.
Definition: app_aes.h:83
aes_env_t::aes_state
app_aes_state_t aes_state
App aes state types.
Definition: app_aes.h:136
_aes_handle
AES handle Structure definition.
Definition: gr55xx_hal_aes.h:130
aes_env_t::use_mode
app_aes_mode_t use_mode
AES encryption mode.
Definition: app_aes.h:135
aes_env_t::handle
aes_handle_t handle
AES handle Structure.
Definition: app_aes.h:134
APP_AES_ACTIVITY
@ APP_AES_ACTIVITY
Definition: app_aes.h:92
APP_AES_MODE_CBC
@ APP_AES_MODE_CBC
CBC encryption mode.
Definition: app_aes.h:75
APP_AES_MODE_ECB
@ APP_AES_MODE_ECB
ECB encryption mode.
Definition: app_aes.h:74
app_aes_encrypt_async
uint16_t app_aes_encrypt_async(uint32_t *p_plain_data, uint32_t number, uint32_t *p_cypher_data)
Encrypted an amount of data in non-blocking mode.
app_drv_error.h
Header file of app driver error code.
app_drv_config.h
Header file of app driver config code.
app_aes_params_t::use_mode
app_aes_mode_t use_mode
AES encryption mode.
Definition: app_aes.h:145
app_aes_evt_handler_t
void(* app_aes_evt_handler_t)(app_aes_evt_t *p_evt)
AES event callback definition.
Definition: app_aes.h:120
APP_AES_EVT_ERROR
@ APP_AES_EVT_ERROR
Error reported by AES peripheral.
Definition: app_aes.h:84
app_aes_evt_t::error_code
uint32_t error_code
Error Code.
Definition: app_aes.h:109