20#ifndef STM32H7xx_HAL_HASH_H
21#define STM32H7xx_HAL_HASH_H
63 HAL_HASH_STATE_RESET = 0x00U,
64 HAL_HASH_STATE_READY = 0x01U,
65 HAL_HASH_STATE_BUSY = 0x02U,
66 HAL_HASH_STATE_TIMEOUT = 0x06U,
67 HAL_HASH_STATE_ERROR = 0x07U,
68 HAL_HASH_STATE_SUSPENDED = 0x08U
69} HAL_HASH_StateTypeDef;
76 HAL_HASH_PHASE_READY = 0x01U,
77 HAL_HASH_PHASE_PROCESS = 0x02U,
78 HAL_HASH_PHASE_HMAC_STEP_1 = 0x03U,
80 HAL_HASH_PHASE_HMAC_STEP_2 = 0x04U,
82 HAL_HASH_PHASE_HMAC_STEP_3 = 0x05U
84} HAL_HASH_PhaseTypeDef;
91 HAL_HASH_SUSPEND_NONE = 0x00U,
92 HAL_HASH_SUSPEND = 0x01U
93} HAL_HASH_SuspendTypeDef;
95#if (USE_HAL_HASH_REGISTER_CALLBACKS == 1U)
101 HAL_HASH_MSPINIT_CB_ID = 0x00U,
102 HAL_HASH_MSPDEINIT_CB_ID = 0x01U,
103 HAL_HASH_INPUTCPLT_CB_ID = 0x02U,
104 HAL_HASH_DGSTCPLT_CB_ID = 0x03U,
105 HAL_HASH_ERROR_CB_ID = 0x04U,
106} HAL_HASH_CallbackIDTypeDef;
113#if (USE_HAL_HASH_REGISTER_CALLBACKS == 1)
114typedef struct __HASH_HandleTypeDef
119 HASH_InitTypeDef Init;
121 uint8_t *pHashInBuffPtr;
123 uint8_t *pHashOutBuffPtr;
125 uint8_t *pHashKeyBuffPtr;
127 uint8_t *pHashMsgBuffPtr;
129 uint32_t HashBuffSize;
131 __IO uint32_t HashInCount;
133 __IO uint32_t HashITCounter;
135 __IO uint32_t HashKeyCount;
139 HAL_HASH_PhaseTypeDef Phase;
145 __IO HAL_HASH_StateTypeDef State;
147 HAL_HASH_SuspendTypeDef SuspendRequest;
149 FlagStatus DigestCalculationDisable;
151 __IO uint32_t NbWordsAlreadyPushed;
153 __IO uint32_t ErrorCode;
155 __IO uint32_t Accumulation;
157#if (USE_HAL_HASH_REGISTER_CALLBACKS == 1)
158 void (* InCpltCallback)(
struct __HASH_HandleTypeDef *hhash);
160 void (* DgstCpltCallback)(
struct __HASH_HandleTypeDef *hhash);
162 void (* ErrorCallback)(
struct __HASH_HandleTypeDef *hhash);
164 void (* MspInitCallback)(
struct __HASH_HandleTypeDef *hhash);
166 void (* MspDeInitCallback)(
struct __HASH_HandleTypeDef *hhash);
171#if (USE_HAL_HASH_REGISTER_CALLBACKS == 1U)
175typedef void (*pHASH_CallbackTypeDef)(HASH_HandleTypeDef *hhash);
193#define HASH_ALGOSELECTION_SHA1 0x00000000U
194#define HASH_ALGOSELECTION_MD5 HASH_CR_ALGO_0
195#define HASH_ALGOSELECTION_SHA224 HASH_CR_ALGO_1
196#define HASH_ALGOSELECTION_SHA256 HASH_CR_ALGO
205#define HASH_ALGOMODE_HASH 0x00000000U
206#define HASH_ALGOMODE_HMAC HASH_CR_MODE
215#define HASH_DATATYPE_32B 0x00000000U
216#define HASH_DATATYPE_16B HASH_CR_DATATYPE_0
217#define HASH_DATATYPE_8B HASH_CR_DATATYPE_1
218#define HASH_DATATYPE_1B HASH_CR_DATATYPE
227#define HASH_HMAC_KEYTYPE_SHORTKEY 0x00000000U
228#define HASH_HMAC_KEYTYPE_LONGKEY HASH_CR_LKEY
237#define HASH_FLAG_DINIS HASH_SR_DINIS
238#define HASH_FLAG_DCIS HASH_SR_DCIS
239#define HASH_FLAG_DMAS HASH_SR_DMAS
240#define HASH_FLAG_BUSY HASH_SR_BUSY
241#define HASH_FLAG_DINNE HASH_CR_DINNE
251#define HASH_IT_DINI HASH_IMR_DINIE
252#define HASH_IT_DCI HASH_IMR_DCIE
262#define HAL_HASH_ERROR_NONE 0x00000000U
263#define HAL_HASH_ERROR_IT 0x00000001U
264#define HAL_HASH_ERROR_DMA 0x00000002U
265#if (USE_HAL_HASH_REGISTER_CALLBACKS == 1U)
266#define HAL_HASH_ERROR_INVALID_CALLBACK 0x00000004U
292#define __HAL_HASH_GET_FLAG(__FLAG__) (((__FLAG__) > 8U) ? \
293 ((HASH->CR & (__FLAG__)) == (__FLAG__)) :\
294 ((HASH->SR & (__FLAG__)) == (__FLAG__)) )
304#define __HAL_HASH_CLEAR_FLAG(__FLAG__) CLEAR_BIT(HASH->SR, (__FLAG__))
314#define __HAL_HASH_ENABLE_IT(__INTERRUPT__) SET_BIT(HASH->IMR, (__INTERRUPT__))
323#define __HAL_HASH_DISABLE_IT(__INTERRUPT__) CLEAR_BIT(HASH->IMR, (__INTERRUPT__))
330#if (USE_HAL_HASH_REGISTER_CALLBACKS == 1)
331#define __HAL_HASH_RESET_HANDLE_STATE(__HANDLE__) do{\
332 (__HANDLE__)->State = HAL_HASH_STATE_RESET;\
333 (__HANDLE__)->MspInitCallback = NULL; \
334 (__HANDLE__)->MspDeInitCallback = NULL; \
337#define __HAL_HASH_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_HASH_STATE_RESET)
345#define __HAL_HASH_RESET_HANDLE_STATUS(__HANDLE__) ((__HANDLE__)->Status = HAL_OK)
352#define __HAL_HASH_SET_MDMAT() SET_BIT(HASH->CR, HASH_CR_MDMAT)
358#define __HAL_HASH_RESET_MDMAT() CLEAR_BIT(HASH->CR, HASH_CR_MDMAT)
365#define __HAL_HASH_START_DIGEST() SET_BIT(HASH->STR, HASH_STR_DCAL)
372#define __HAL_HASH_SET_NBVALIDBITS(__SIZE__) MODIFY_REG(HASH->STR, HASH_STR_NBLW, 8U * ((__SIZE__) % 4U))
378#define __HAL_HASH_INIT() SET_BIT(HASH->CR, HASH_CR_INIT)
394#define HASH_DIGEST_LENGTH() ((READ_BIT(HASH->CR, HASH_CR_ALGO) == HASH_ALGOSELECTION_SHA1) ? 20U : \
395 ((READ_BIT(HASH->CR, HASH_CR_ALGO) == HASH_ALGOSELECTION_SHA224) ? 28U : \
396 ((READ_BIT(HASH->CR, HASH_CR_ALGO) == HASH_ALGOSELECTION_SHA256) ? 32U : 16U ) ) )
401#define HASH_NBW_PUSHED() ((READ_BIT(HASH->CR, HASH_CR_NBW)) >> 8U)
408#define IS_HASH_DATATYPE(__DATATYPE__) (((__DATATYPE__) == HASH_DATATYPE_32B)|| \
409 ((__DATATYPE__) == HASH_DATATYPE_16B)|| \
410 ((__DATATYPE__) == HASH_DATATYPE_8B) || \
411 ((__DATATYPE__) == HASH_DATATYPE_1B))
420#define IS_HASH_DMA_MULTIBUFFER_SIZE(__SIZE__) ((READ_BIT(HASH->CR, HASH_CR_MDMAT) == 0U) || (((__SIZE__) % 4U) == 0U))
430#define IS_HMAC_DMA_MULTIBUFFER_SIZE(__HANDLE__,__SIZE__) ((((__HANDLE__)->DigestCalculationDisable) == RESET)\
431 || (((__SIZE__) % 4U) == 0U))
437#define IS_HASH_PROCESSING(__HANDLE__) ((__HANDLE__)->Phase == HAL_HASH_PHASE_PROCESS)
444#define IS_HMAC_PROCESSING(__HANDLE__) (((__HANDLE__)->Phase == HAL_HASH_PHASE_HMAC_STEP_1) || \
445 ((__HANDLE__)->Phase == HAL_HASH_PHASE_HMAC_STEP_2) || \
446 ((__HANDLE__)->Phase == HAL_HASH_PHASE_HMAC_STEP_3))
467void HAL_HASH_MspInit(HASH_HandleTypeDef *hhash);
468void HAL_HASH_MspDeInit(HASH_HandleTypeDef *hhash);
469void HAL_HASH_InCpltCallback(HASH_HandleTypeDef *hhash);
470void HAL_HASH_DgstCpltCallback(HASH_HandleTypeDef *hhash);
471void HAL_HASH_ErrorCallback(HASH_HandleTypeDef *hhash);
473#if (USE_HAL_HASH_REGISTER_CALLBACKS == 1)
474HAL_StatusTypeDef HAL_HASH_RegisterCallback(HASH_HandleTypeDef *hhash, HAL_HASH_CallbackIDTypeDef CallbackID,
475 pHASH_CallbackTypeDef pCallback);
476HAL_StatusTypeDef HAL_HASH_UnRegisterCallback(HASH_HandleTypeDef *hhash, HAL_HASH_CallbackIDTypeDef CallbackID);
490HAL_StatusTypeDef HAL_HASH_SHA1_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t *pOutBuffer,
492HAL_StatusTypeDef HAL_HASH_MD5_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t *pOutBuffer,
494HAL_StatusTypeDef HAL_HASH_MD5_Accmlt(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size);
495HAL_StatusTypeDef HAL_HASH_SHA1_Accmlt(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size);
496HAL_StatusTypeDef HAL_HASH_MD5_Accmlt_End(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size,
497 uint8_t *pOutBuffer, uint32_t Timeout);
498HAL_StatusTypeDef HAL_HASH_SHA1_Accmlt_End(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size,
499 uint8_t *pOutBuffer, uint32_t Timeout);
511HAL_StatusTypeDef HAL_HASH_SHA1_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size,
512 uint8_t *pOutBuffer);
513HAL_StatusTypeDef HAL_HASH_SHA1_Accmlt_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size);
514HAL_StatusTypeDef HAL_HASH_SHA1_Accmlt_End_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size,
515 uint8_t *pOutBuffer);
516HAL_StatusTypeDef HAL_HASH_MD5_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size,
517 uint8_t *pOutBuffer);
518HAL_StatusTypeDef HAL_HASH_MD5_Accmlt_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size);
519HAL_StatusTypeDef HAL_HASH_MD5_Accmlt_End_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size,
520 uint8_t *pOutBuffer);
521void HAL_HASH_IRQHandler(HASH_HandleTypeDef *hhash);
531HAL_StatusTypeDef HAL_HASH_SHA1_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size);
532HAL_StatusTypeDef HAL_HASH_SHA1_Finish(HASH_HandleTypeDef *hhash, uint8_t *pOutBuffer, uint32_t Timeout);
533HAL_StatusTypeDef HAL_HASH_MD5_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size);
534HAL_StatusTypeDef HAL_HASH_MD5_Finish(HASH_HandleTypeDef *hhash, uint8_t *pOutBuffer, uint32_t Timeout);
545HAL_StatusTypeDef HAL_HMAC_SHA1_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t *pOutBuffer,
547HAL_StatusTypeDef HAL_HMAC_MD5_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t *pOutBuffer,
558HAL_StatusTypeDef HAL_HMAC_MD5_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size,
559 uint8_t *pOutBuffer);
560HAL_StatusTypeDef HAL_HMAC_SHA1_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size,
561 uint8_t *pOutBuffer);
572HAL_StatusTypeDef HAL_HMAC_SHA1_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size);
573HAL_StatusTypeDef HAL_HMAC_MD5_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size);
585HAL_HASH_StateTypeDef HAL_HASH_GetState(HASH_HandleTypeDef *hhash);
587void HAL_HASH_ContextSaving(HASH_HandleTypeDef *hhash, uint8_t *pMemBuffer);
588void HAL_HASH_ContextRestoring(HASH_HandleTypeDef *hhash, uint8_t *pMemBuffer);
589void HAL_HASH_SwFeed_ProcessSuspend(HASH_HandleTypeDef *hhash);
591uint32_t HAL_HASH_GetError(HASH_HandleTypeDef *hhash);
608HAL_StatusTypeDef HASH_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t *pOutBuffer,
609 uint32_t Timeout, uint32_t Algorithm);
610HAL_StatusTypeDef HASH_Accumulate(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint32_t Algorithm);
611HAL_StatusTypeDef HASH_Accumulate_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint32_t Algorithm);
612HAL_StatusTypeDef HASH_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t *pOutBuffer,
614HAL_StatusTypeDef HASH_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint32_t Algorithm);
615HAL_StatusTypeDef HASH_Finish(HASH_HandleTypeDef *hhash, uint8_t *pOutBuffer, uint32_t Timeout);
616HAL_StatusTypeDef HMAC_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t *pOutBuffer,
617 uint32_t Timeout, uint32_t Algorithm);
618HAL_StatusTypeDef HMAC_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t *pOutBuffer,
620HAL_StatusTypeDef HMAC_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint32_t Algorithm);
#define __IO
Definition: core_cm4.h:239
This file contains HAL common defines, enumeration, macros and structures definitions.
HAL_StatusTypeDef
HAL Status structures definition.
Definition: stm32h7xx_hal_def.h:47
HAL_LockTypeDef
HAL Lock structures definition.
Definition: stm32h7xx_hal_def.h:58
Header file of HASH HAL module.
DMA handle Structure definition.
Definition: stm32h7xx_hal_dma.h:138