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