gr55xx_hal_aes.h
Go to the documentation of this file.
1 /**
2  ****************************************************************************************
3  *
4  * @file gr55xx_hal_aes.h
5  * @author BLE Driver Team
6  * @brief Header file containing functions prototypes of AES HAL 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 HAL_DRIVER HAL Driver
43  * @{
44  */
45 
46 /** @defgroup HAL_AES AES
47  * @brief AES HAL module driver.
48  * @{
49  */
50 
51 /* Define to prevent recursive inclusion -------------------------------------*/
52 #ifndef __GR55xx_HAL_AES_H__
53 #define __GR55xx_HAL_AES_H__
54 
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 
59 /* Includes ------------------------------------------------------------------*/
60 #include "gr55xx_ll_aes.h"
61 #include "gr55xx_hal_def.h"
62 
63 /* Exported types ------------------------------------------------------------*/
64 /** @addtogroup HAL_AES_ENUMERATIONS Enumerations
65  * @{
66  */
67 
68 /** @defgroup HAL_AES_state HAL AES State
69  * @{
70  */
71 
72 /**
73  * @brief HAL AES State Enumerations definition
74  */
75 typedef enum
76 {
77  HAL_AES_STATE_RESET = 0x00, /**< Peripheral not initialized */
78  HAL_AES_STATE_READY = 0x01, /**< Peripheral initialized and ready for use */
79  HAL_AES_STATE_BUSY = 0x02, /**< Peripheral in indirect mode and busy */
80  HAL_AES_STATE_ERROR = 0x03, /**< Peripheral in error */
81  HAL_AES_STATE_TIMEOUT = 0x04, /**< Peripheral in timeout */
82  HAL_AES_STATE_SUSPENDED = 0x05, /**< Peripheral in suspended */
84 
85 /** @} */
86 
87 /** @} */
88 
89 /** @addtogroup HAL_AES_STRUCTURES Structures
90  * @{
91  */
92 
93 /** @defgroup AES_Configuration AES Configuration
94  * @{
95  */
96 
97 /**
98  * @brief AES Init Structure definition
99  */
100 typedef struct _aes_init
101 {
102  uint32_t key_size; /**< 128, 192 or 256-bits key length.
103  This parameter can be a value of @ref AES_Key_Size */
104 
105  uint32_t operation_mode; /**< AES operating mode.
106  This parameter can be a value of @ref AES_OPERATION_MODE */
107 
108  uint32_t chaining_mode; /**< AES chaining mode.
109  This parameter can be a value of @ref AES_CHAININGMODE */
110 
111  uint32_t *p_key; /**< Encryption/Decryption Key */
112 
113  uint32_t *p_init_vector; /**< Initialization Vector used for CBC modes */
114 
115  uint32_t dpa_mode; /**< DPA Mode */
116 
117  uint32_t *p_seed; /**< Random seeds */
118 
120 /** @} */
121 
122 /** @defgroup AES_handle AES Handle
123  * @{
124  */
125 
126 /**
127  * @brief AES handle Structure definition
128  */
129 typedef struct _aes_handle
130 {
131  aes_regs_t *p_instance; /**< AES registers base address */
132 
133  aes_init_t init; /**< AES operation parameters */
134 
135  uint32_t *p_cryp_input_buffer; /**< Pointer to CRYP processing (encryption or decryption) input buffer */
136 
137  uint32_t *p_cryp_output_buffer; /**< Pointer to CRYP processing (encryption or decryption) output buffer */
138 
139  uint32_t block_size; /**< Data size in blocks (16 bytes per block) */
140 
141  uint32_t block_count; /**< Blocks count */
142 
143  __IO hal_lock_t lock; /**< Locking object */
144 
145  __IO hal_aes_state_t state; /**< AES operation state */
146 
147  __IO uint32_t error_code; /**< AES Error code */
148 
149  uint32_t timeout; /**< Timeout for the AES operation */
150 
151  uint32_t retention[18]; /**< AES important register information. */
152 
154 /** @} */
155 
156 /** @} */
157 
158 /** @addtogroup HAL_AES_CALLBACK_STRUCTURES Callback Structures
159  * @{
160  */
161 
162 /** @defgroup AES_Callback AES Callback
163  * @{
164  */
165 
166 /**
167  * @brief HAL AES Callback function definition
168  */
169 typedef struct _hal_aes_callback
170 {
171  void (*aes_msp_init)(aes_handle_t *p_aes); /**< AES init MSP callback */
172  void (*aes_msp_deinit)(aes_handle_t *p_aes); /**< AES de-init MSP callback */
173  void (*aes_error_callback)(aes_handle_t *p_aes); /**< AES error callback */
174  void (*aes_done_callback)(aes_handle_t *p_aes); /**< AES encrypt or decrypt done callback */
175  void (*aes_abort_cplt_callback)(aes_handle_t *p_aes); /**< AES abort complete callback */
177 
178 /** @} */
179 
180 /** @} */
181 
182 /**
183  * @defgroup HAL_AES_MACRO Defines
184  * @{
185  */
186 
187 /* Exported constants --------------------------------------------------------*/
188 /** @defgroup AES_Exported_Constants AES Exported Constants
189  * @{
190  */
191 
192 /** @defgroup AES_Error_Code AES Error Code
193  * @{
194  */
195 #define HAL_AES_ERROR_NONE ((uint32_t)0x00000000) /**< No error */
196 #define HAL_AES_ERROR_TIMEOUT ((uint32_t)0x00000001) /**< Timeout error */
197 #define HAL_AES_ERROR_TRANSFER ((uint32_t)0x00000002) /**< Transfer error */
198 #define HAL_AES_ERROR_INVALID_PARAM ((uint32_t)0x00000004) /**< Invalid parameters error */
199 /** @} */
200 
201 /** @defgroup AES_Key_Size AES Key Size
202  * @{
203  */
204 #define AES_KEYSIZE_128BITS LL_AES_KEY_SIZE_128 /**< 128 bits */
205 #define AES_KEYSIZE_192BITS LL_AES_KEY_SIZE_192 /**< 192 bits */
206 #define AES_KEYSIZE_256BITS LL_AES_KEY_SIZE_256 /**< 256 bits */
207 /** @} */
208 
209 /** @defgroup AES_Block_Size AES Block Size
210  * @{
211  */
212 #define AES_BLOCK_MAX (2048) /**< Block max size */
213 #define AES_BLOCKSIZE_BITS (128) /**< Block size in bits */
214 #define AES_BLOCKSIZE_BYTES (AES_BLOCKSIZE_BITS >> 3) /**< Block size in bytes */
215 #define AES_BLOCKSIZE_WORDS (AES_BLOCKSIZE_BYTES >> 2) /**< Block size in words */
216 /** @} */
217 
218 /** @defgroup AES_OPERATION_MODE AES Operation Mode
219  * @{
220  */
221 #define AES_OPERATION_MODE_ENCRYPT (1) /**< Encrypt operation mode */
222 #define AES_OPERATION_MODE_DECRYPT (0) /**< Decrypt operation mode */
223 /** @} */
224 
225 /** @defgroup AES_CHAININGMODE AES Chaining Mode
226  * @{
227  */
228 #define AES_CHAININGMODE_ECB LL_AES_OPERATION_MODE_ECB /**< ECB chaining mode */
229 #define AES_CHAININGMODE_CBC LL_AES_OPERATION_MODE_CBC /**< CBC chaining mode */
230 /** @} */
231 
232 /** @defgroup AES_Flags_definition AES Flags Definition
233  * @{
234  */
235 #define AES_FLAG_DATAREADY LL_AES_FLAG_DATAREADY /**< Data ready flag */
236 #define AES_FLAG_DMA_DONE LL_AES_FLAG_DMA_DONE /**< DMA transfer done flag */
237 #define AES_FLAG_DMA_ERR LL_AES_FLAG_DMA_ERR /**< DMA transfer error flag */
238 #define AES_FLAG_KEY_VALID LL_AES_FLAG_KEY_VALID /**< Key valid flag */
239 /** @} */
240 
241 /** @defgroup AES_Interrupt_definition AES Interrupt definition
242  * @{
243  */
244 #define AES_IT_DONE ((uint32_t)0x00000001) /**< AES Encrypted or Decrypted Data Done Interrupt source */
245 /** @} */
246 
247 /** @defgroup AES_Timeout_definition AES Timeout definition
248  * @{
249  */
250 #define HAL_AES_TIMEOUT_DEFAULT_VALUE ((uint32_t)5000) /**< 5s */
251 /** @} */
252 
253 /** @} */
254 
255 /* Exported macro ------------------------------------------------------------*/
256 /** @defgroup AES_Exported_Macros AES Exported Macros
257  * @{
258  */
259 
260 /** @brief Reset AES handle states.
261  * @param __HANDLE__ AES handle.
262  * @retval None
263  */
264 #define __HAL_AES_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->state = HAL_AES_STATE_RESET)
265 
266 /** @brief Enable the specified AES peripheral.
267  * @param __HANDLE__ Specifies the AES Handle.
268  * @retval None
269  */
270 #define __HAL_AES_ENABLE(__HANDLE__) SET_BITS((__HANDLE__)->p_instance->CTRL, AES_CTRL_MODULE_EN)
271 /** @brief Disable the specified AES peripheral.
272  * @param __HANDLE__ Specifies the AES Handle.
273  * @retval None
274  */
275 #define __HAL_AES_DISABLE(__HANDLE__) CLEAR_BITS((__HANDLE__)->p_instance->CTRL, AES_CTRL_MODULE_EN)
276 /** @brief Enable the AES interrupt.
277  * @param __HANDLE__ Specifies the AES Handle.
278  * @retval None
279  */
280 #define __HAL_AES_ENABLE_IT(__HANDLE__) ll_aes_enable_it_done((__HANDLE__)->p_instance)
281 
282 /** @brief Disable the AES interrupt.
283  * @param __HANDLE__ Specifies the AES Handle.
284  * @retval None
285  */
286 #define __HAL_AES_DISABLE_IT(__HANDLE__) ll_aes_disable_it_done((__HANDLE__)->p_instance)
287 
288 /** @brief Check whether the specified AES interrupt flag is set or not.
289  * @param __HANDLE__ Specifies the AES Handle.
290  * @param __FLAG__ Specifies the interrupt flag to check.
291  * This parameter can be the following value:
292  * @arg @ref AES_IT_DONE Encrypted or Decrypted Data Done Interrupt
293  * @retval The new state of __FLAG__ (TRUE or FALSE).
294  */
295 #define __HAL_AES_GET_FLAG_IT(__HANDLE__, __FLAG__) (READ_BITS((__HANDLE__)->p_instance->INT, (__FLAG__)) == (__FLAG__))
296 /** @brief Clear the specified AES interrupt flag.
297  * @param __HANDLE__ Specifies the AES interrupt Handle.
298  * @param __FLAG__ Specifies the flag to clear.
299  * This parameter can be the following value:
300  * @arg @ref AES_IT_DONE Encrypted or Decrypted Data Done Interrupt
301  * @retval None
302  */
303 #define __HAL_AES_CLEAR_FLAG_IT(__HANDLE__, __FLAG__) SET_BITS((__HANDLE__)->p_instance->INT, (__FLAG__))
304 /** @brief Check whether the specified AES flag is set or not.
305  * @param __HANDLE__ Specifies the AES Handle.
306  * @param __FLAG__ Specifies the flag to check.
307  * This parameter can be one of the following values:
308  * @arg @ref AES_FLAG_DATAREADY Data ready flag
309  * @arg @ref AES_FLAG_DMA_DONE DMA transfer done flag
310  * @arg @ref AES_FLAG_DMA_ERR DMA transfer error flag
311  * @arg @ref AES_FLAG_KEY_VALID Key valid flag
312  * @retval The new state of __FLAG__ (TRUE or FALSE).
313  */
314 #define __HAL_AES_GET_FLAG(__HANDLE__, __FLAG__) ((READ_BITS((__HANDLE__)->p_instance->STAT, (__FLAG__)) != 0) ? SET : RESET)
315 /** @} */
316 
317 /* Private macros ------------------------------------------------------------*/
318 /** @defgroup AES_Private_Macro AES Private Macros
319  * @{
320  */
321 
322 /** @brief Check if AES Key Size is valid.
323  * @param __SIZE__ AES Key Size.
324  * @retval SET (__SIZE__ is valid) or RESET (__SIZE__ is invalid)
325  */
326 #define IS_AES_KEY_SIZE(__SIZE__) (((__SIZE__) == AES_KEYSIZE_128BITS) || \
327  ((__SIZE__) == AES_KEYSIZE_192BITS) || \
328  ((__SIZE__) == AES_KEYSIZE_256BITS))
329 
330 /** @brief Check if AES Operation Mode is valid.
331  * @param __MODE__ AES Operation Mode.
332  * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
333  */
334 #define IS_AES_OPERATION_MODE(__MODE__) (((__MODE__) == AES_OPERATION_MODE_ENCRYPT) || \
335  ((__MODE__) == AES_OPERATION_MODE_DECRYPT))
336 
337 /** @brief Check if AES Chaining Mode is valid.
338  * @param __MODE__ AES Chaining Mode.
339  * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
340  */
341 #define IS_AES_CHAININGMODE(__MODE__) (((__MODE__) == AES_CHAININGMODE_ECB) || \
342  ((__MODE__) == AES_CHAININGMODE_CBC))
343 
344 /** @} */
345 
346 /** @} */
347 
348 /* Exported functions --------------------------------------------------------*/
349 /** @addtogroup HAL_AES_DRIVER_FUNCTIONS Functions
350  * @{
351  */
352 
353 /** @addtogroup AES_Exported_Functions_Group1 Initialization and de-initialization functions
354  * @brief Initialization and Configuration functions
355  *
356 @verbatim
357  ===============================================================================
358  ##### Initialization and de-initialization functions #####
359  ===============================================================================
360  [..] This subsection provides a set of functions allowing to initialize and
361  de-initialize the AESx peripheral:
362 
363  (+) User must implement hal_aes_msp_init() function in which he configures
364  all related peripherals resources (GPIO, DMA, IT and NVIC ).
365 
366  (+) Call the function hal_aes_init() to configure the selected device with
367  the selected configuration:
368  (++) Key Size
369  (++) operation_mode
370  (++) ChainingMode
371  (++) key
372  (++) init_vector
373  (++) DPAMode
374  (++) Seed
375 
376  (+) Call the function hal_aes_deinit() to restore the default configuration
377  of the selected AESx peripheral.
378 
379 @endverbatim
380  * @{
381  */
382 
383 /**
384  ****************************************************************************************
385  * @brief Initialize the AES according to the specified parameters
386  * in the aes_init_t and initialize the associated handle.
387  *
388  * @param[in] p_aes: Pointer to an AES handle which contains the configuration
389  * information for the specified AES module.
390  *
391  * @retval ::HAL_OK: Operation is OK.
392  * @retval ::HAL_ERROR: Parameter error or operation not supported.
393  * @retval ::HAL_BUSY: Driver is busy.
394  * @retval ::HAL_TIMEOUT: Timeout occurred.
395  ****************************************************************************************
396  */
398 
399 /**
400  ****************************************************************************************
401  * @brief De-initialize the AES peripheral.
402  *
403  * @param[in] p_aes: Pointer to an AES handle which contains the configuration
404  * information for the specified AES module.
405  *
406  * @retval ::HAL_OK: Operation is OK.
407  * @retval ::HAL_ERROR: Parameter error or operation not supported.
408  * @retval ::HAL_BUSY: Driver is busy.
409  * @retval ::HAL_TIMEOUT: Timeout occurred.
410  ****************************************************************************************
411  */
413 
414 /**
415  ****************************************************************************************
416  * @brief Initialize the AES MSP.
417  *
418  * @note This function should not be modified. When the callback is needed,
419  * the hal_aes_msp_deinit can be implemented in the user file.
420  *
421  * @param[in] p_aes: Pointer to an AES handle which contains the configuration
422  * information for the specified AES module.
423  ****************************************************************************************
424  */
426 
427 /**
428  ****************************************************************************************
429  * @brief De-initialize the AES MSP.
430  *
431  * @note This function should not be modified. When the callback is needed,
432  * the hal_aes_msp_deinit can be implemented in the user file.
433  *
434  * @param[in] p_aes: Pointer to an AES handle which contains the configuration
435  * information for the specified AES module.
436  ****************************************************************************************
437  */
439 
440 /** @} */
441 
442 /** @addtogroup AES_Exported_Functions_Group2 IO operation functions
443  * @brief AES Encrypt/Decrypt functions
444  *
445 @verbatim
446  ===============================================================================
447  ##### IO operation functions #####
448  ===============================================================================
449  This subsection provides a set of functions allowing to manage the AES encrypt or decrypt.
450 
451  (#) There are two mode of transfer:
452  (++) Blocking mode: The communication is performed in polling mode.
453  The HAL status of all data processing are returned by the same function
454  after finishing transfer.
455  (++) Non-Blocking mode: The communication is performed using Interrupts
456  or DMA. These API return the HAL status.
457  The end of the data processing will be indicated through the
458  dedicated AES IRQ when using Interrupt mode or the DMA IRQ when
459  using DMA mode.
460  The hal_aes_done_callback() user callbacks will be executed respectively
461  at the end of the encrypt or decrypt process
462  The hal_aes_error_callback() user callback will be executed when a error is detected
463 
464  (#) Blocking mode API's are :
465  (++) hal_aes_ecb_encrypt()
466  (++) hal_aes_ecb_decrypt()
467  (++) hal_aes_cbc_encrypt()
468  (++) hal_aes_cbc_decrypt()
469 
470  (#) Non-Blocking mode API's with Interrupt are :
471  (++) hal_aes_ecb_encrypt_it()
472  (++) hal_aes_ecb_decrypt_it()
473  (++) hal_aes_cbc_encrypt_it()
474  (++) hal_aes_cbc_decrypt_it()
475 
476  (#) Non-Blocking mode API's with DMA are :
477  (++) hal_aes_ecb_encrypt_dma()
478  (++) hal_aes_ecb_decrypt_dma()
479  (++) hal_aes_cbc_encrypt_dma()
480  (++) hal_aes_cbc_decrypt_dma()
481 
482  (#) A set of encrypt or decrypt Callbacks are provided in Non_Blocking mode:
483  (++) hal_aes_done_callback()
484  (++) hal_aes_error_callback()
485 
486  (#) Non-Blocking mode transfers could be aborted using Abort API's :
487  (++) hal_aes_abort()
488  (++) hal_aes_abort_it()
489 
490  (#) For Abort services based on interrupts (hal_aes_abort_xxx_it), Abort Complete Callback is provided:
491  (++) hal_aes_abort_cplt_callback()
492 
493 @endverbatim
494  * @{
495  */
496 
497 /**
498  ****************************************************************************************
499  * @brief Encrypted an amount of data in blocking mode in ECB mode.
500  *
501  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
502  * the specified AES module.
503  * @param[in] p_plain_data: Pointer to plain data buffer
504  * @param[in] number: Amount of data to be decrypted in bytes
505  * @param[out] p_cypher_data: Pointer to cypher data buffer
506  * @param[in] timeout: Timeout duration
507  *
508  * @retval ::HAL_OK: Operation is OK.
509  * @retval ::HAL_ERROR: Parameter error or operation not supported.
510  * @retval ::HAL_BUSY: Driver is busy.
511  * @retval ::HAL_TIMEOUT: Timeout occurred.
512  ****************************************************************************************
513  */
514 hal_status_t hal_aes_ecb_encrypt(aes_handle_t *p_aes, uint32_t *p_plain_data, uint32_t number, uint32_t *p_cypher_data, uint32_t timeout);
515 
516 /**
517  ****************************************************************************************
518  * @brief Decrypted an amount of data in blocking mode in ECB mode.
519  *
520  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
521  * the specified AES module.
522  * @param[in] p_cypher_data: Pointer to cypher data buffer
523  * @param[in] number: Amount of data to be decrypted in bytes
524  * @param[out] p_plain_data: Pointer to plain data buffer
525  * @param[in] timeout: Timeout duration
526  *
527  * @retval ::HAL_OK: Operation is OK.
528  * @retval ::HAL_ERROR: Parameter error or operation not supported.
529  * @retval ::HAL_BUSY: Driver is busy.
530  * @retval ::HAL_TIMEOUT: Timeout occurred.
531  ****************************************************************************************
532  */
533 hal_status_t hal_aes_ecb_decrypt(aes_handle_t *p_aes, uint32_t *p_cypher_data, uint32_t number, uint32_t *p_plain_data, uint32_t timeout);
534 
535 /**
536  ****************************************************************************************
537  * @brief Encrypted an amount of data in blocking mode in CBC mode.
538  *
539  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
540  * the specified AES module.
541  * @param[in] p_plain_data: Pointer to plain data buffer
542  * @param[in] number: Amount of data to be decrypted in bytes
543  * @param[out] p_cypher_data: Pointer to cypher data buffer
544  * @param[in] timeout: Timeout duration
545  *
546  * @retval ::HAL_OK: Operation is OK.
547  * @retval ::HAL_ERROR: Parameter error or operation not supported.
548  * @retval ::HAL_BUSY: Driver is busy.
549  * @retval ::HAL_TIMEOUT: Timeout occurred.
550  ****************************************************************************************
551  */
552 hal_status_t hal_aes_cbc_encrypt(aes_handle_t *p_aes, uint32_t *p_plain_data, uint32_t number, uint32_t *p_cypher_data, uint32_t timeout);
553 
554 /**
555  ****************************************************************************************
556  * @brief Decrypted an amount of data in blocking mode in CBC mode.
557  *
558  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
559  * the specified AES module.
560  * @param[in] p_cypher_data: Pointer to cypher data buffer
561  * @param[in] number: Amount of data to be decrypted in bytes
562  * @param[out] p_plain_data: Pointer to plain data buffer
563  * @param[in] timeout: Timeout duration
564  *
565  * @retval ::HAL_OK: Operation is OK.
566  * @retval ::HAL_ERROR: Parameter error or operation not supported.
567  * @retval ::HAL_BUSY: Driver is busy.
568  * @retval ::HAL_TIMEOUT: Timeout occurred.
569  ****************************************************************************************
570  */
571 hal_status_t hal_aes_cbc_decrypt(aes_handle_t *p_aes, uint32_t *p_cypher_data, uint32_t number, uint32_t *p_plain_data, uint32_t timeout);
572 
573 /**
574  ****************************************************************************************
575  * @brief Encrypted an amount of data in non-blocking mode with Interrupt in ECB mode.
576  *
577  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
578  * the specified AES module.
579  * @param[in] p_plain_data: Pointer to plain data buffer
580  * @param[in] number: Amount of data to be decrypted in bytes
581  * @param[out] p_cypher_data: Pointer to cypher data buffer
582  *
583  * @retval ::HAL_OK: Operation is OK.
584  * @retval ::HAL_ERROR: Parameter error or operation not supported.
585  * @retval ::HAL_BUSY: Driver is busy.
586  * @retval ::HAL_TIMEOUT: Timeout occurred.
587  ****************************************************************************************
588  */
589 hal_status_t hal_aes_ecb_encrypt_it(aes_handle_t *p_aes, uint32_t *p_plain_data, uint32_t number, uint32_t *p_cypher_data);
590 
591 /**
592  ****************************************************************************************
593  * @brief Decrypted an amount of data in non-blocking mode with Interrupt in ECB mode.
594  *
595  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
596  * the specified AES module.
597  * @param[in] p_cypher_data: Pointer to cypher data buffer
598  * @param[in] number: Amount of data to be decrypted in bytes
599  * @param[out] p_plain_data: Pointer to plain data buffer
600  *
601  * @retval ::HAL_OK: Operation is OK.
602  * @retval ::HAL_ERROR: Parameter error or operation not supported.
603  * @retval ::HAL_BUSY: Driver is busy.
604  * @retval ::HAL_TIMEOUT: Timeout occurred.
605  ****************************************************************************************
606  */
607 hal_status_t hal_aes_ecb_decrypt_it(aes_handle_t *p_aes, uint32_t *p_cypher_data, uint32_t number, uint32_t *p_plain_data);
608 
609 /**
610  ****************************************************************************************
611  * @brief Encrypted an amount of data in non-blocking mode with Interrupt in CBC mode.
612  *
613  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
614  * the specified AES module.
615  * @param[in] p_plain_data: Pointer to plain data buffer
616  * @param[in] number: Amount of data to be decrypted in bytes
617  * @param[out] p_cypher_data: Pointer to cypher data buffer
618  *
619  * @retval ::HAL_OK: Operation is OK.
620  * @retval ::HAL_ERROR: Parameter error or operation not supported.
621  * @retval ::HAL_BUSY: Driver is busy.
622  * @retval ::HAL_TIMEOUT: Timeout occurred.
623  ****************************************************************************************
624  */
625 hal_status_t hal_aes_cbc_encrypt_it(aes_handle_t *p_aes, uint32_t *p_plain_data, uint32_t number, uint32_t *p_cypher_data);
626 
627 /**
628  ****************************************************************************************
629  * @brief Decrypted an amount of data in non-blocking mode with Interrupt in CBC mode.
630  *
631  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
632  * the specified AES module.
633  * @param[in] p_cypher_data: Pointer to cypher data buffer
634  * @param[in] number: Amount of data to be decrypted in bytes
635  * @param[out] p_plain_data: Pointer to plain data buffer
636  *
637  * @retval ::HAL_OK: Operation is OK.
638  * @retval ::HAL_ERROR: Parameter error or operation not supported.
639  * @retval ::HAL_BUSY: Driver is busy.
640  * @retval ::HAL_TIMEOUT: Timeout occurred.
641  ****************************************************************************************
642  */
643 hal_status_t hal_aes_cbc_decrypt_it(aes_handle_t *p_aes, uint32_t *p_cypher_data, uint32_t number, uint32_t *p_plain_data);
644 
645 /**
646  ****************************************************************************************
647  * @brief Encrypted an amount of data in non-blocking mode with DMA in ECB mode.
648  *
649  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
650  * the specified AES module.
651  * @param[in] p_plain_data: Pointer to plain data buffer
652  * @param[in] number: Amount of data to be decrypted in bytes
653  * @param[out] p_cypher_data: Pointer to cypher data buffer
654  *
655  * @retval ::HAL_OK: Operation is OK.
656  * @retval ::HAL_ERROR: Parameter error or operation not supported.
657  * @retval ::HAL_BUSY: Driver is busy.
658  * @retval ::HAL_TIMEOUT: Timeout occurred.
659  ****************************************************************************************
660  */
661 hal_status_t hal_aes_ecb_encrypt_dma(aes_handle_t *p_aes, uint32_t *p_plain_data, uint32_t number, uint32_t *p_cypher_data);
662 
663 /**
664  ****************************************************************************************
665  * @brief Decrypted an amount of data in non-blocking mode with DMA in ECB mode.
666  *
667  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
668  * the specified AES module.
669  * @param[in] p_cypher_data: Pointer to cypher data buffer
670  * @param[in] number: Amount of data to be decrypted in bytes
671  * @param[out] p_plain_data: Pointer to plain data buffer
672  *
673  * @retval ::HAL_OK: Operation is OK.
674  * @retval ::HAL_ERROR: Parameter error or operation not supported.
675  * @retval ::HAL_BUSY: Driver is busy.
676  * @retval ::HAL_TIMEOUT: Timeout occurred.
677  ****************************************************************************************
678  */
679 hal_status_t hal_aes_ecb_decrypt_dma(aes_handle_t *p_aes, uint32_t *p_cypher_data, uint32_t number, uint32_t *p_plain_data);
680 
681 /**
682  ****************************************************************************************
683  * @brief Encrypted an amount of data in non-blocking mode with DMA in CBC mode.
684  *
685  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
686  * the specified AES module.
687  * @param[in] p_plain_data: Pointer to plain data buffer
688  * @param[in] number: Amount of data to be decrypted in bytes
689  * @param[out] p_cypher_data: Pointer to cypher data buffer
690  *
691  * @retval ::HAL_OK: Operation is OK.
692  * @retval ::HAL_ERROR: Parameter error or operation not supported.
693  * @retval ::HAL_BUSY: Driver is busy.
694  * @retval ::HAL_TIMEOUT: Timeout occurred.
695  ****************************************************************************************
696  */
697 hal_status_t hal_aes_cbc_encrypt_dma(aes_handle_t *p_aes, uint32_t *p_plain_data, uint32_t number, uint32_t *p_cypher_data);
698 
699 /**
700  ****************************************************************************************
701  * @brief Decrypted an amount of data in non-blocking mode with DMA in CBC mode.
702  *
703  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
704  * the specified AES module.
705  * @param[in] p_cypher_data: Pointer to cypher data buffer
706  * @param[in] number: Amount of data to be decrypted in bytes
707  * @param[out] p_plain_data: Pointer to plain data buffer
708  *
709  * @retval ::HAL_OK: Operation is OK.
710  * @retval ::HAL_ERROR: Parameter error or operation not supported.
711  * @retval ::HAL_BUSY: Driver is busy.
712  * @retval ::HAL_TIMEOUT: Timeout occurred.
713  ****************************************************************************************
714  */
715 hal_status_t hal_aes_cbc_decrypt_dma(aes_handle_t *p_aes, uint32_t *p_cypher_data, uint32_t number, uint32_t *p_plain_data);
716 
717 /** @} */
718 
719 /** @addtogroup AES_IRQ_Handler_and_Callbacks IRQ Handler and Callbacks
720  * @brief IRQ Handler and Callbacks functions
721  * @{
722  */
723 
724 /**
725  ****************************************************************************************
726  * @brief Handle AES interrupt request.
727  *
728  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
729  * the specified the specified AES module.
730  ****************************************************************************************
731  */
733 
734 /**
735  ****************************************************************************************
736  * @brief Encrypt or decrypt Done callback.
737  *
738  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
739  * the specified AES module.
740  ****************************************************************************************
741  */
743 
744 /**
745  ****************************************************************************************
746  * @brief AES error callback.
747  *
748  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
749  * the specified AES module.
750  ****************************************************************************************
751  */
753 
754 /**
755  ****************************************************************************************
756  * @brief AES Abort Complete callback.
757  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
758  * the specified AES module.
759  ****************************************************************************************
760  */
762 
763 /** @} */
764 
765 /** @defgroup AES_Exported_Functions_Group3 Peripheral State and Errors functions
766  * @brief AES control functions
767  *
768 @verbatim
769  ===============================================================================
770  ##### Peripheral State and Errors functions #####
771  ===============================================================================
772  [..]
773  This subsection provides a set of functions allowing to control the AES.
774  (+) hal_aes_get_state() API can be helpful to check in run-time the state of the AES peripheral.
775  (+) hal_aes_get_error() check in run-time Errors occurring during communication.
776  (+) hal_aes_set_timeout() set the timeout during internal process.
777 @endverbatim
778  * @{
779  */
780 
781 /**
782  ****************************************************************************************
783  * @brief Return the AES handle state.
784  *
785  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
786  * the specified AES module.
787  *
788  * @retval ::HAL_AES_STATE_RESET: Peripheral not initialized.
789  * @retval ::HAL_AES_STATE_READY: Peripheral initialized and ready for use.
790  * @retval ::HAL_AES_STATE_BUSY: Peripheral in indirect mode and busy.
791  * @retval ::HAL_AES_STATE_ERROR: Peripheral in error.
792  * @retval ::HAL_AES_STATE_TIMEOUT: Peripheral in timeout.
793  * @retval ::HAL_AES_STATE_SUSPENDED: Peripheral in suspended.
794  ****************************************************************************************
795  */
797 
798 /**
799  ****************************************************************************************
800  * @brief Return the AES error code.
801  *
802  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
803  * the specified AES module.
804  *
805  * @return AES error code in bitmap format
806  ****************************************************************************************
807  */
809 
810 /**
811  ****************************************************************************************
812  * @brief Set the AES internal process timeout value.
813  *
814  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
815  * the specified AES module.
816  * @param[in] timeout: Internal process timeout value.
817  ****************************************************************************************
818  */
819 void hal_aes_set_timeout(aes_handle_t *p_aes, uint32_t timeout);
820 
821 /**
822  ****************************************************************************************
823  * @brief Suspend some registers related to AES configuration before sleep.
824  * @param[in] p_aes: Pointer to a AES handle which contains the configuration
825  * information for the specified AES module.
826  * @retval ::HAL_OK: Operation is OK.
827  * @retval ::HAL_ERROR: Parameter error or operation not supported.
828  * @retval ::HAL_BUSY: Driver is busy.
829  * @retval ::HAL_TIMEOUT: Timeout occurred.
830  ****************************************************************************************
831  */
833 
834 /**
835  ****************************************************************************************
836  * @brief Restore some registers related to AES configuration after sleep.
837  * This function must be used in conjunction with the hal_aes_suspend_reg().
838  * @param[in] p_aes: Pointer to a AES handle which contains the configuration
839  * information for the specified AES module.
840  * @retval ::HAL_OK: Operation is OK.
841  * @retval ::HAL_ERROR: Parameter error or operation not supported.
842  * @retval ::HAL_BUSY: Driver is busy.
843  * @retval ::HAL_TIMEOUT: Timeout occurred.
844  ****************************************************************************************
845  */
847 
848 /** @} */
849 
850 /** @} */
851 
852 #ifdef __cplusplus
853 }
854 #endif
855 
856 #endif /* __GR55xx_HAL_AES_H__ */
857 
858 /** @} */
859 
860 /** @} */
861 
862 /** @} */
hal_aes_msp_deinit
void hal_aes_msp_deinit(aes_handle_t *p_aes)
De-initialize the AES MSP.
hal_aes_abort_cplt_callback
void hal_aes_abort_cplt_callback(aes_handle_t *p_aes)
AES Abort Complete callback.
_hal_aes_callback::aes_msp_deinit
void(* aes_msp_deinit)(aes_handle_t *p_aes)
Definition: gr55xx_hal_aes.h:172
hal_lock_t
hal_lock_t
HAL Lock structures definition.
Definition: gr55xx_hal_def.h:81
HAL_AES_STATE_RESET
@ HAL_AES_STATE_RESET
Definition: gr55xx_hal_aes.h:77
_hal_aes_callback::aes_msp_init
void(* aes_msp_init)(aes_handle_t *p_aes)
Definition: gr55xx_hal_aes.h:171
_hal_aes_callback::aes_done_callback
void(* aes_done_callback)(aes_handle_t *p_aes)
Definition: gr55xx_hal_aes.h:174
hal_aes_ecb_encrypt_it
hal_status_t hal_aes_ecb_encrypt_it(aes_handle_t *p_aes, uint32_t *p_plain_data, uint32_t number, uint32_t *p_cypher_data)
Encrypted an amount of data in non-blocking mode with Interrupt in ECB mode.
_aes_init::p_seed
uint32_t * p_seed
Definition: gr55xx_hal_aes.h:117
hal_aes_suspend_reg
hal_status_t hal_aes_suspend_reg(aes_handle_t *p_aes)
Suspend some registers related to AES configuration before sleep.
_aes_handle::block_count
uint32_t block_count
Definition: gr55xx_hal_aes.h:141
_aes_init::p_key
uint32_t * p_key
Definition: gr55xx_hal_aes.h:111
hal_aes_get_error
uint32_t hal_aes_get_error(aes_handle_t *p_aes)
Return the AES error code.
aes_handle_t
struct _aes_handle aes_handle_t
AES handle Structure definition.
_aes_handle::lock
__IO hal_lock_t lock
Definition: gr55xx_hal_aes.h:143
HAL_AES_STATE_TIMEOUT
@ HAL_AES_STATE_TIMEOUT
Definition: gr55xx_hal_aes.h:81
hal_aes_callback_t
struct _hal_aes_callback hal_aes_callback_t
HAL AES Callback function definition.
hal_aes_ecb_encrypt
hal_status_t hal_aes_ecb_encrypt(aes_handle_t *p_aes, uint32_t *p_plain_data, uint32_t number, uint32_t *p_cypher_data, uint32_t timeout)
Encrypted an amount of data in blocking mode in ECB mode.
hal_aes_msp_init
void hal_aes_msp_init(aes_handle_t *p_aes)
Initialize the AES MSP.
_aes_handle::error_code
__IO uint32_t error_code
Definition: gr55xx_hal_aes.h:147
hal_aes_cbc_encrypt_dma
hal_status_t hal_aes_cbc_encrypt_dma(aes_handle_t *p_aes, uint32_t *p_plain_data, uint32_t number, uint32_t *p_cypher_data)
Encrypted an amount of data in non-blocking mode with DMA in CBC mode.
hal_aes_set_timeout
void hal_aes_set_timeout(aes_handle_t *p_aes, uint32_t timeout)
Set the AES internal process timeout value.
hal_aes_resume_reg
hal_status_t hal_aes_resume_reg(aes_handle_t *p_aes)
Restore some registers related to AES configuration after sleep. This function must be used in conjun...
gr55xx_ll_aes.h
Header file containing functions prototypes of AES LL library.
hal_aes_init
hal_status_t hal_aes_init(aes_handle_t *p_aes)
Initialize the AES according to the specified parameters in the aes_init_t and initialize the associa...
hal_aes_irq_handler
void hal_aes_irq_handler(aes_handle_t *p_aes)
Handle AES interrupt request.
_aes_handle::retention
uint32_t retention[18]
Definition: gr55xx_hal_aes.h:151
hal_aes_cbc_encrypt_it
hal_status_t hal_aes_cbc_encrypt_it(aes_handle_t *p_aes, uint32_t *p_plain_data, uint32_t number, uint32_t *p_cypher_data)
Encrypted an amount of data in non-blocking mode with Interrupt in CBC mode.
hal_aes_get_state
hal_aes_state_t hal_aes_get_state(aes_handle_t *p_aes)
Return the AES handle state.
HAL_AES_STATE_READY
@ HAL_AES_STATE_READY
Definition: gr55xx_hal_aes.h:78
_aes_init::p_init_vector
uint32_t * p_init_vector
Definition: gr55xx_hal_aes.h:113
_aes_init
AES Init Structure definition.
Definition: gr55xx_hal_aes.h:101
_aes_handle::state
__IO hal_aes_state_t state
Definition: gr55xx_hal_aes.h:145
hal_aes_cbc_decrypt
hal_status_t hal_aes_cbc_decrypt(aes_handle_t *p_aes, uint32_t *p_cypher_data, uint32_t number, uint32_t *p_plain_data, uint32_t timeout)
Decrypted an amount of data in blocking mode in CBC mode.
aes_init_t
struct _aes_init aes_init_t
AES Init Structure definition.
hal_aes_ecb_decrypt
hal_status_t hal_aes_ecb_decrypt(aes_handle_t *p_aes, uint32_t *p_cypher_data, uint32_t number, uint32_t *p_plain_data, uint32_t timeout)
Decrypted an amount of data in blocking mode in ECB mode.
_hal_aes_callback::aes_abort_cplt_callback
void(* aes_abort_cplt_callback)(aes_handle_t *p_aes)
Definition: gr55xx_hal_aes.h:175
hal_aes_ecb_encrypt_dma
hal_status_t hal_aes_ecb_encrypt_dma(aes_handle_t *p_aes, uint32_t *p_plain_data, uint32_t number, uint32_t *p_cypher_data)
Encrypted an amount of data in non-blocking mode with DMA in ECB mode.
_aes_handle::init
aes_init_t init
Definition: gr55xx_hal_aes.h:133
_hal_aes_callback
HAL AES Callback function definition.
Definition: gr55xx_hal_aes.h:170
_aes_handle::timeout
uint32_t timeout
Definition: gr55xx_hal_aes.h:149
_aes_handle::p_instance
aes_regs_t * p_instance
Definition: gr55xx_hal_aes.h:131
HAL_AES_STATE_ERROR
@ HAL_AES_STATE_ERROR
Definition: gr55xx_hal_aes.h:80
hal_status_t
hal_status_t
HAL Status structures definition.
Definition: gr55xx_hal_def.h:70
_aes_handle
AES handle Structure definition.
Definition: gr55xx_hal_aes.h:130
hal_aes_cbc_decrypt_dma
hal_status_t hal_aes_cbc_decrypt_dma(aes_handle_t *p_aes, uint32_t *p_cypher_data, uint32_t number, uint32_t *p_plain_data)
Decrypted an amount of data in non-blocking mode with DMA in CBC mode.
hal_aes_deinit
hal_status_t hal_aes_deinit(aes_handle_t *p_aes)
De-initialize the AES peripheral.
_aes_init::dpa_mode
uint32_t dpa_mode
Definition: gr55xx_hal_aes.h:115
_aes_init::operation_mode
uint32_t operation_mode
Definition: gr55xx_hal_aes.h:105
_aes_init::key_size
uint32_t key_size
Definition: gr55xx_hal_aes.h:102
_aes_handle::block_size
uint32_t block_size
Definition: gr55xx_hal_aes.h:139
hal_aes_ecb_decrypt_dma
hal_status_t hal_aes_ecb_decrypt_dma(aes_handle_t *p_aes, uint32_t *p_cypher_data, uint32_t number, uint32_t *p_plain_data)
Decrypted an amount of data in non-blocking mode with DMA in ECB mode.
hal_aes_state_t
hal_aes_state_t
HAL AES State Enumerations definition.
Definition: gr55xx_hal_aes.h:76
hal_aes_cbc_encrypt
hal_status_t hal_aes_cbc_encrypt(aes_handle_t *p_aes, uint32_t *p_plain_data, uint32_t number, uint32_t *p_cypher_data, uint32_t timeout)
Encrypted an amount of data in blocking mode in CBC mode.
HAL_AES_STATE_SUSPENDED
@ HAL_AES_STATE_SUSPENDED
Definition: gr55xx_hal_aes.h:82
_aes_handle::p_cryp_output_buffer
uint32_t * p_cryp_output_buffer
Definition: gr55xx_hal_aes.h:137
hal_aes_ecb_decrypt_it
hal_status_t hal_aes_ecb_decrypt_it(aes_handle_t *p_aes, uint32_t *p_cypher_data, uint32_t number, uint32_t *p_plain_data)
Decrypted an amount of data in non-blocking mode with Interrupt in ECB mode.
_hal_aes_callback::aes_error_callback
void(* aes_error_callback)(aes_handle_t *p_aes)
Definition: gr55xx_hal_aes.h:173
HAL_AES_STATE_BUSY
@ HAL_AES_STATE_BUSY
Definition: gr55xx_hal_aes.h:79
hal_aes_error_callback
void hal_aes_error_callback(aes_handle_t *p_aes)
AES error callback.
_aes_init::chaining_mode
uint32_t chaining_mode
Definition: gr55xx_hal_aes.h:108
_aes_handle::p_cryp_input_buffer
uint32_t * p_cryp_input_buffer
Definition: gr55xx_hal_aes.h:135
hal_aes_done_callback
void hal_aes_done_callback(aes_handle_t *p_aes)
Encrypt or decrypt Done callback.
hal_aes_cbc_decrypt_it
hal_status_t hal_aes_cbc_decrypt_it(aes_handle_t *p_aes, uint32_t *p_cypher_data, uint32_t number, uint32_t *p_plain_data)
Decrypted an amount of data in non-blocking mode with Interrupt in CBC mode.
gr55xx_hal_def.h
This file contains HAL common definitions, enumeration, macros and structures definitions.