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 */
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_ENABLE)
271 
272 /** @brief Disable the specified AES peripheral.
273  * @param __HANDLE__ Specifies the AES Handle.
274  * @retval None
275  */
276 #define __HAL_AES_DISABLE(__HANDLE__) CLEAR_BITS((__HANDLE__)->p_instance->CTRL, AES_CTRL_ENABLE)
277 
278 /** @brief Enable the AES interrupt.
279  * @param __HANDLE__ Specifies the AES Handle.
280  * @retval None
281  */
282 #define __HAL_AES_ENABLE_IT(__HANDLE__) ll_aes_enable_it_done((__HANDLE__)->p_instance)
283 
284 /** @brief Disable the AES interrupt.
285  * @param __HANDLE__ Specifies the AES Handle.
286  * @retval None
287  */
288 #define __HAL_AES_DISABLE_IT(__HANDLE__) ll_aes_disable_it_done((__HANDLE__)->p_instance)
289 
290 /** @brief Check whether the specified AES interrupt flag is set or not.
291  * @param __HANDLE__ Specifies the AES Handle.
292  * @param __FLAG__ Specifies the interrupt flag to check.
293  * This parameter can be the following value:
294  * @arg @ref AES_IT_DONE Encrypted or Decrypted Data Done Interrupt
295  * @retval The new state of __FLAG__ (TRUE or FALSE).
296  */
297 #define __HAL_AES_GET_FLAG_IT(__HANDLE__, __FLAG__) (READ_BITS((__HANDLE__)->p_instance->INTERRUPT, (__FLAG__)) == (__FLAG__))
298 
299 /** @brief Clear the specified AES interrupt flag.
300  * @param __HANDLE__ Specifies the AES interrupt Handle.
301  * @param __FLAG__ Specifies the flag to clear.
302  * This parameter can be the following value:
303  * @arg @ref AES_IT_DONE Encrypted or Decrypted Data Done Interrupt
304  * @retval None
305  */
306 #define __HAL_AES_CLEAR_FLAG_IT(__HANDLE__, __FLAG__) SET_BITS((__HANDLE__)->p_instance->INTERRUPT, (__FLAG__))
307 
308 /** @brief Check whether the specified AES flag is set or not.
309  * @param __HANDLE__ Specifies the AES Handle.
310  * @param __FLAG__ Specifies the flag to check.
311  * This parameter can be one of the following values:
312  * @arg @ref AES_FLAG_DATAREADY Data ready flag
313  * @arg @ref AES_FLAG_DMA_DONE DMA transfer done flag
314  * @arg @ref AES_FLAG_DMA_ERR DMA transfer error flag
315  * @arg @ref AES_FLAG_KEY_VALID Key valid flag
316  * @retval The new state of __FLAG__ (TRUE or FALSE).
317  */
318 #define __HAL_AES_GET_FLAG(__HANDLE__, __FLAG__) ((READ_BITS((__HANDLE__)->p_instance->STATUS, (__FLAG__)) != 0) ? SET : RESET)
319 
320 /** @} */
321 
322 /* Private macros ------------------------------------------------------------*/
323 /** @defgroup AES_Private_Macro AES Private Macros
324  * @{
325  */
326 
327 /** @brief Check if AES Key Size is valid.
328  * @param __SIZE__ AES Key Size.
329  * @retval SET (__SIZE__ is valid) or RESET (__SIZE__ is invalid)
330  */
331 #define IS_AES_KEY_SIZE(__SIZE__) (((__SIZE__) == AES_KEYSIZE_128BITS) || \
332  ((__SIZE__) == AES_KEYSIZE_192BITS) || \
333  ((__SIZE__) == AES_KEYSIZE_256BITS))
334 
335 /** @brief Check if AES Operation Mode is valid.
336  * @param __MODE__ AES Operation Mode.
337  * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
338  */
339 #define IS_AES_OPERATION_MODE(__MODE__) (((__MODE__) == AES_OPERATION_MODE_ENCRYPT) || \
340  ((__MODE__) == AES_OPERATION_MODE_DECRYPT))
341 
342 /** @brief Check if AES Chaining Mode is valid.
343  * @param __MODE__ AES Chaining Mode.
344  * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
345  */
346 #define IS_AES_CHAININGMODE(__MODE__) (((__MODE__) == AES_CHAININGMODE_ECB) || \
347  ((__MODE__) == AES_CHAININGMODE_CBC))
348 
349 /** @} */
350 
351 /** @} */
352 
353 /* Exported functions --------------------------------------------------------*/
354 /** @addtogroup HAL_AES_DRIVER_FUNCTIONS Functions
355  * @{
356  */
357 
358 /** @addtogroup AES_Exported_Functions_Group1 Initialization and de-initialization functions
359  * @brief Initialization and Configuration functions
360  *
361 @verbatim
362  ===============================================================================
363  ##### Initialization and de-initialization functions #####
364  ===============================================================================
365  [..] This subsection provides a set of functions allowing to initialize and
366  de-initialize the AESx peripheral:
367 
368  (+) User must implement hal_aes_msp_init() function in which he configures
369  all related peripherals resources (GPIO, DMA, IT and NVIC ).
370 
371  (+) Call the function hal_aes_init() to configure the selected device with
372  the selected configuration:
373  (++) Key Size
374  (++) operation_mode
375  (++) ChainingMode
376  (++) key
377  (++) init_vector
378  (++) DPAMode
379  (++) Seed
380 
381  (+) Call the function hal_aes_deinit() to restore the default configuration
382  of the selected AESx peripheral.
383 
384 @endverbatim
385  * @{
386  */
387 
388 /**
389  ****************************************************************************************
390  * @brief Initialize the AES according to the specified parameters
391  * in the aes_init_t and initialize the associated handle.
392  *
393  * @param[in] p_aes: Pointer to an AES handle which contains the configuration
394  * information for the specified AES module.
395  *
396  * @retval ::HAL_OK: Operation is OK.
397  * @retval ::HAL_ERROR: Parameter error or operation not supported.
398  * @retval ::HAL_BUSY: Driver is busy.
399  * @retval ::HAL_TIMEOUT: Timeout occurred.
400  ****************************************************************************************
401  */
403 
404 /**
405  ****************************************************************************************
406  * @brief De-initialize the AES peripheral.
407  *
408  * @param[in] p_aes: Pointer to an AES handle which contains the configuration
409  * information for the specified AES module.
410  *
411  * @retval ::HAL_OK: Operation is OK.
412  * @retval ::HAL_ERROR: Parameter error or operation not supported.
413  * @retval ::HAL_BUSY: Driver is busy.
414  * @retval ::HAL_TIMEOUT: Timeout occurred.
415  ****************************************************************************************
416  */
418 
419 /**
420  ****************************************************************************************
421  * @brief Initialize the AES MSP.
422  *
423  * @note This function should not be modified. When the callback is needed,
424  * the hal_aes_msp_deinit can be implemented in the user file.
425  *
426  * @param[in] p_aes: Pointer to an AES handle which contains the configuration
427  * information for the specified AES module.
428  ****************************************************************************************
429  */
431 
432 /**
433  ****************************************************************************************
434  * @brief De-initialize the AES MSP.
435  *
436  * @note This function should not be modified. When the callback is needed,
437  * the hal_aes_msp_deinit can be implemented in the user file.
438  *
439  * @param[in] p_aes: Pointer to an AES handle which contains the configuration
440  * information for the specified AES module.
441  ****************************************************************************************
442  */
444 
445 /** @} */
446 
447 /** @addtogroup AES_Exported_Functions_Group2 IO operation functions
448  * @brief AES Encrypt/Decrypt functions
449  *
450 @verbatim
451  ===============================================================================
452  ##### IO operation functions #####
453  ===============================================================================
454  This subsection provides a set of functions allowing to manage the AES encrypt or decrypt.
455 
456  (#) There are two mode of transfer:
457  (++) Blocking mode: The communication is performed in polling mode.
458  The HAL status of all data processing are returned by the same function
459  after finishing transfer.
460  (++) Non-Blocking mode: The communication is performed using Interrupts
461  or DMA. These API return the HAL status.
462  The end of the data processing will be indicated through the
463  dedicated AES IRQ when using Interrupt mode or the DMA IRQ when
464  using DMA mode.
465  The hal_aes_done_callback() user callbacks will be executed respectively
466  at the end of the encrypt or decrypt process
467  The hal_aes_error_callback() user callback will be executed when a error is detected
468 
469  (#) Blocking mode API's are :
470  (++) hal_aes_ecb_encrypt()
471  (++) hal_aes_ecb_decrypt()
472  (++) hal_aes_cbc_encrypt()
473  (++) hal_aes_cbc_decrypt()
474 
475  (#) Non-Blocking mode API's with Interrupt are :
476  (++) hal_aes_ecb_encrypt_it()
477  (++) hal_aes_ecb_decrypt_it()
478  (++) hal_aes_cbc_encrypt_it()
479  (++) hal_aes_cbc_decrypt_it()
480 
481  (#) Non-Blocking mode API's with DMA are :
482  (++) hal_aes_ecb_encrypt_dma()
483  (++) hal_aes_ecb_decrypt_dma()
484  (++) hal_aes_cbc_encrypt_dma()
485  (++) hal_aes_cbc_decrypt_dma()
486 
487  (#) A set of encrypt or decrypt Callbacks are provided in Non_Blocking mode:
488  (++) hal_aes_done_callback()
489  (++) hal_aes_error_callback()
490 
491  (#) Non-Blocking mode transfers could be aborted using Abort API's :
492  (++) hal_aes_abort()
493  (++) hal_aes_abort_it()
494 
495  (#) For Abort services based on interrupts (hal_aes_abort_xxx_it), Abort Complete Callback is provided:
496  (++) hal_aes_abort_cplt_callback()
497 
498 @endverbatim
499  * @{
500  */
501 
502 /**
503  ****************************************************************************************
504  * @brief Encrypted an amount of data in blocking mode in ECB mode.
505  *
506  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
507  * the specified AES module.
508  * @param[in] p_plain_data: Pointer to plain data buffer
509  * @param[in] number: Amount of data to be decrypted in bytes
510  * @param[out] p_cypher_data: Pointer to cypher data buffer
511  * @param[in] timeout: Timeout duration
512  *
513  * @retval ::HAL_OK: Operation is OK.
514  * @retval ::HAL_ERROR: Parameter error or operation not supported.
515  * @retval ::HAL_BUSY: Driver is busy.
516  * @retval ::HAL_TIMEOUT: Timeout occurred.
517  ****************************************************************************************
518  */
519 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);
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, uint32_t *p_plain_data, uint32_t timeout);
539 
540 /**
541  ****************************************************************************************
542  * @brief Encrypted an amount of data in blocking mode in CBC mode.
543  *
544  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
545  * the specified AES module.
546  * @param[in] p_plain_data: Pointer to plain data buffer
547  * @param[in] number: Amount of data to be decrypted in bytes
548  * @param[out] p_cypher_data: Pointer to cypher data buffer
549  * @param[in] timeout: Timeout duration
550  *
551  * @retval ::HAL_OK: Operation is OK.
552  * @retval ::HAL_ERROR: Parameter error or operation not supported.
553  * @retval ::HAL_BUSY: Driver is busy.
554  * @retval ::HAL_TIMEOUT: Timeout occurred.
555  ****************************************************************************************
556  */
557 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);
558 
559 /**
560  ****************************************************************************************
561  * @brief Decrypted an amount of data in blocking mode in CBC mode.
562  *
563  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
564  * the specified AES module.
565  * @param[in] p_cypher_data: Pointer to cypher data buffer
566  * @param[in] number: Amount of data to be decrypted in bytes
567  * @param[out] p_plain_data: Pointer to plain data buffer
568  * @param[in] timeout: Timeout duration
569  *
570  * @retval ::HAL_OK: Operation is OK.
571  * @retval ::HAL_ERROR: Parameter error or operation not supported.
572  * @retval ::HAL_BUSY: Driver is busy.
573  * @retval ::HAL_TIMEOUT: Timeout occurred.
574  ****************************************************************************************
575  */
576 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);
577 
578 /**
579  ****************************************************************************************
580  * @brief Encrypted an amount of data in non-blocking mode with Interrupt in ECB mode.
581  *
582  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
583  * the specified AES module.
584  * @param[in] p_plain_data: Pointer to plain data buffer
585  * @param[in] number: Amount of data to be decrypted in bytes
586  * @param[out] p_cypher_data: Pointer to cypher data buffer
587  *
588  * @retval ::HAL_OK: Operation is OK.
589  * @retval ::HAL_ERROR: Parameter error or operation not supported.
590  * @retval ::HAL_BUSY: Driver is busy.
591  * @retval ::HAL_TIMEOUT: Timeout occurred.
592  ****************************************************************************************
593  */
594 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);
595 
596 /**
597  ****************************************************************************************
598  * @brief Decrypted an amount of data in non-blocking mode with Interrupt in ECB mode.
599  *
600  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
601  * the specified AES module.
602  * @param[in] p_cypher_data: Pointer to cypher data buffer
603  * @param[in] number: Amount of data to be decrypted in bytes
604  * @param[out] p_plain_data: Pointer to plain data buffer
605  *
606  * @retval ::HAL_OK: Operation is OK.
607  * @retval ::HAL_ERROR: Parameter error or operation not supported.
608  * @retval ::HAL_BUSY: Driver is busy.
609  * @retval ::HAL_TIMEOUT: Timeout occurred.
610  ****************************************************************************************
611  */
612 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);
613 
614 /**
615  ****************************************************************************************
616  * @brief Encrypted an amount of data in non-blocking mode with Interrupt in CBC mode.
617  *
618  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
619  * the specified AES module.
620  * @param[in] p_plain_data: Pointer to plain data buffer
621  * @param[in] number: Amount of data to be decrypted in bytes
622  * @param[out] p_cypher_data: Pointer to cypher data buffer
623  *
624  * @retval ::HAL_OK: Operation is OK.
625  * @retval ::HAL_ERROR: Parameter error or operation not supported.
626  * @retval ::HAL_BUSY: Driver is busy.
627  * @retval ::HAL_TIMEOUT: Timeout occurred.
628  ****************************************************************************************
629  */
630 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);
631 
632 /**
633  ****************************************************************************************
634  * @brief Decrypted an amount of data in non-blocking mode with Interrupt in CBC mode.
635  *
636  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
637  * the specified AES module.
638  * @param[in] p_cypher_data: Pointer to cypher data buffer
639  * @param[in] number: Amount of data to be decrypted in bytes
640  * @param[out] p_plain_data: Pointer to plain data buffer
641  *
642  * @retval ::HAL_OK: Operation is OK.
643  * @retval ::HAL_ERROR: Parameter error or operation not supported.
644  * @retval ::HAL_BUSY: Driver is busy.
645  * @retval ::HAL_TIMEOUT: Timeout occurred.
646  ****************************************************************************************
647  */
648 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);
649 
650 /**
651  ****************************************************************************************
652  * @brief Encrypted an amount of data in non-blocking mode with DMA in ECB mode.
653  *
654  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
655  * the specified AES module.
656  * @param[in] p_plain_data: Pointer to plain data buffer
657  * @param[in] number: Amount of data to be decrypted in bytes
658  * @param[out] p_cypher_data: Pointer to cypher data buffer
659  *
660  * @retval ::HAL_OK: Operation is OK.
661  * @retval ::HAL_ERROR: Parameter error or operation not supported.
662  * @retval ::HAL_BUSY: Driver is busy.
663  * @retval ::HAL_TIMEOUT: Timeout occurred.
664  ****************************************************************************************
665  */
666 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);
667 
668 /**
669  ****************************************************************************************
670  * @brief Decrypted an amount of data in non-blocking mode with DMA in ECB mode.
671  *
672  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
673  * the specified AES module.
674  * @param[in] p_cypher_data: Pointer to cypher data buffer
675  * @param[in] number: Amount of data to be decrypted in bytes
676  * @param[out] p_plain_data: Pointer to plain data buffer
677  *
678  * @retval ::HAL_OK: Operation is OK.
679  * @retval ::HAL_ERROR: Parameter error or operation not supported.
680  * @retval ::HAL_BUSY: Driver is busy.
681  * @retval ::HAL_TIMEOUT: Timeout occurred.
682  ****************************************************************************************
683  */
684 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);
685 
686 /**
687  ****************************************************************************************
688  * @brief Encrypted an amount of data in non-blocking mode with DMA in CBC mode.
689  *
690  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
691  * the specified AES module.
692  * @param[in] p_plain_data: Pointer to plain data buffer
693  * @param[in] number: Amount of data to be decrypted in bytes
694  * @param[out] p_cypher_data: Pointer to cypher data buffer
695  *
696  * @retval ::HAL_OK: Operation is OK.
697  * @retval ::HAL_ERROR: Parameter error or operation not supported.
698  * @retval ::HAL_BUSY: Driver is busy.
699  * @retval ::HAL_TIMEOUT: Timeout occurred.
700  ****************************************************************************************
701  */
702 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);
703 
704 /**
705  ****************************************************************************************
706  * @brief Decrypted an amount of data in non-blocking mode with DMA in CBC mode.
707  *
708  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
709  * the specified AES module.
710  * @param[in] p_cypher_data: Pointer to cypher data buffer
711  * @param[in] number: Amount of data to be decrypted in bytes
712  * @param[out] p_plain_data: Pointer to plain data buffer
713  *
714  * @retval ::HAL_OK: Operation is OK.
715  * @retval ::HAL_ERROR: Parameter error or operation not supported.
716  * @retval ::HAL_BUSY: Driver is busy.
717  * @retval ::HAL_TIMEOUT: Timeout occurred.
718  ****************************************************************************************
719  */
720 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);
721 
722 /**
723  ****************************************************************************************
724  * @brief Abort the current encryption or decryption
725  *
726  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
727  * the specified AES module.
728  *
729  * @retval ::HAL_OK: Operation is OK.
730  * @retval ::HAL_ERROR: Parameter error or operation not supported.
731  * @retval ::HAL_BUSY: Driver is busy.
732  * @retval ::HAL_TIMEOUT: Timeout occurred.
733  ****************************************************************************************
734  */
736 
737 /**
738  ****************************************************************************************
739  * @brief Abort the current encryption or decryption (non-blocking function)
740  *
741  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
742  * the specified AES module.
743  *
744  * @retval ::HAL_OK: Operation is OK.
745  * @retval ::HAL_ERROR: Parameter error or operation not supported.
746  * @retval ::HAL_BUSY: Driver is busy.
747  * @retval ::HAL_TIMEOUT: Timeout occurred.
748  ****************************************************************************************
749  */
751 
752 /** @} */
753 
754 /** @addtogroup AES_IRQ_Handler_and_Callbacks IRQ Handler and Callbacks
755  * @brief IRQ Handler and Callbacks functions
756  * @{
757  */
758 
759 /**
760  ****************************************************************************************
761  * @brief Handle AES interrupt request.
762  *
763  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
764  * the specified the specified AES module.
765  ****************************************************************************************
766  */
768 
769 /**
770  ****************************************************************************************
771  * @brief Encrypt or decrypt Done callback.
772  *
773  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
774  * the specified AES module.
775  ****************************************************************************************
776  */
778 
779 /**
780  ****************************************************************************************
781  * @brief AES error callback.
782  *
783  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
784  * the specified AES module.
785  ****************************************************************************************
786  */
788 
789 /**
790  ****************************************************************************************
791  * @brief AES Abort Complete callback.
792  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
793  * the specified AES module.
794  ****************************************************************************************
795  */
797 
798 /** @} */
799 
800 /** @defgroup AES_Exported_Functions_Group3 Peripheral State and Errors functions
801  * @brief AES control functions
802  *
803 @verbatim
804  ===============================================================================
805  ##### Peripheral State and Errors functions #####
806  ===============================================================================
807  [..]
808  This subsection provides a set of functions allowing to control the AES.
809  (+) hal_aes_get_state() API can be helpful to check in run-time the state of the AES peripheral.
810  (+) hal_aes_get_error() check in run-time Errors occurring during communication.
811  (+) hal_aes_set_timeout() set the timeout during internal process.
812 @endverbatim
813  * @{
814  */
815 
816 /**
817  ****************************************************************************************
818  * @brief Return the AES handle state.
819  *
820  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
821  * the specified AES module.
822  *
823  * @retval ::HAL_AES_STATE_RESET: Peripheral not initialized.
824  * @retval ::HAL_AES_STATE_READY: Peripheral initialized and ready for use.
825  * @retval ::HAL_AES_STATE_BUSY: Peripheral in indirect mode and busy.
826  * @retval ::HAL_AES_STATE_ERROR: Peripheral in error.
827  * @retval ::HAL_AES_STATE_TIMEOUT: Peripheral in timeout.
828  * @retval ::HAL_AES_STATE_SUSPENDED: Peripheral in suspended.
829  ****************************************************************************************
830  */
832 
833 /**
834  ****************************************************************************************
835  * @brief Return the AES error code.
836  *
837  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
838  * the specified AES module.
839  *
840  * @return AES error code in bitmap format
841  ****************************************************************************************
842  */
844 
845 /**
846  ****************************************************************************************
847  * @brief Set the AES internal process timeout value.
848  *
849  * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
850  * the specified AES module.
851  * @param[in] timeout: Internal process timeout value.
852  ****************************************************************************************
853  */
854 void hal_aes_set_timeout(aes_handle_t *p_aes, uint32_t timeout);
855 
856 /**
857  ****************************************************************************************
858  * @brief Suspend some registers related to AES configuration before sleep.
859  * @param[in] p_aes: Pointer to a AES handle which contains the configuration
860  * information for the specified AES module.
861  * @retval ::HAL_OK: Operation is OK.
862  * @retval ::HAL_ERROR: Parameter error or operation not supported.
863  * @retval ::HAL_BUSY: Driver is busy.
864  * @retval ::HAL_TIMEOUT: Timeout occurred.
865  ****************************************************************************************
866  */
868 
869 /**
870  ****************************************************************************************
871  * @brief Restore some registers related to AES configuration after sleep.
872  * This function must be used in conjunction with the hal_aes_suspend_reg().
873  * @param[in] p_aes: Pointer to a AES handle which contains the configuration
874  * information for the specified AES module.
875  * @retval ::HAL_OK: Operation is OK.
876  * @retval ::HAL_ERROR: Parameter error or operation not supported.
877  * @retval ::HAL_BUSY: Driver is busy.
878  * @retval ::HAL_TIMEOUT: Timeout occurred.
879  ****************************************************************************************
880  */
882 
883 /** @} */
884 
885 /** @} */
886 
887 #ifdef __cplusplus
888 }
889 #endif
890 
891 #endif /* __GR55xx_HAL_AES_H__ */
892 
893 /** @} */
894 
895 /** @} */
896 
897 /** @} */
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_abort_it
hal_status_t hal_aes_abort_it(aes_handle_t *p_aes)
Abort the current encryption or decryption (non-blocking function)
hal_lock_t
hal_lock_t
HAL Lock structures definition.
Definition: gr55xx_hal_def.h:81
HAL_AES_STATE_RESET
@ HAL_AES_STATE_RESET
Peripheral not initialized
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)
AES init MSP callback
Definition: gr55xx_hal_aes.h:171
_aes_init::p_seed
uint32_t * p_seed
Random seeds.
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
Blocks count
Definition: gr55xx_hal_aes.h:141
_aes_init::p_key
uint32_t * p_key
Encryption/Decryption 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
Locking object
Definition: gr55xx_hal_aes.h:143
HAL_AES_STATE_TIMEOUT
@ HAL_AES_STATE_TIMEOUT
Peripheral in 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
AES 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.
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]
AES important register information.
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
Peripheral initialized and ready for use
Definition: gr55xx_hal_aes.h:78
_aes_init::p_init_vector
uint32_t * p_init_vector
Initialization Vector used for CBC modes.
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
AES operation 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
AES operation parameters
Definition: gr55xx_hal_aes.h:133
_aes_callback::aes_error_callback
void(* aes_error_callback)(aes_handle_t *p_aes)
AES error callback
Definition: gr55xx_hal_aes.h:173
_aes_callback::aes_done_callback
void(* aes_done_callback)(aes_handle_t *p_aes)
AES encrypt or decrypt done callback
Definition: gr55xx_hal_aes.h:174
hal_aes_abort
hal_status_t hal_aes_abort(aes_handle_t *p_aes)
Abort the current encryption or decryption.
_aes_handle::timeout
uint32_t timeout
Timeout for the AES operation
Definition: gr55xx_hal_aes.h:149
_aes_handle::p_instance
aes_regs_t * p_instance
AES registers base address
Definition: gr55xx_hal_aes.h:131
HAL_AES_STATE_ERROR
@ HAL_AES_STATE_ERROR
Peripheral in 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
DPA Mode.
Definition: gr55xx_hal_aes.h:115
_aes_init::operation_mode
uint32_t operation_mode
AES operating mode.
Definition: gr55xx_hal_aes.h:105
_aes_callback::aes_msp_deinit
void(* aes_msp_deinit)(aes_handle_t *p_aes)
AES de-init MSP callback
Definition: gr55xx_hal_aes.h:172
_aes_init::key_size
uint32_t key_size
128, 192 or 256-bits key length.
Definition: gr55xx_hal_aes.h:102
_aes_handle::block_size
uint32_t block_size
Data size in blocks (16 bytes per block)
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
Peripheral in suspended
Definition: gr55xx_hal_aes.h:82
_aes_handle::p_cryp_output_buffer
uint32_t * p_cryp_output_buffer
Pointer to CRYP processing (encryption or decryption) 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
Peripheral in indirect mode and 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
AES 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
Pointer to CRYP processing (encryption or decryption) 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.
_aes_callback::aes_abort_cplt_callback
void(* aes_abort_cplt_callback)(aes_handle_t *p_aes)
AES abort complete callback
Definition: gr55xx_hal_aes.h:175