gr55xx_hal_aes.h
Go to the documentation of this file.
1 
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 ------------------------------------------------------------*/
75 typedef enum
76 {
84 
100 typedef struct _aes_init
101 {
102  uint32_t key_size;
105  uint32_t operation_mode;
108  uint32_t chaining_mode;
111  uint32_t *p_key;
113  uint32_t *p_init_vector;
115  uint32_t dpa_mode;
117  uint32_t *p_seed;
129 typedef struct _aes_handle
130 {
131  aes_regs_t *p_instance;
139  uint32_t block_size;
141  uint32_t block_count;
147  __IO uint32_t error_code;
149  uint32_t timeout;
151  uint32_t retention[18];
169 typedef struct _aes_callback
170 {
171  void (*aes_msp_init)(aes_handle_t *p_aes);
172  void (*aes_msp_deinit)(aes_handle_t *p_aes);
174  void (*aes_done_callback)(aes_handle_t *p_aes);
177 
187 /* Exported constants --------------------------------------------------------*/
195 #define HAL_AES_ERROR_NONE ((uint32_t)0x00000000)
196 #define HAL_AES_ERROR_TIMEOUT ((uint32_t)0x00000001)
197 #define HAL_AES_ERROR_TRANSFER ((uint32_t)0x00000002)
198 #define HAL_AES_ERROR_INVALID_PARAM ((uint32_t)0x00000004)
204 #define AES_KEYSIZE_128BITS LL_AES_KEY_SIZE_128
205 #define AES_KEYSIZE_192BITS LL_AES_KEY_SIZE_192
206 #define AES_KEYSIZE_256BITS LL_AES_KEY_SIZE_256
212 #define AES_BLOCK_MAX (2048)
213 #define AES_BLOCKSIZE_BITS (128)
214 #define AES_BLOCKSIZE_BYTES (AES_BLOCKSIZE_BITS >> 3)
215 #define AES_BLOCKSIZE_WORDS (AES_BLOCKSIZE_BYTES >> 2)
221 #define AES_OPERATION_MODE_ENCRYPT (1)
222 #define AES_OPERATION_MODE_DECRYPT (0)
228 #define AES_CHAININGMODE_ECB LL_AES_OPERATION_MODE_ECB
229 #define AES_CHAININGMODE_CBC LL_AES_OPERATION_MODE_CBC
235 #define AES_FLAG_DATAREADY LL_AES_FLAG_DATAREADY
236 #define AES_FLAG_DMA_DONE LL_AES_FLAG_DMA_DONE
237 #define AES_FLAG_DMA_ERR LL_AES_FLAG_DMA_ERR
238 #define AES_FLAG_KEY_VALID LL_AES_FLAG_KEY_VALID
244 #define AES_IT_DONE ((uint32_t)0x00000001)
250 #define HAL_AES_TIMEOUT_DEFAULT_VALUE ((uint32_t)5000)
255 /* Exported macro ------------------------------------------------------------*/
256 
264 #define __HAL_AES_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->state = HAL_AES_STATE_RESET)
265 
270 #define __HAL_AES_ENABLE(__HANDLE__) SET_BITS((__HANDLE__)->p_instance->CTRL, AES_CTRL_ENABLE)
271 
276 #define __HAL_AES_DISABLE(__HANDLE__) CLEAR_BITS((__HANDLE__)->p_instance->CTRL, AES_CTRL_ENABLE)
277 
282 #define __HAL_AES_ENABLE_IT(__HANDLE__) ll_aes_enable_it_done((__HANDLE__)->p_instance)
283 
288 #define __HAL_AES_DISABLE_IT(__HANDLE__) ll_aes_disable_it_done((__HANDLE__)->p_instance)
289 
297 #define __HAL_AES_GET_FLAG_IT(__HANDLE__, __FLAG__) (READ_BITS((__HANDLE__)->p_instance->INTERRUPT, (__FLAG__)) == (__FLAG__))
298 
306 #define __HAL_AES_CLEAR_FLAG_IT(__HANDLE__, __FLAG__) SET_BITS((__HANDLE__)->p_instance->INTERRUPT, (__FLAG__))
307 
318 #define __HAL_AES_GET_FLAG(__HANDLE__, __FLAG__) ((READ_BITS((__HANDLE__)->p_instance->STATUS, (__FLAG__)) != 0) ? SET : RESET)
319 
322 /* Private macros ------------------------------------------------------------*/
331 #define IS_AES_KEY_SIZE(__SIZE__) (((__SIZE__) == AES_KEYSIZE_128BITS) || \
332  ((__SIZE__) == AES_KEYSIZE_192BITS) || \
333  ((__SIZE__) == AES_KEYSIZE_256BITS))
334 
339 #define IS_AES_OPERATION_MODE(__MODE__) (((__MODE__) == AES_OPERATION_MODE_ENCRYPT) || \
340  ((__MODE__) == AES_OPERATION_MODE_DECRYPT))
341 
346 #define IS_AES_CHAININGMODE(__MODE__) (((__MODE__) == AES_CHAININGMODE_ECB) || \
347  ((__MODE__) == AES_CHAININGMODE_CBC))
348 
353 /* Exported functions --------------------------------------------------------*/
403 
418 
431 
444 
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 
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 
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 
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 
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 
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 
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 
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 
664 
679 
696 
706 
716 
725 
760 
772 
782 void hal_aes_set_timeout(aes_handle_t *p_aes, uint32_t timeout);
783 
796 
810 
815 #ifdef __cplusplus
816 }
817 #endif
818 
819 #endif /* __GR55xx_HAL_AES_H__ */
820 
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
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_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.
_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
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
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_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_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.
_aes_callback::aes_abort_cplt_callback
void(* aes_abort_cplt_callback)(aes_handle_t *p_aes)
Definition: gr55xx_hal_aes.h:175