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 */
83 } hal_aes_state_t;
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 Normally, it should be a global pointer. */
113
114 uint32_t *p_init_vector; /**< Initialization Vector used for CBC modes */
115
116 uint32_t dpa_mode; /**< DPA Mode */
117
118 uint32_t *p_seed; /**< Random seeds */
119
120 } aes_init_t;
121 /** @} */
122
123 /** @defgroup AES_handle AES Handle
124 * @{
125 */
126
127 /**
128 * @brief AES handle Structure definition
129 */
130 typedef struct _aes_handle
131 {
132 aes_regs_t *p_instance; /**< AES registers base address */
133
134 aes_init_t init; /**< AES operation parameters */
135
136 uint32_t *p_cryp_input_buffer; /**< Pointer to CRYP processing (encryption or decryption) input buffer */
137
138 uint32_t *p_cryp_output_buffer; /**< Pointer to CRYP processing (encryption or decryption) output buffer */
139
140 uint32_t block_size; /**< Data size in blocks (16 bytes per block) */
141
142 uint32_t block_count; /**< Blocks count */
143
144 __IO hal_lock_t lock; /**< Locking object */
145
146 __IO hal_aes_state_t state; /**< AES operation state */
147
148 __IO uint32_t error_code; /**< AES Error code */
149
150 uint32_t timeout; /**< Timeout for the AES operation */
151
152 uint32_t retention[18]; /**< AES important register information. */
153
154 } aes_handle_t;
155 /** @} */
156
157 /** @} */
158
159 /** @addtogroup HAL_AES_CALLBACK_STRUCTURES Callback Structures
160 * @{
161 */
162
163 /** @defgroup AES_Callback AES Callback
164 * @{
165 */
166
167 /**
168 * @brief HAL AES Callback function definition
169 */
170 typedef struct _aes_callback
171 {
172 void (*aes_msp_init)(aes_handle_t *p_aes); /**< AES init MSP callback */
173 void (*aes_msp_deinit)(aes_handle_t *p_aes); /**< AES de-init MSP callback */
174 void (*aes_error_callback)(aes_handle_t *p_aes); /**< AES error callback */
175 void (*aes_done_callback)(aes_handle_t *p_aes); /**< AES encrypt or decrypt done callback */
176 } aes_callback_t;
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 */
402 hal_status_t hal_aes_init(aes_handle_t *p_aes);
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 */
417 hal_status_t hal_aes_deinit(aes_handle_t *p_aes);
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 */
430 void hal_aes_msp_init(aes_handle_t *p_aes);
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 */
443 void hal_aes_msp_deinit(aes_handle_t *p_aes);
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 @endverbatim
492 * @{
493 */
494
495 /**
496 ****************************************************************************************
497 * @brief Encrypted an amount of data in blocking mode in ECB mode.
498 *
499 * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
500 * the specified AES module.
501 * @param[in] p_plain_data: Pointer to plain data buffer
502 * @param[in] number: Amount of data to be decrypted in bytes
503 * @param[out] p_cypher_data: Pointer to cypher data buffer
504 * @param[in] timeout: Timeout duration
505 *
506 * @retval ::HAL_OK: Operation is OK.
507 * @retval ::HAL_ERROR: Parameter error or operation not supported.
508 * @retval ::HAL_BUSY: Driver is busy.
509 * @retval ::HAL_TIMEOUT: Timeout occurred.
510 ****************************************************************************************
511 */
512 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);
513
514 /**
515 ****************************************************************************************
516 * @brief Decrypted an amount of data in blocking mode in ECB mode.
517 *
518 * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
519 * the specified AES module.
520 * @param[in] p_cypher_data: Pointer to cypher data buffer
521 * @param[in] number: Amount of data to be decrypted in bytes
522 * @param[out] p_plain_data: Pointer to plain data buffer
523 * @param[in] timeout: Timeout duration
524 *
525 * @retval ::HAL_OK: Operation is OK.
526 * @retval ::HAL_ERROR: Parameter error or operation not supported.
527 * @retval ::HAL_BUSY: Driver is busy.
528 * @retval ::HAL_TIMEOUT: Timeout occurred.
529 ****************************************************************************************
530 */
531 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);
532
533 /**
534 ****************************************************************************************
535 * @brief Encrypted an amount of data in blocking mode in CBC mode.
536 *
537 * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
538 * the specified AES module.
539 * @param[in] p_plain_data: Pointer to plain data buffer
540 * @param[in] number: Amount of data to be decrypted in bytes
541 * @param[out] p_cypher_data: Pointer to cypher data buffer
542 * @param[in] timeout: Timeout duration
543 *
544 * @retval ::HAL_OK: Operation is OK.
545 * @retval ::HAL_ERROR: Parameter error or operation not supported.
546 * @retval ::HAL_BUSY: Driver is busy.
547 * @retval ::HAL_TIMEOUT: Timeout occurred.
548 ****************************************************************************************
549 */
550 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);
551
552 /**
553 ****************************************************************************************
554 * @brief Decrypted an amount of data in blocking mode in CBC mode.
555 *
556 * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
557 * the specified AES module.
558 * @param[in] p_cypher_data: Pointer to cypher data buffer
559 * @param[in] number: Amount of data to be decrypted in bytes
560 * @param[out] p_plain_data: Pointer to plain data buffer
561 * @param[in] timeout: Timeout duration
562 *
563 * @retval ::HAL_OK: Operation is OK.
564 * @retval ::HAL_ERROR: Parameter error or operation not supported.
565 * @retval ::HAL_BUSY: Driver is busy.
566 * @retval ::HAL_TIMEOUT: Timeout occurred.
567 ****************************************************************************************
568 */
569 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);
570
571 /**
572 ****************************************************************************************
573 * @brief Encrypted an amount of data in non-blocking mode with Interrupt in ECB mode.
574 *
575 * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
576 * the specified AES module.
577 * @param[in] p_plain_data: Pointer to plain data buffer
578 * @param[in] number: Amount of data to be decrypted in bytes
579 * @param[out] p_cypher_data: Pointer to cypher data buffer
580 *
581 * @retval ::HAL_OK: Operation is OK.
582 * @retval ::HAL_ERROR: Parameter error or operation not supported.
583 * @retval ::HAL_BUSY: Driver is busy.
584 * @retval ::HAL_TIMEOUT: Timeout occurred.
585 ****************************************************************************************
586 */
587 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);
588
589 /**
590 ****************************************************************************************
591 * @brief Decrypted an amount of data in non-blocking mode with Interrupt in ECB mode.
592 *
593 * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
594 * the specified AES module.
595 * @param[in] p_cypher_data: Pointer to cypher data buffer
596 * @param[in] number: Amount of data to be decrypted in bytes
597 * @param[out] p_plain_data: Pointer to plain data buffer
598 *
599 * @retval ::HAL_OK: Operation is OK.
600 * @retval ::HAL_ERROR: Parameter error or operation not supported.
601 * @retval ::HAL_BUSY: Driver is busy.
602 * @retval ::HAL_TIMEOUT: Timeout occurred.
603 ****************************************************************************************
604 */
605 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);
606
607 /**
608 ****************************************************************************************
609 * @brief Encrypted an amount of data in non-blocking mode with Interrupt in CBC mode.
610 *
611 * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
612 * the specified AES module.
613 * @param[in] p_plain_data: Pointer to plain data buffer
614 * @param[in] number: Amount of data to be decrypted in bytes
615 * @param[out] p_cypher_data: Pointer to cypher data buffer
616 *
617 * @retval ::HAL_OK: Operation is OK.
618 * @retval ::HAL_ERROR: Parameter error or operation not supported.
619 * @retval ::HAL_BUSY: Driver is busy.
620 * @retval ::HAL_TIMEOUT: Timeout occurred.
621 ****************************************************************************************
622 */
623 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);
624
625 /**
626 ****************************************************************************************
627 * @brief Decrypted an amount of data in non-blocking mode with Interrupt in CBC mode.
628 *
629 * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
630 * the specified AES module.
631 * @param[in] p_cypher_data: Pointer to cypher data buffer
632 * @param[in] number: Amount of data to be decrypted in bytes
633 * @param[out] p_plain_data: Pointer to plain data buffer
634 *
635 * @retval ::HAL_OK: Operation is OK.
636 * @retval ::HAL_ERROR: Parameter error or operation not supported.
637 * @retval ::HAL_BUSY: Driver is busy.
638 * @retval ::HAL_TIMEOUT: Timeout occurred.
639 ****************************************************************************************
640 */
641 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);
642
643 /**
644 ****************************************************************************************
645 * @brief Encrypted an amount of data in non-blocking mode with DMA in ECB mode.
646 *
647 * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
648 * the specified AES module.
649 * @param[in] p_plain_data: Pointer to plain data buffer
650 * @param[in] number: Amount of data to be decrypted in bytes
651 * @param[out] p_cypher_data: Pointer to cypher data buffer
652 *
653 * @retval ::HAL_OK: Operation is OK.
654 * @retval ::HAL_ERROR: Parameter error or operation not supported.
655 * @retval ::HAL_BUSY: Driver is busy.
656 * @retval ::HAL_TIMEOUT: Timeout occurred.
657 ****************************************************************************************
658 */
659 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);
660
661 /**
662 ****************************************************************************************
663 * @brief Decrypted an amount of data in non-blocking mode with DMA in ECB mode.
664 *
665 * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
666 * the specified AES module.
667 * @param[in] p_cypher_data: Pointer to cypher data buffer
668 * @param[in] number: Amount of data to be decrypted in bytes
669 * @param[out] p_plain_data: Pointer to plain data buffer
670 *
671 * @retval ::HAL_OK: Operation is OK.
672 * @retval ::HAL_ERROR: Parameter error or operation not supported.
673 * @retval ::HAL_BUSY: Driver is busy.
674 * @retval ::HAL_TIMEOUT: Timeout occurred.
675 ****************************************************************************************
676 */
677 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);
678
679 /**
680 ****************************************************************************************
681 * @brief Encrypted an amount of data in non-blocking mode with DMA in CBC mode.
682 *
683 * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
684 * the specified AES module.
685 * @param[in] p_plain_data: Pointer to plain data buffer
686 * @param[in] number: Amount of data to be decrypted in bytes
687 * @param[out] p_cypher_data: Pointer to cypher data buffer
688 *
689 * @retval ::HAL_OK: Operation is OK.
690 * @retval ::HAL_ERROR: Parameter error or operation not supported.
691 * @retval ::HAL_BUSY: Driver is busy.
692 * @retval ::HAL_TIMEOUT: Timeout occurred.
693 ****************************************************************************************
694 */
695 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);
696
697 /**
698 ****************************************************************************************
699 * @brief Decrypted an amount of data in non-blocking mode with DMA in CBC mode.
700 *
701 * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
702 * the specified AES module.
703 * @param[in] p_cypher_data: Pointer to cypher data buffer
704 * @param[in] number: Amount of data to be decrypted in bytes
705 * @param[out] p_plain_data: Pointer to plain data buffer
706 *
707 * @retval ::HAL_OK: Operation is OK.
708 * @retval ::HAL_ERROR: Parameter error or operation not supported.
709 * @retval ::HAL_BUSY: Driver is busy.
710 * @retval ::HAL_TIMEOUT: Timeout occurred.
711 ****************************************************************************************
712 */
713 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);
714
715 /** @} */
716
717 /** @addtogroup AES_IRQ_Handler_and_Callbacks IRQ Handler and Callbacks
718 * @brief IRQ Handler and Callbacks functions
719 * @{
720 */
721
722 /**
723 ****************************************************************************************
724 * @brief Handle AES interrupt request.
725 *
726 * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
727 * the specified the specified AES module.
728 ****************************************************************************************
729 */
730 void hal_aes_irq_handler(aes_handle_t *p_aes);
731
732 /**
733 ****************************************************************************************
734 * @brief Encrypt or decrypt Done callback.
735 *
736 * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
737 * the specified AES module.
738 ****************************************************************************************
739 */
740 void hal_aes_done_callback(aes_handle_t *p_aes);
741
742 /**
743 ****************************************************************************************
744 * @brief AES error callback.
745 *
746 * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
747 * the specified AES module.
748 ****************************************************************************************
749 */
750 void hal_aes_error_callback(aes_handle_t *p_aes);
751
752 /** @} */
753
754 /** @defgroup AES_Exported_Functions_Group3 Peripheral State and Errors functions
755 * @brief AES control functions
756 *
757 @verbatim
758 ===============================================================================
759 ##### Peripheral State and Errors functions #####
760 ===============================================================================
761 [..]
762 This subsection provides a set of functions allowing to control the AES.
763 (+) hal_aes_get_state() API can be helpful to check in run-time the state of the AES peripheral.
764 (+) hal_aes_get_error() check in run-time Errors occurring during communication.
765 (+) hal_aes_set_timeout() set the timeout during internal process.
766 @endverbatim
767 * @{
768 */
769
770 /**
771 ****************************************************************************************
772 * @brief Return the AES handle state.
773 *
774 * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
775 * the specified AES module.
776 *
777 * @retval ::HAL_AES_STATE_RESET: Peripheral not initialized.
778 * @retval ::HAL_AES_STATE_READY: Peripheral initialized and ready for use.
779 * @retval ::HAL_AES_STATE_BUSY: Peripheral in indirect mode and busy.
780 * @retval ::HAL_AES_STATE_ERROR: Peripheral in error.
781 * @retval ::HAL_AES_STATE_TIMEOUT: Peripheral in timeout.
782 * @retval ::HAL_AES_STATE_SUSPENDED: Peripheral in suspended.
783 ****************************************************************************************
784 */
785 hal_aes_state_t hal_aes_get_state(aes_handle_t *p_aes);
786
787 /**
788 ****************************************************************************************
789 * @brief Return the AES error code.
790 *
791 * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
792 * the specified AES module.
793 *
794 * @return AES error code in bitmap format
795 ****************************************************************************************
796 */
797 uint32_t hal_aes_get_error(aes_handle_t *p_aes);
798
799 /**
800 ****************************************************************************************
801 * @brief Set the AES internal process timeout value.
802 *
803 * @param[in] p_aes: Pointer to an AES handle which contains the configuration information for
804 * the specified AES module.
805 * @param[in] timeout: Internal process timeout value.
806 ****************************************************************************************
807 */
808 void hal_aes_set_timeout(aes_handle_t *p_aes, uint32_t timeout);
809
810 /**
811 ****************************************************************************************
812 * @brief Suspend some registers related to AES configuration before sleep.
813 * @param[in] p_aes: Pointer to a AES handle which contains the configuration
814 * information for the specified AES module.
815 * @retval ::HAL_OK: Operation is OK.
816 * @retval ::HAL_ERROR: Parameter error or operation not supported.
817 * @retval ::HAL_BUSY: Driver is busy.
818 * @retval ::HAL_TIMEOUT: Timeout occurred.
819 ****************************************************************************************
820 */
821 hal_status_t hal_aes_suspend_reg(aes_handle_t *p_aes);
822
823 /**
824 ****************************************************************************************
825 * @brief Restore some registers related to AES configuration after sleep.
826 * This function must be used in conjunction with the hal_aes_suspend_reg().
827 * @param[in] p_aes: Pointer to a AES handle which contains the configuration
828 * information for the specified AES module.
829 * @retval ::HAL_OK: Operation is OK.
830 * @retval ::HAL_ERROR: Parameter error or operation not supported.
831 * @retval ::HAL_BUSY: Driver is busy.
832 * @retval ::HAL_TIMEOUT: Timeout occurred.
833 ****************************************************************************************
834 */
835 hal_status_t hal_aes_resume_reg(aes_handle_t *p_aes);
836
837 /** @} */
838
839 /** @} */
840
841 #ifdef __cplusplus
842 }
843 #endif
844
845 #endif /* __GR55xx_HAL_AES_H__ */
846
847 /** @} */
848
849 /** @} */
850
851 /** @} */
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:172
_aes_init::p_seed
uint32_t * p_seed
Definition: gr55xx_hal_aes.h:118
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:142
_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:144
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:148
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:152
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:114
_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:146
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:134
_aes_callback::aes_error_callback
void(* aes_error_callback)(aes_handle_t *p_aes)
Definition: gr55xx_hal_aes.h:174
_aes_callback::aes_done_callback
void(* aes_done_callback)(aes_handle_t *p_aes)
Definition: gr55xx_hal_aes.h:175
_aes_handle::timeout
uint32_t timeout
Definition: gr55xx_hal_aes.h:150
_aes_handle::p_instance
aes_regs_t * p_instance
Definition: gr55xx_hal_aes.h:132
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:131
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:116
_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:173
_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:140
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:138
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:171
_aes_handle::p_cryp_input_buffer
uint32_t * p_cryp_input_buffer
Definition: gr55xx_hal_aes.h:136
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.