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 /** @defgroup 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 "gr55xx_hal.h"
56 #include "app_drv_error.h"
57 #ifdef ENV_USE_FREERTOS
58 #include "app_rtos_cfg.h"
59 #endif
60 
61 #ifdef __cplusplus
62 extern "C" {
63 #endif
64 
65 #ifdef HAL_AES_MODULE_ENABLED
66 
67 /** @addtogroup APP_AES_ENUM Enumerations
68  * @{
69  */
70 
71 /**
72  * @brief AES operating mode Enumerations definition
73  */
74 typedef enum
75 {
76  APP_AES_TYPE_INTERRUPT, /**< Interrupt operation mode. */
77  APP_AES_TYPE_POLLING, /**< Polling operation mode. */
78  APP_AES_TYPE_DMA, /**< DMA operation mode. */
79  APP_AES_TYPE_MAX /**< Only for check parameter, not used as input parameters. */
81 
82 /**
83  * @brief AES encryption and decryption mode Enumerations definition
84  */
85 typedef enum
86 {
87  APP_AES_MODE_ECB, /**< ECB encryption mode. */
88  APP_AES_MODE_CBC, /**< CBC encryption mode. */
89  APP_AES_MODE_MAX /**< Only for check parameter, not used as input parameters. */
91 
92 /**
93  * @brief AES event Enumerations definition
94  */
95 typedef enum
96 {
97  APP_AES_EVT_ERROR, /**< Error reported by AES peripheral. */
98  APP_AES_EVT_DONE /**< Encryption and decryption completed. */
100 /** @} */
101 
102 
103 /** @addtogroup APP_AES_STRUCT Structures
104  * @{
105  */
106 
107 /**
108  * @brief AES parameters structure definition
109  */
110 typedef struct
111 {
112  app_aes_type_t use_type; /**< Specifies the operation mode of AES. */
113  app_aes_mode_t use_mode; /**< AES encryption mode. */
114  aes_init_t init; /**< AES operation parameters */
116 
117 /**
118  * @brief AES event structure definition
119  */
120 typedef struct
121 {
122  app_aes_evt_type_t type; /**< Type of event. */
123  uint32_t error_code; /**< AES Error code . */
124 } app_aes_evt_t;
125 
126 /**
127  * @brief AES event callback definition
128  */
129 typedef void (*app_aes_evt_handler_t)(app_aes_evt_t *p_evt);
130 
131 /** @} */
132 
133 /* Exported functions --------------------------------------------------------*/
134 /** @addtogroup APP_AES_DRIVER_FUNCTIONS Functions
135  * @{
136  */
137 
138 /**
139  ****************************************************************************************
140  * @brief Initialize the APP AES DRIVER according to the specified parameters
141  * in the app_aes_params_t and app_aes_evt_handler_t.
142  * @note If interrupt mode is set, you can use blocking mode. Conversely, if blocking mode
143  * is set, you can't use interrupt mode.
144  *
145  * @param[in] p_params: Pointer to app_aes_params_t parameter which contains the
146  * configuration information for the specified AES module.
147  * @param[in] evt_handler: AES user callback function.
148  *
149  * @return Result of initialization.
150  ****************************************************************************************
151  */
152 uint16_t app_aes_init(app_aes_params_t *p_params, app_aes_evt_handler_t evt_handler);
153 
154 /**
155  ****************************************************************************************
156  * @brief De-initialize the APP AES DRIVER peripheral.
157  *
158  * @return Result of De-initialization.
159  ****************************************************************************************
160  */
161 uint16_t app_aes_deinit(void);
162 
163 /**
164  ****************************************************************************************
165  * @brief Encrypted an amount of data in blocking mode.
166  *
167  * @param[in] p_plain_data: Pointer to plain data buffer.
168  * @param[in] number: Amount of data to be Encrypted in bytes
169  * @param[out] p_cypher_data: Pointer to cypher data buffer
170  * @param[in] timeout: Timeout duration
171  *
172  * @return Result of operation.
173  ****************************************************************************************
174  */
175 uint16_t app_aes_encrypt_sync(uint32_t *p_plain_data, uint32_t number, uint32_t *p_cypher_data, uint32_t timeout);
176 
177 /**
178  ****************************************************************************************
179  * @brief Decrypted an amount of data in blocking mode.
180  *
181  * @param[in] p_cypher_data: Pointer to cypher data buffer.
182  * @param[in] number: Amount of data to be decrypted in bytes
183  * @param[out] p_plain_data: Pointer to plain data buffer
184  * @param[in] timeout: Timeout duration
185  *
186  * @return Result of operation.
187  ****************************************************************************************
188  */
189 uint16_t app_aes_decrypt_sync(uint32_t *p_cypher_data, uint32_t number, uint32_t *p_plain_data, uint32_t timeout);
190 
191 /**
192  ****************************************************************************************
193  * @brief Encrypted an amount of data in non-blocking mode.
194  *
195  * @param[in] p_cypher_data: Pointer to cypher data buffer.
196  * @param[in] number: Amount of data to be decrypted in bytes
197  * @param[out] p_plain_data: Pointer to plain data buffer
198  *
199  * @return Result of operation.
200  ****************************************************************************************
201  */
202 uint16_t app_aes_encrypt_async(uint32_t *p_plain_data, uint32_t number, uint32_t *p_cypher_data);
203 
204 /**
205  ****************************************************************************************
206  * @brief Decrypted an amount of data in non-blocking mode.
207  *
208  * @param[in] p_cypher_data: Pointer to cypher data buffer.
209  * @param[in] number: Amount of data to be decrypted in bytes
210  * @param[out] p_plain_data: Pointer to plain data buffer
211  *
212  * @return Result of operation.
213  ****************************************************************************************
214  */
215 uint16_t app_aes_decrypt_async(uint32_t *p_cypher_data, uint32_t number, uint32_t *p_plain_data);
216 
217 /**
218  ****************************************************************************************
219  * @brief Return the AES handle.
220  *
221  * @return Pointer to the AES handle.
222  ****************************************************************************************
223  */
225 
226 #ifdef ENV_RTOS_USE_SEMP
227 /**
228  ****************************************************************************************
229  * @brief [RTOS] Decrypted an amount of data in non-blocking mode.
230  *
231  * @param[in] p_cypher_data: Pointer to cypher data buffer.
232  * @param[in] number: Amount of data to be decrypted in bytes
233  * @param[out] p_plain_data: Pointer to plain data buffer
234  *
235  * @return Result of operation.
236  ****************************************************************************************
237  */
238 uint16_t app_aes_decrypt_sem_sync(uint32_t *p_cypher_data, uint32_t number, uint32_t *p_plain_data);
239 
240 /**
241  ****************************************************************************************
242  * @brief [RTOS] Encrypted an amount of data in blocking mode.
243  *
244  * @param[in] p_plain_data: Pointer to plain data buffer.
245  * @param[in] number: Amount of data to be Encrypted in bytes
246  * @param[out] p_cypher_data: Pointer to cypher data buffer
247  *
248  * @return Result of operation.
249  ****************************************************************************************
250  */
251 uint16_t app_aes_encrypt_sem_sync(uint32_t *p_plain_data, uint32_t number, uint32_t *p_cypher_data);
252 #endif
253 
254 /** @} */
255 
256 #endif
257 
258 #ifdef __cplusplus
259 }
260 #endif
261 
262 #endif
263 
264 /** @} */
265 /** @} */
266 /** @} */
app_aes_type_t
app_aes_type_t
AES operating mode Enumerations definition.
Definition: app_aes.h:75
app_aes_mode_t
app_aes_mode_t
AES encryption and decryption mode Enumerations definition.
Definition: app_aes.h:86
app_aes_params_t
AES parameters structure definition.
Definition: app_aes.h:111
APP_AES_TYPE_POLLING
@ APP_AES_TYPE_POLLING
Polling operation mode.
Definition: app_aes.h:77
app_aes_evt_t
AES event structure definition.
Definition: app_aes.h:121
APP_AES_EVT_DONE
@ APP_AES_EVT_DONE
Encryption and decryption completed.
Definition: app_aes.h:98
APP_AES_TYPE_MAX
@ APP_AES_TYPE_MAX
Only for check parameter, not used as input parameters.
Definition: app_aes.h:79
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_init
AES Init Structure definition.
Definition: gr55xx_hal_aes.h:101
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:129
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:114
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_TYPE_INTERRUPT
@ APP_AES_TYPE_INTERRUPT
Interrupt operation mode.
Definition: app_aes.h:76
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.
APP_AES_MODE_MAX
@ APP_AES_MODE_MAX
Only for check parameter, not used as input parameters.
Definition: app_aes.h:89
app_aes_evt_t::type
app_aes_evt_type_t type
Type of event.
Definition: app_aes.h:122
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:96
app_aes_params_t::use_type
app_aes_type_t use_type
Specifies the operation mode of AES.
Definition: app_aes.h:112
_aes_handle
AES handle Structure definition.
Definition: gr55xx_hal_aes.h:130
gr55xx_hal.h
This file contains all the functions prototypes for the HAL module driver.
APP_AES_TYPE_DMA
@ APP_AES_TYPE_DMA
DMA operation mode.
Definition: app_aes.h:78
APP_AES_MODE_CBC
@ APP_AES_MODE_CBC
CBC encryption mode.
Definition: app_aes.h:88
APP_AES_MODE_ECB
@ APP_AES_MODE_ECB
ECB encryption mode.
Definition: app_aes.h:87
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_rtos_cfg.h
Header file of app rtos config code.
app_drv_error.h
Header file of app driver error code.
app_aes_params_t::use_mode
app_aes_mode_t use_mode
AES encryption mode.
Definition: app_aes.h:113
APP_AES_EVT_ERROR
@ APP_AES_EVT_ERROR
Error reported by AES peripheral.
Definition: app_aes.h:97
app_aes_evt_t::error_code
uint32_t error_code
AES Error code .
Definition: app_aes.h:123