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 _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 */
176 
177 /** @} */
178 
179 /** @} */
180 
181 /**
182  * @defgroup HAL_AES_MACRO Defines
183  * @{
184  */
185 
186 /* Exported constants --------------------------------------------------------*/
187 /** @defgroup AES_Exported_Constants AES Exported Constants
188  * @{
189  */
190 
191 /** @defgroup AES_Error_Code AES Error Code
192  * @{
193  */
194 #define HAL_AES_ERROR_NONE ((uint32_t)0x00000000) /**< No error */
195 #define HAL_AES_ERROR_TIMEOUT ((uint32_t)0x00000001) /**< Timeout error */
196 #define HAL_AES_ERROR_TRANSFER ((uint32_t)0x00000002) /**< Transfer error */
197 #define HAL_AES_ERROR_INVALID_PARAM ((uint32_t)0x00000004) /**< Invalid parameters error */
198 /** @} */
199 
200 /** @defgroup AES_Key_Size AES Key Size
201  * @{
202  */
203 #define AES_KEYSIZE_128BITS LL_AES_KEY_SIZE_128 /**< 128 bits */
204 #define AES_KEYSIZE_192BITS LL_AES_KEY_SIZE_192 /**< 192 bits */
205 #define AES_KEYSIZE_256BITS LL_AES_KEY_SIZE_256 /**< 256 bits */
206 /** @} */
207 
208 /** @defgroup AES_Block_Size AES Block Size
209  * @{
210  */
211 #define AES_BLOCK_MAX (2048) /**< Block max size */
212 #define AES_BLOCKSIZE_BITS (128) /**< Block size in bits */
213 #define AES_BLOCKSIZE_BYTES (AES_BLOCKSIZE_BITS >> 3) /**< Block size in bytes */
214 #define AES_BLOCKSIZE_WORDS (AES_BLOCKSIZE_BYTES >> 2) /**< Block size in words */
215 /** @} */
216 
217 /** @defgroup AES_OPERATION_MODE AES Operation Mode
218  * @{
219  */
220 #define AES_OPERATION_MODE_ENCRYPT (1) /**< Encrypt operation mode */
221 #define AES_OPERATION_MODE_DECRYPT (0) /**< Decrypt operation mode */
222 /** @} */
223 
224 /** @defgroup AES_CHAININGMODE AES Chaining Mode
225  * @{
226  */
227 #define AES_CHAININGMODE_ECB LL_AES_OPERATION_MODE_ECB /**< ECB chaining mode */
228 #define AES_CHAININGMODE_CBC LL_AES_OPERATION_MODE_CBC /**< CBC chaining mode */
229 /** @} */
230 
231 /** @defgroup AES_Flags_definition AES Flags Definition
232  * @{
233  */
234 #define AES_FLAG_DATAREADY LL_AES_FLAG_DATAREADY /**< Data ready flag */
235 #define AES_FLAG_DMA_DONE LL_AES_FLAG_DMA_DONE /**< DMA transfer done flag */
236 #define AES_FLAG_DMA_ERR LL_AES_FLAG_DMA_ERR /**< DMA transfer error flag */
237 #define AES_FLAG_KEY_VALID LL_AES_FLAG_KEY_VALID /**< Key valid flag */
238 /** @} */
239 
240 /** @defgroup AES_Interrupt_definition AES Interrupt definition
241  * @{
242  */
243 #define AES_IT_DONE ((uint32_t)0x00000001) /**< AES Encrypted or Decrypted Data Done Interrupt source */
244 /** @} */
245 
246 /** @defgroup AES_Timeout_definition AES Timeout definition
247  * @{
248  */
249 #define HAL_AES_TIMEOUT_DEFAULT_VALUE ((uint32_t)5000) /**< 5s */
250 /** @} */
251 
252 /** @} */
253 
254 /* Exported macro ------------------------------------------------------------*/
255 /** @defgroup AES_Exported_Macros AES Exported Macros
256  * @{
257  */
258 
259 /** @brief Reset AES handle states.
260  * @param __HANDLE__ AES handle.
261  * @retval None
262  */
263 #define __HAL_AES_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->state = HAL_AES_STATE_RESET)
264 
265 /** @brief Enable the specified AES peripheral.
266  * @param __HANDLE__ Specifies the AES Handle.
267  * @retval None
268  */
269 #define __HAL_AES_ENABLE(__HANDLE__) SET_BITS((__HANDLE__)->p_instance->CTRL, AES_CTRL_MODULE_EN)
270 /** @brief Disable the specified AES peripheral.
271  * @param __HANDLE__ Specifies the AES Handle.
272  * @retval None
273  */
274 #define __HAL_AES_DISABLE(__HANDLE__) CLEAR_BITS((__HANDLE__)->p_instance->CTRL, AES_CTRL_MODULE_EN)
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__) (READ_BITS((__HANDLE__)->p_instance->INT, (__FLAG__)) == (__FLAG__))
295 /** @brief Clear the specified AES interrupt flag.
296  * @param __HANDLE__ Specifies the AES interrupt Handle.
297  * @param __FLAG__ Specifies the flag to clear.
298  * This parameter can be the following value:
299  * @arg @ref AES_IT_DONE Encrypted or Decrypted Data Done Interrupt
300  * @retval None
301  */
302 #define __HAL_AES_CLEAR_FLAG_IT(__HANDLE__, __FLAG__) SET_BITS((__HANDLE__)->p_instance->INT, (__FLAG__))
303 /** @brief Check whether the specified AES flag is set or not.
304  * @param __HANDLE__ Specifies the AES Handle.
305  * @param __FLAG__ Specifies the flag to check.
306  * This parameter can be one of the following values:
307  * @arg @ref AES_FLAG_DATAREADY Data ready flag
308  * @arg @ref AES_FLAG_DMA_DONE DMA transfer done flag
309  * @arg @ref AES_FLAG_DMA_ERR DMA transfer error flag
310  * @arg @ref AES_FLAG_KEY_VALID Key valid flag
311  * @retval The new state of __FLAG__ (TRUE or FALSE).
312  */
313 #define __HAL_AES_GET_FLAG(__HANDLE__, __FLAG__) ((READ_BITS((__HANDLE__)->p_instance->STAT, (__FLAG__)) != 0) ? SET : RESET)
314 /** @} */
315 
316 /* Private macros ------------------------------------------------------------*/
317 /** @defgroup AES_Private_Macro AES Private Macros
318  * @{
319  */
320 
321 /** @brief Check if AES Key Size is valid.
322  * @param __SIZE__ AES Key Size.
323  * @retval SET (__SIZE__ is valid) or RESET (__SIZE__ is invalid)
324  */
325 #define IS_AES_KEY_SIZE(__SIZE__) (((__SIZE__) == AES_KEYSIZE_128BITS) || \
326  ((__SIZE__) == AES_KEYSIZE_192BITS) || \
327  ((__SIZE__) == AES_KEYSIZE_256BITS))
328 
329 /** @brief Check if AES Operation Mode is valid.
330  * @param __MODE__ AES Operation Mode.
331  * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
332  */
333 #define IS_AES_OPERATION_MODE(__MODE__) (((__MODE__) == AES_OPERATION_MODE_ENCRYPT) || \
334  ((__MODE__) == AES_OPERATION_MODE_DECRYPT))
335 
336 /** @brief Check if AES Chaining Mode is valid.
337  * @param __MODE__ AES Chaining Mode.
338  * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
339  */
340 #define IS_AES_CHAININGMODE(__MODE__) (((__MODE__) == AES_CHAININGMODE_ECB) || \
341  ((__MODE__) == AES_CHAININGMODE_CBC))
342 
343 /** @} */
344 
345 /** @} */
346 
347 /* Exported functions --------------------------------------------------------*/
348 /** @addtogroup HAL_AES_DRIVER_FUNCTIONS Functions
349  * @{
350  */
351 
352 /** @addtogroup AES_Exported_Functions_Group1 Initialization and de-initialization functions
353  * @brief Initialization and Configuration functions
354  *
355 @verbatim
356  ===============================================================================
357  ##### Initialization and de-initialization functions #####
358  ===============================================================================
359  [..] This subsection provides a set of functions allowing to initialize and
360  de-initialize the AESx peripheral:
361 
362  (+) User must implement hal_aes_msp_init() function in which he configures
363  all related peripherals resources (GPIO, DMA, IT and NVIC ).
364 
365  (+) Call the function hal_aes_init() to configure the selected device with
366  the selected configuration:
367  (++) Key Size
368  (++) operation_mode
369  (++) ChainingMode
370  (++) key
371  (++) init_vector
372  (++) DPAMode
373  (++) Seed
374 
375  (+) Call the function hal_aes_deinit() to restore the default configuration
376  of the selected AESx peripheral.
377 
378 @endverbatim
379  * @{
380  */
381 
382 /**
383  ****************************************************************************************
384  * @brief Initialize the AES according to the specified parameters
385  * in the aes_init_t and initialize the associated handle.
386  *
387  * @param[in] p_aes: Pointer to an AES handle which contains the configuration
388  * information for the specified AES module.
389  *
390  * @retval ::HAL_OK: Operation is OK.
391  * @retval ::HAL_ERROR: Parameter error or operation not supported.
392  * @retval ::HAL_BUSY: Driver is busy.
393  * @retval ::HAL_TIMEOUT: Timeout occurred.
394  ****************************************************************************************
395  */
397 
398 /**
399  ****************************************************************************************
400  * @brief De-initialize the AES peripheral.
401  *
402  * @param[in] p_aes: Pointer to an AES handle which contains the configuration
403  * information for the specified AES module.
404  *
405  * @retval ::HAL_OK: Operation is OK.
406  * @retval ::HAL_ERROR: Parameter error or operation not supported.
407  * @retval ::HAL_BUSY: Driver is busy.
408  * @retval ::HAL_TIMEOUT: Timeout occurred.
409  ****************************************************************************************
410  */
412 
413 /**
414  ****************************************************************************************
415  * @brief Initialize the AES MSP.
416  *
417  * @note This function should not be modified. When the callback is needed,
418  * the hal_aes_msp_deinit can be implemented in the user file.
419  *
420  * @param[in] p_aes: Pointer to an AES handle which contains the configuration
421  * information for the specified AES module.
422  ****************************************************************************************
423  */
425 
426 /**
427  ****************************************************************************************
428  * @brief De-initialize the AES MSP.
429  *
430  * @note This function should not be modified. When the callback is needed,
431  * the hal_aes_msp_deinit can be implemented in the user file.
432  *
433  * @param[in] p_aes: Pointer to an AES handle which contains the configuration
434  * information for the specified AES module.
435  ****************************************************************************************
436  */
438 
439 /** @} */
440 
441 /** @addtogroup AES_Exported_Functions_Group2 IO operation functions
442  * @brief AES Encrypt/Decrypt functions
443  *
444 @verbatim
445  ===============================================================================
446  ##### IO operation functions #####
447  ===============================================================================
448  This subsection provides a set of functions allowing to manage the AES encrypt or decrypt.
449 
450  (#) There are two mode of transfer:
451  (++) Blocking mode: The communication is performed in polling mode.
452  The HAL status of all data processing are returned by the same function
453  after finishing transfer.
454  (++) Non-Blocking mode: The communication is performed using Interrupts
455  or DMA. These API return the HAL status.
456  The end of the data processing will be indicated through the
457  dedicated AES IRQ when using Interrupt mode or the DMA IRQ when
458  using DMA mode.
459  The hal_aes_done_callback() user callbacks will be executed respectively
460  at the end of the encrypt or decrypt process
461  The hal_aes_error_callback() user callback will be executed when a error is detected
462 
463  (#) Blocking mode API's are :
464  (++) hal_aes_ecb_encrypt()
465  (++) hal_aes_ecb_decrypt()
466  (++) hal_aes_cbc_encrypt()
467  (++) hal_aes_cbc_decrypt()
468 
469  (#) Non-Blocking mode API's with Interrupt are :
470  (++) hal_aes_ecb_encrypt_it()
471  (++) hal_aes_ecb_decrypt_it()
472  (++) hal_aes_cbc_encrypt_it()
473  (++) hal_aes_cbc_decrypt_it()
474 
475  (#) Non-Blocking mode API's with DMA are :
476  (++) hal_aes_ecb_encrypt_dma()
477  (++) hal_aes_ecb_decrypt_dma()
478  (++) hal_aes_cbc_encrypt_dma()
479  (++) hal_aes_cbc_decrypt_dma()
480 
481  (#) A set of encrypt or decrypt Callbacks are provided in Non_Blocking mode:
482  (++) hal_aes_done_callback()
483  (++) hal_aes_error_callback()
484 
485 @endverbatim
486  * @{
487  */
488 
489 /**
490  ****************************************************************************************
491  * @brief Encrypted an amount of data in blocking mode in ECB mode.
492  *
493  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
494  * the specified AES module.
495  * @param[in] p_plain_data: Pointer to plain data buffer
496  * @param[in] number: Amount of data to be decrypted in bytes
497  * @param[out] p_cypher_data: Pointer to cypher data buffer
498  * @param[in] timeout: Timeout duration
499  *
500  * @retval ::HAL_OK: Operation is OK.
501  * @retval ::HAL_ERROR: Parameter error or operation not supported.
502  * @retval ::HAL_BUSY: Driver is busy.
503  * @retval ::HAL_TIMEOUT: Timeout occurred.
504  ****************************************************************************************
505  */
506 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);
507 
508 /**
509  ****************************************************************************************
510  * @brief Decrypted an amount of data in blocking mode in ECB mode.
511  *
512  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
513  * the specified AES module.
514  * @param[in] p_cypher_data: Pointer to cypher data buffer
515  * @param[in] number: Amount of data to be decrypted in bytes
516  * @param[out] p_plain_data: Pointer to plain data buffer
517  * @param[in] timeout: Timeout duration
518  *
519  * @retval ::HAL_OK: Operation is OK.
520  * @retval ::HAL_ERROR: Parameter error or operation not supported.
521  * @retval ::HAL_BUSY: Driver is busy.
522  * @retval ::HAL_TIMEOUT: Timeout occurred.
523  ****************************************************************************************
524  */
525 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);
526 
527 /**
528  ****************************************************************************************
529  * @brief Encrypted an amount of data in blocking mode in CBC mode.
530  *
531  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
532  * the specified AES module.
533  * @param[in] p_plain_data: Pointer to plain data buffer
534  * @param[in] number: Amount of data to be decrypted in bytes
535  * @param[out] p_cypher_data: Pointer to cypher data buffer
536  * @param[in] timeout: Timeout duration
537  *
538  * @retval ::HAL_OK: Operation is OK.
539  * @retval ::HAL_ERROR: Parameter error or operation not supported.
540  * @retval ::HAL_BUSY: Driver is busy.
541  * @retval ::HAL_TIMEOUT: Timeout occurred.
542  ****************************************************************************************
543  */
544 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);
545 
546 /**
547  ****************************************************************************************
548  * @brief Decrypted an amount of data in blocking mode in CBC mode.
549  *
550  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
551  * the specified AES module.
552  * @param[in] p_cypher_data: Pointer to cypher data buffer
553  * @param[in] number: Amount of data to be decrypted in bytes
554  * @param[out] p_plain_data: Pointer to plain data buffer
555  * @param[in] timeout: Timeout duration
556  *
557  * @retval ::HAL_OK: Operation is OK.
558  * @retval ::HAL_ERROR: Parameter error or operation not supported.
559  * @retval ::HAL_BUSY: Driver is busy.
560  * @retval ::HAL_TIMEOUT: Timeout occurred.
561  ****************************************************************************************
562  */
563 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);
564 
565 /**
566  ****************************************************************************************
567  * @brief Encrypted an amount of data in non-blocking mode with Interrupt in ECB mode.
568  *
569  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
570  * the specified AES module.
571  * @param[in] p_plain_data: Pointer to plain data buffer
572  * @param[in] number: Amount of data to be decrypted in bytes
573  * @param[out] p_cypher_data: Pointer to cypher data buffer
574  *
575  * @retval ::HAL_OK: Operation is OK.
576  * @retval ::HAL_ERROR: Parameter error or operation not supported.
577  * @retval ::HAL_BUSY: Driver is busy.
578  * @retval ::HAL_TIMEOUT: Timeout occurred.
579  ****************************************************************************************
580  */
581 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);
582 
583 /**
584  ****************************************************************************************
585  * @brief Decrypted an amount of data in non-blocking mode with Interrupt in ECB mode.
586  *
587  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
588  * the specified AES module.
589  * @param[in] p_cypher_data: Pointer to cypher data buffer
590  * @param[in] number: Amount of data to be decrypted in bytes
591  * @param[out] p_plain_data: Pointer to plain data buffer
592  *
593  * @retval ::HAL_OK: Operation is OK.
594  * @retval ::HAL_ERROR: Parameter error or operation not supported.
595  * @retval ::HAL_BUSY: Driver is busy.
596  * @retval ::HAL_TIMEOUT: Timeout occurred.
597  ****************************************************************************************
598  */
599 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);
600 
601 /**
602  ****************************************************************************************
603  * @brief Encrypted an amount of data in non-blocking mode with Interrupt in CBC mode.
604  *
605  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
606  * the specified AES module.
607  * @param[in] p_plain_data: Pointer to plain data buffer
608  * @param[in] number: Amount of data to be decrypted in bytes
609  * @param[out] p_cypher_data: Pointer to cypher data buffer
610  *
611  * @retval ::HAL_OK: Operation is OK.
612  * @retval ::HAL_ERROR: Parameter error or operation not supported.
613  * @retval ::HAL_BUSY: Driver is busy.
614  * @retval ::HAL_TIMEOUT: Timeout occurred.
615  ****************************************************************************************
616  */
617 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);
618 
619 /**
620  ****************************************************************************************
621  * @brief Decrypted 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_cypher_data: Pointer to cypher data buffer
626  * @param[in] number: Amount of data to be decrypted in bytes
627  * @param[out] p_plain_data: Pointer to plain 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_decrypt_it(aes_handle_t *p_aes, uint32_t *p_cypher_data, uint32_t number, uint32_t *p_plain_data);
636 
637 /**
638  ****************************************************************************************
639  * @brief Encrypted an amount of data in non-blocking mode with DMA in ECB mode.
640  *
641  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
642  * the specified AES module.
643  * @param[in] p_plain_data: Pointer to plain data buffer
644  * @param[in] number: Amount of data to be decrypted in bytes
645  * @param[out] p_cypher_data: Pointer to cypher data buffer
646  *
647  * @retval ::HAL_OK: Operation is OK.
648  * @retval ::HAL_ERROR: Parameter error or operation not supported.
649  * @retval ::HAL_BUSY: Driver is busy.
650  * @retval ::HAL_TIMEOUT: Timeout occurred.
651  ****************************************************************************************
652  */
653 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);
654 
655 /**
656  ****************************************************************************************
657  * @brief Decrypted an amount of data in non-blocking mode with DMA in ECB mode.
658  *
659  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
660  * the specified AES module.
661  * @param[in] p_cypher_data: Pointer to cypher data buffer
662  * @param[in] number: Amount of data to be decrypted in bytes
663  * @param[out] p_plain_data: Pointer to plain data buffer
664  *
665  * @retval ::HAL_OK: Operation is OK.
666  * @retval ::HAL_ERROR: Parameter error or operation not supported.
667  * @retval ::HAL_BUSY: Driver is busy.
668  * @retval ::HAL_TIMEOUT: Timeout occurred.
669  ****************************************************************************************
670  */
671 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);
672 
673 /**
674  ****************************************************************************************
675  * @brief Encrypted an amount of data in non-blocking mode with DMA in CBC mode.
676  *
677  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
678  * the specified AES module.
679  * @param[in] p_plain_data: Pointer to plain data buffer
680  * @param[in] number: Amount of data to be decrypted in bytes
681  * @param[out] p_cypher_data: Pointer to cypher data buffer
682  *
683  * @retval ::HAL_OK: Operation is OK.
684  * @retval ::HAL_ERROR: Parameter error or operation not supported.
685  * @retval ::HAL_BUSY: Driver is busy.
686  * @retval ::HAL_TIMEOUT: Timeout occurred.
687  ****************************************************************************************
688  */
689 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);
690 
691 /**
692  ****************************************************************************************
693  * @brief Decrypted an amount of data in non-blocking mode with DMA in CBC mode.
694  *
695  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
696  * the specified AES module.
697  * @param[in] p_cypher_data: Pointer to cypher data buffer
698  * @param[in] number: Amount of data to be decrypted in bytes
699  * @param[out] p_plain_data: Pointer to plain data buffer
700  *
701  * @retval ::HAL_OK: Operation is OK.
702  * @retval ::HAL_ERROR: Parameter error or operation not supported.
703  * @retval ::HAL_BUSY: Driver is busy.
704  * @retval ::HAL_TIMEOUT: Timeout occurred.
705  ****************************************************************************************
706  */
707 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);
708 
709 /** @} */
710 
711 /** @addtogroup AES_IRQ_Handler_and_Callbacks IRQ Handler and Callbacks
712  * @brief IRQ Handler and Callbacks functions
713  * @{
714  */
715 
716 /**
717  ****************************************************************************************
718  * @brief Handle AES interrupt request.
719  *
720  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
721  * the specified the specified AES module.
722  ****************************************************************************************
723  */
725 
726 /**
727  ****************************************************************************************
728  * @brief Encrypt or decrypt Done callback.
729  *
730  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
731  * the specified AES module.
732  ****************************************************************************************
733  */
735 
736 /**
737  ****************************************************************************************
738  * @brief AES error callback.
739  *
740  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
741  * the specified AES module.
742  ****************************************************************************************
743  */
745 
746 /** @} */
747 
748 /** @defgroup AES_Exported_Functions_Group3 Peripheral State and Errors functions
749  * @brief AES control functions
750  *
751 @verbatim
752  ===============================================================================
753  ##### Peripheral State and Errors functions #####
754  ===============================================================================
755  [..]
756  This subsection provides a set of functions allowing to control the AES.
757  (+) hal_aes_get_state() API can be helpful to check in run-time the state of the AES peripheral.
758  (+) hal_aes_get_error() check in run-time Errors occurring during communication.
759  (+) hal_aes_set_timeout() set the timeout during internal process.
760 @endverbatim
761  * @{
762  */
763 
764 /**
765  ****************************************************************************************
766  * @brief Return the AES handle state.
767  *
768  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
769  * the specified AES module.
770  *
771  * @retval ::HAL_AES_STATE_RESET: Peripheral not initialized.
772  * @retval ::HAL_AES_STATE_READY: Peripheral initialized and ready for use.
773  * @retval ::HAL_AES_STATE_BUSY: Peripheral in indirect mode and busy.
774  * @retval ::HAL_AES_STATE_ERROR: Peripheral in error.
775  * @retval ::HAL_AES_STATE_TIMEOUT: Peripheral in timeout.
776  * @retval ::HAL_AES_STATE_SUSPENDED: Peripheral in suspended.
777  ****************************************************************************************
778  */
780 
781 /**
782  ****************************************************************************************
783  * @brief Return the AES error code.
784  *
785  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
786  * the specified AES module.
787  *
788  * @return AES error code in bitmap format
789  ****************************************************************************************
790  */
792 
793 /**
794  ****************************************************************************************
795  * @brief Set the AES internal process timeout value.
796  *
797  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
798  * the specified AES module.
799  * @param[in] timeout: Internal process timeout value.
800  ****************************************************************************************
801  */
802 void hal_aes_set_timeout(aes_handle_t *p_aes, uint32_t timeout);
803 
804 /**
805  ****************************************************************************************
806  * @brief Suspend some registers related to AES configuration before sleep.
807  * @param[in] p_aes: Pointer to a AES handle which contains the configuration
808  * information for the specified AES module.
809  * @retval ::HAL_OK: Operation is OK.
810  * @retval ::HAL_ERROR: Parameter error or operation not supported.
811  * @retval ::HAL_BUSY: Driver is busy.
812  * @retval ::HAL_TIMEOUT: Timeout occurred.
813  ****************************************************************************************
814  */
816 
817 /**
818  ****************************************************************************************
819  * @brief Restore some registers related to AES configuration after sleep.
820  * This function must be used in conjunction with the hal_aes_suspend_reg().
821  * @param[in] p_aes: Pointer to a AES handle which contains the configuration
822  * information for the specified AES module.
823  * @retval ::HAL_OK: Operation is OK.
824  * @retval ::HAL_ERROR: Parameter error or operation not supported.
825  * @retval ::HAL_BUSY: Driver is busy.
826  * @retval ::HAL_TIMEOUT: Timeout occurred.
827  ****************************************************************************************
828  */
830 
831 /** @} */
832 
833 /** @} */
834 
835 #ifdef __cplusplus
836 }
837 #endif
838 
839 #endif /* __GR55xx_HAL_AES_H__ */
840 
841 /** @} */
842 
843 /** @} */
844 
845 /** @} */
hal_aes_msp_deinit
void hal_aes_msp_deinit(aes_handle_t *p_aes)
De-initialize the AES MSP.
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_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_callback::aes_msp_init
void(* aes_msp_init)(aes_handle_t *p_aes)
Definition: gr55xx_hal_aes.h:171
_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_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_callback_t
struct _aes_callback aes_callback_t
HAL AES Callback function definition.
_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_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
_aes_callback::aes_error_callback
void(* aes_error_callback)(aes_handle_t *p_aes)
Definition: gr55xx_hal_aes.h:173
_aes_callback::aes_done_callback
void(* aes_done_callback)(aes_handle_t *p_aes)
Definition: gr55xx_hal_aes.h:174
_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_callback::aes_msp_deinit
void(* aes_msp_deinit)(aes_handle_t *p_aes)
Definition: gr55xx_hal_aes.h:172
_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_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_callback
HAL AES Callback function definition.
Definition: gr55xx_hal_aes.h:170
_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.