gr55xx_hal_hmac.h
Go to the documentation of this file.
1
51 /* Define to prevent recursive inclusion -------------------------------------*/
52 #ifndef __GR55xx_HAL_HMAC_H__
53 #define __GR55xx_HAL_HMAC_H__
54
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58
59 /* Includes ------------------------------------------------------------------*/
60 #include "gr55xx_ll_hmac.h"
61 #include "gr55xx_hal_def.h"
62
63 /* Exported types ------------------------------------------------------------*/
76 typedef enum
77 {
78 HAL_HMAC_STATE_RESET = 0x00,
79 HAL_HMAC_STATE_READY = 0x01,
80 HAL_HMAC_STATE_BUSY = 0x02,
81 HAL_HMAC_STATE_ERROR = 0x03,
82 HAL_HMAC_STATE_TIMEOUT = 0x04,
83 HAL_HMAC_STATE_SUSPENDED = 0x05,
85 } hal_hmac_state_t;
86
102 typedef struct _hmac_init
103 {
104 uint32_t mode;
106 uint32_t *p_key;
108 uint32_t *p_user_hash;
110 uint32_t key_fetch_type;
115 uint32_t dpa_mode;
116 uint32_t enable_irq;
117 uint32_t enable_dma_mode;
119 } hmac_init_t;
129 typedef struct _hmac_handle
130 {
131 hmac_regs_t *p_instance;
133 hmac_init_t init;
135 uint32_t *p_message;
137 uint32_t *p_digest;
139 uint32_t block_size;
141 uint32_t block_count;
143 uint32_t is_last_trans;
145 __IO hal_lock_t lock;
147 __IO hal_hmac_state_t state;
149 __IO uint32_t error_code;
151 uint32_t timeout;
153 uint32_t retention[17];
155 } hmac_handle_t;
156
173 typedef struct _hal_hmac_callback
174 {
175 void (*hmac_msp_init)(hmac_handle_t *p_hmac);
176 void (*hmac_msp_deinit)(hmac_handle_t *p_hmac);
177 void (*hmac_done_callback)(hmac_handle_t *p_hmac);
178 void (*hmac_error_callback)(hmac_handle_t *p_hmac);
179 } hal_hmac_callback_t;
180
190 /* Exported constants --------------------------------------------------------*/
198 #define HAL_HMAC_ERROR_NONE ((uint32_t)0x00000000)
199 #define HAL_HMAC_ERROR_TIMEOUT ((uint32_t)0x00000001)
200 #define HAL_HMAC_ERROR_TRANSFER ((uint32_t)0x00000002)
201 #define HAL_HMAC_ERROR_INVALID_PARAM ((uint32_t)0x00000004)
207 #define HMAC_MODE_SHA LL_HMAC_CALCULATETYPE_SHA
208 #define HMAC_MODE_HMAC LL_HMAC_CALCULATETYPE_HMAC
214 #define HMAC_BLOCK_MAX (512)
215 #define HMAC_BLOCKSIZE_BITS (512)
216 #define HMAC_BLOCKSIZE_BYTES (HMAC_BLOCKSIZE_BITS >> 3)
217 #define HMAC_BLOCKSIZE_WORDS (HMAC_BLOCKSIZE_BYTES >> 2)
218 #define HMAC_DIGESTSIZE_BITS (256)
219 #define HMAC_DIGESTSIZE_BYTES (HMAC_DIGESTSIZE_BITS >> 3)
220 #define HMAC_DIGESTSIZE_WORDS (HMAC_DIGESTSIZE_BYTES >> 2)
221 #define HMAC_DMA_BLOCK_MAX (512)
227 #define HMAC_FLAG_DATAREADY_SHA LL_HMAC_FLAG_DATAREADY_SHA
228 #define HMAC_FLAG_DATAREADY_HMAC LL_HMAC_FLAG_DATAREADY_HMAC
229 #define HMAC_FLAG_DMA_MESSAGEDONE LL_HMAC_FLAG_DMA_MESSAGEDONE
230 #define HMAC_FLAG_DMA_DONE LL_HMAC_FLAG_DMA_DONE
231 #define HMAC_FLAG_DMA_ERR LL_HMAC_FLAG_DMA_ERR
232 #define HMAC_FLAG_KEY_VALID LL_HMAC_FLAG_KEY_VALID
238 #define HAL_HMAC_KEYTYPE_MCU LL_HMAC_KEYTYPE_MCU
239 /* { Start_private */
240 #define HAL_HMAC_KEYTYPE_AHB LL_HMAC_KEYTYPE_AHB
241 /* } End_private */
242 #define HAL_HMAC_KEYTYPE_KRAM LL_HMAC_KEYTYPE_KRAM
248 #define HAL_HMAC_ENABLE_IRQ (0x1)
249 #define HAL_HMAC_DISABLE_IRQ (0x0)
255 #define HAL_HMAC_ENABLE_DMA (0x1)
256 #define HAL_HMAC_DISABLE_DMA (0x0)
262 #define HMAC_IT_DONE ((uint32_t)0x00000001)
268 #define HAL_HMAC_TIMEOUT_DEFAULT_VALUE ((uint32_t)5000)
273 /* Exported macro ------------------------------------------------------------*/
274
282 #define __HAL_HMAC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->state = HAL_HMAC_STATE_RESET)
283
288 #define __HAL_HMAC_ENABLE(__HANDLE__) SET_BITS((__HANDLE__)->p_instance->CTRL, HMAC_CTRL_ENABLE)
289
294 #define __HAL_HMAC_DISABLE(__HANDLE__) CLEAR_BITS((__HANDLE__)->p_instance->CTRL, HMAC_CTRL_ENABLE)
295
300 #define __HAL_HMAC_ENABLE_IT(__HANDLE__) ll_hmac_enable_it_done((__HANDLE__)->p_instance)
301
306 #define __HAL_HMAC_DISABLE_IT(__HANDLE__) ll_hmac_disable_it_done((__HANDLE__)->p_instance)
307
315 #define __HAL_HMAC_GET_FLAG_IT(__HANDLE__, __FLAG__) (READ_BITS((__HANDLE__)->p_instance->INTERRUPT, (__FLAG__)) == (__FLAG__))
316
324 #define __HAL_HMAC_CLEAR_FLAG_IT(__HANDLE__, __FLAG__) SET_BITS((__HANDLE__)->p_instance->INTERRUPT, (__FLAG__))
325
337 #define __HAL_HMAC_GET_FLAG(__HANDLE__, __FLAG__) ((READ_BITS((__HANDLE__)->p_instance->STATUS, (__FLAG__)) != 0) ? SET : RESET)
338
343 /* Exported functions --------------------------------------------------------*/
386 hal_status_t hal_hmac_init(hmac_handle_t *p_hmac);
387
398 hal_status_t hal_hmac_deinit(hmac_handle_t *p_hmac);
399
408 void hal_hmac_msp_init(hmac_handle_t *p_hmac);
409
418 void hal_hmac_msp_deinit(hmac_handle_t *p_hmac);
419
491 hal_status_t hal_hmac_sha256_digest(hmac_handle_t *p_hmac, uint32_t *p_message, uint32_t number, uint32_t *p_digest, uint32_t timeout);
492
507 hal_status_t hal_hmac_sha256_digest_poll(hmac_handle_t *p_hmac, uint32_t *p_message, uint32_t number, uint32_t *p_digest, uint32_t timeout);
508
523 hal_status_t hal_hmac_sha256_digest_it(hmac_handle_t *p_hmac, uint32_t *p_message, uint32_t number, uint32_t *p_digest, uint32_t timeout);
524
539 hal_status_t hal_hmac_sha256_digest_dma(hmac_handle_t *p_hmac, uint32_t *p_message, uint32_t number, uint32_t *p_digest, uint32_t timeout);
540
554 void hal_hmac_irq_handler(hmac_handle_t *p_hmac);
555
562 void hal_hmac_done_callback(hmac_handle_t *p_hmac);
563
570 void hal_hmac_error_callback(hmac_handle_t *p_hmac);
571
602 hal_hmac_state_t hal_hmac_get_state(hmac_handle_t *p_hmac);
603
611 uint32_t hal_hmac_get_error(hmac_handle_t *p_hmac);
612
620 void hal_hmac_set_timeout(hmac_handle_t *p_hmac, uint32_t timeout);
621
622
634 hal_status_t hal_hmac_suspend_reg(hmac_handle_t *p_hmac);
635
648 hal_status_t hal_hmac_resume_reg(hmac_handle_t *p_hmac);
649
650
655 #ifdef __cplusplus
656 }
657 #endif
658
659 #endif /* __GR55xx_HAL_HMAC_H__ */
660
_hmac_init::key_fetch_type
uint32_t key_fetch_type
Definition: gr55xx_hal_hmac.h:110
_hmac_init::p_user_hash
uint32_t * p_user_hash
Definition: gr55xx_hal_hmac.h:108
hal_hmac_get_error
uint32_t hal_hmac_get_error(hmac_handle_t *p_hmac)
Return the HMAC error code.
hal_hmac_resume_reg
hal_status_t hal_hmac_resume_reg(hmac_handle_t *p_hmac)
Restore some registers related to HMAC configuration after sleep. This function must be used in conju...
hal_hmac_irq_handler
void hal_hmac_irq_handler(hmac_handle_t *p_hmac)
Handle HMAC interrupt request.
_hmac_init
HMAC init Structure definition.
Definition: gr55xx_hal_hmac.h:103
hal_lock_t
hal_lock_t
HAL Lock structures definition.
Definition: gr55xx_hal_def.h:81
_hal_hmac_callback::hmac_msp_init
void(* hmac_msp_init)(hmac_handle_t *p_hmac)
Definition: gr55xx_hal_hmac.h:175
_hmac_handle::p_message
uint32_t * p_message
Definition: gr55xx_hal_hmac.h:135
hmac_handle_t
struct _hmac_handle hmac_handle_t
HMAC handle Structure definition.
hal_hmac_suspend_reg
hal_status_t hal_hmac_suspend_reg(hmac_handle_t *p_hmac)
Suspend some registers related to HMAC configuration before sleep.
_hmac_handle::state
__IO hal_hmac_state_t state
Definition: gr55xx_hal_hmac.h:147
HAL_HMAC_STATE_TIMEOUT
@ HAL_HMAC_STATE_TIMEOUT
Definition: gr55xx_hal_hmac.h:82
hal_hmac_msp_init
void hal_hmac_msp_init(hmac_handle_t *p_hmac)
Initialize the HMAC MSP.
_hmac_handle::error_code
__IO uint32_t error_code
Definition: gr55xx_hal_hmac.h:149
HAL_HMAC_STATE_SUSPENDED
@ HAL_HMAC_STATE_SUSPENDED
Definition: gr55xx_hal_hmac.h:83
_hmac_handle::init
hmac_init_t init
Definition: gr55xx_hal_hmac.h:133
hal_hmac_msp_deinit
void hal_hmac_msp_deinit(hmac_handle_t *p_hmac)
De-initialize the HMAC MSP.
hal_hmac_init
hal_status_t hal_hmac_init(hmac_handle_t *p_hmac)
Initialize the HMAC according to the specified parameters in the hmac_init_t and initialize the assoc...
_hal_hmac_callback::hmac_error_callback
void(* hmac_error_callback)(hmac_handle_t *p_hmac)
Definition: gr55xx_hal_hmac.h:178
HAL_HMAC_STATE_ERROR
@ HAL_HMAC_STATE_ERROR
Definition: gr55xx_hal_hmac.h:81
hal_hmac_sha256_digest_poll
hal_status_t hal_hmac_sha256_digest_poll(hmac_handle_t *p_hmac, uint32_t *p_message, uint32_t number, uint32_t *p_digest, uint32_t timeout)
xxx in polling mode in HMAC/SHA mode.
hal_hmac_callback_t
struct _hal_hmac_callback hal_hmac_callback_t
HAL_HMAC Callback function definition.
_hmac_handle::p_instance
hmac_regs_t * p_instance
Definition: gr55xx_hal_hmac.h:131
HAL_HMAC_STATE_RESET
@ HAL_HMAC_STATE_RESET
Definition: gr55xx_hal_hmac.h:78
hmac_init_t
struct _hmac_init hmac_init_t
HMAC init Structure definition.
_hmac_init::enable_dma_mode
uint32_t enable_dma_mode
Definition: gr55xx_hal_hmac.h:117
hal_hmac_set_timeout
void hal_hmac_set_timeout(hmac_handle_t *p_hmac, uint32_t timeout)
Set the HMAC internal process timeout value.
hal_hmac_sha256_digest_it
hal_status_t hal_hmac_sha256_digest_it(hmac_handle_t *p_hmac, uint32_t *p_message, uint32_t number, uint32_t *p_digest, uint32_t timeout)
xxx in interrupt mode in HMAC/SHA mode.
hal_hmac_sha256_digest_dma
hal_status_t hal_hmac_sha256_digest_dma(hmac_handle_t *p_hmac, uint32_t *p_message, uint32_t number, uint32_t *p_digest, uint32_t timeout)
xxx in DMA mode in HMAC/SHA mode.
hal_hmac_error_callback
void hal_hmac_error_callback(hmac_handle_t *p_hmac)
HMAC error callback.
_hmac_init::dpa_mode
uint32_t dpa_mode
Definition: gr55xx_hal_hmac.h:115
_hmac_handle::block_count
uint32_t block_count
Definition: gr55xx_hal_hmac.h:141
_hmac_handle::lock
__IO hal_lock_t lock
Definition: gr55xx_hal_hmac.h:145
_hmac_init::p_key
uint32_t * p_key
Definition: gr55xx_hal_hmac.h:106
hal_hmac_get_state
hal_hmac_state_t hal_hmac_get_state(hmac_handle_t *p_hmac)
Return the HMAC handle state.
hal_hmac_sha256_digest
hal_status_t hal_hmac_sha256_digest(hmac_handle_t *p_hmac, uint32_t *p_message, uint32_t number, uint32_t *p_digest, uint32_t timeout)
xxx in blocking mode in SHA mode.
_hmac_handle
HMAC handle Structure definition.
Definition: gr55xx_hal_hmac.h:130
_hmac_init::enable_irq
uint32_t enable_irq
Definition: gr55xx_hal_hmac.h:116
hal_status_t
hal_status_t
HAL Status structures definition.
Definition: gr55xx_hal_def.h:70
_hal_hmac_callback::hmac_msp_deinit
void(* hmac_msp_deinit)(hmac_handle_t *p_hmac)
Definition: gr55xx_hal_hmac.h:176
_hal_hmac_callback::hmac_done_callback
void(* hmac_done_callback)(hmac_handle_t *p_hmac)
Definition: gr55xx_hal_hmac.h:177
hal_hmac_done_callback
void hal_hmac_done_callback(hmac_handle_t *p_hmac)
Digest Done callback.
HAL_HMAC_STATE_READY
@ HAL_HMAC_STATE_READY
Definition: gr55xx_hal_hmac.h:79
_hmac_init::mode
uint32_t mode
Definition: gr55xx_hal_hmac.h:104
_hmac_handle::is_last_trans
uint32_t is_last_trans
Definition: gr55xx_hal_hmac.h:143
hal_hmac_state_t
hal_hmac_state_t
HAL HMAC State enumerations definition.
Definition: gr55xx_hal_hmac.h:77
_hmac_handle::block_size
uint32_t block_size
Definition: gr55xx_hal_hmac.h:139
hal_hmac_deinit
hal_status_t hal_hmac_deinit(hmac_handle_t *p_hmac)
De-initialize the HMAC peripheral.
_hmac_handle::p_digest
uint32_t * p_digest
Definition: gr55xx_hal_hmac.h:137
_hmac_handle::retention
uint32_t retention[17]
Definition: gr55xx_hal_hmac.h:153
_hmac_handle::timeout
uint32_t timeout
Definition: gr55xx_hal_hmac.h:151
gr55xx_ll_hmac.h
Header file containing functions prototypes of HMAC LL library.
_hal_hmac_callback
HAL_HMAC Callback function definition.
Definition: gr55xx_hal_hmac.h:174
gr55xx_hal_def.h
This file contains HAL common definitions, enumeration, macros and structures definitions.
HAL_HMAC_STATE_BUSY
@ HAL_HMAC_STATE_BUSY
Definition: gr55xx_hal_hmac.h:80