RTEMS 6.1-rc1
stm32h7xx_hal_hash.h
Go to the documentation of this file.
1
19/* Define to prevent recursive inclusion -------------------------------------*/
20#ifndef STM32H7xx_HAL_HASH_H
21#define STM32H7xx_HAL_HASH_H
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27/* Includes ------------------------------------------------------------------*/
28#include "stm32h7xx_hal_def.h"
29
33#if defined (HASH)
38/* Exported types ------------------------------------------------------------*/
47typedef struct
48{
49 uint32_t DataType;
52 uint32_t KeySize;
54 uint8_t *pKey;
56} HASH_InitTypeDef;
57
61typedef enum
62{
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;
70
74typedef enum
75{
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;
85
89typedef enum
90{
91 HAL_HASH_SUSPEND_NONE = 0x00U,
92 HAL_HASH_SUSPEND = 0x01U
93} HAL_HASH_SuspendTypeDef;
94
95#if (USE_HAL_HASH_REGISTER_CALLBACKS == 1U)
99typedef enum
100{
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;
107#endif /* USE_HAL_HASH_REGISTER_CALLBACKS */
108
109
113#if (USE_HAL_HASH_REGISTER_CALLBACKS == 1)
114typedef struct __HASH_HandleTypeDef
115#else
116typedef struct
117#endif /* (USE_HAL_HASH_REGISTER_CALLBACKS) */
118{
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;
137 HAL_StatusTypeDef Status;
139 HAL_HASH_PhaseTypeDef Phase;
141 DMA_HandleTypeDef *hdmain;
143 HAL_LockTypeDef Lock;
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);
168#endif /* (USE_HAL_HASH_REGISTER_CALLBACKS) */
169} HASH_HandleTypeDef;
170
171#if (USE_HAL_HASH_REGISTER_CALLBACKS == 1U)
175typedef void (*pHASH_CallbackTypeDef)(HASH_HandleTypeDef *hhash);
176#endif /* USE_HAL_HASH_REGISTER_CALLBACKS */
177
182/* Exported constants --------------------------------------------------------*/
183
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
267#endif /* USE_HAL_HASH_REGISTER_CALLBACKS */
276/* Exported macros -----------------------------------------------------------*/
292#define __HAL_HASH_GET_FLAG(__FLAG__) (((__FLAG__) > 8U) ? \
293 ((HASH->CR & (__FLAG__)) == (__FLAG__)) :\
294 ((HASH->SR & (__FLAG__)) == (__FLAG__)) )
295
296
304#define __HAL_HASH_CLEAR_FLAG(__FLAG__) CLEAR_BIT(HASH->SR, (__FLAG__))
305
306
314#define __HAL_HASH_ENABLE_IT(__INTERRUPT__) SET_BIT(HASH->IMR, (__INTERRUPT__))
315
323#define __HAL_HASH_DISABLE_IT(__INTERRUPT__) CLEAR_BIT(HASH->IMR, (__INTERRUPT__))
324
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; \
335 }while(0)
336#else
337#define __HAL_HASH_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_HASH_STATE_RESET)
338#endif /* USE_HAL_HASH_REGISTER_CALLBACKS */
339
340
345#define __HAL_HASH_RESET_HANDLE_STATUS(__HANDLE__) ((__HANDLE__)->Status = HAL_OK)
346
352#define __HAL_HASH_SET_MDMAT() SET_BIT(HASH->CR, HASH_CR_MDMAT)
353
358#define __HAL_HASH_RESET_MDMAT() CLEAR_BIT(HASH->CR, HASH_CR_MDMAT)
359
360
365#define __HAL_HASH_START_DIGEST() SET_BIT(HASH->STR, HASH_STR_DCAL)
366
372#define __HAL_HASH_SET_NBVALIDBITS(__SIZE__) MODIFY_REG(HASH->STR, HASH_STR_NBLW, 8U * ((__SIZE__) % 4U))
373
378#define __HAL_HASH_INIT() SET_BIT(HASH->CR, HASH_CR_INIT)
379
385/* Private macros --------------------------------------------------------*/
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)
402
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))
412
420#define IS_HASH_DMA_MULTIBUFFER_SIZE(__SIZE__) ((READ_BIT(HASH->CR, HASH_CR_MDMAT) == 0U) || (((__SIZE__) % 4U) == 0U))
421
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)
438
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))
447
452/* Include HASH HAL Extended module */
454/* Exported functions --------------------------------------------------------*/
455
464/* Initialization/de-initialization methods **********************************/
465HAL_StatusTypeDef HAL_HASH_Init(HASH_HandleTypeDef *hhash);
466HAL_StatusTypeDef HAL_HASH_DeInit(HASH_HandleTypeDef *hhash);
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);
472/* Callbacks Register/UnRegister functions ***********************************/
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);
477#endif /* USE_HAL_HASH_REGISTER_CALLBACKS */
478
479
489/* HASH processing using polling *********************************************/
490HAL_StatusTypeDef HAL_HASH_SHA1_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t *pOutBuffer,
491 uint32_t Timeout);
492HAL_StatusTypeDef HAL_HASH_MD5_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t *pOutBuffer,
493 uint32_t Timeout);
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);
500
501
510/* HASH processing using IT **************************************************/
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);
530/* HASH processing using DMA *************************************************/
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);
535
544/* HASH-MAC processing using polling *****************************************/
545HAL_StatusTypeDef HAL_HMAC_SHA1_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t *pOutBuffer,
546 uint32_t Timeout);
547HAL_StatusTypeDef HAL_HMAC_MD5_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t *pOutBuffer,
548 uint32_t Timeout);
549
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);
562
571/* HASH-HMAC processing using DMA ********************************************/
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);
574
584/* Peripheral State methods **************************************************/
585HAL_HASH_StateTypeDef HAL_HASH_GetState(HASH_HandleTypeDef *hhash);
586HAL_StatusTypeDef HAL_HASH_GetStatus(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);
590HAL_StatusTypeDef HAL_HASH_DMAFeed_ProcessSuspend(HASH_HandleTypeDef *hhash);
591uint32_t HAL_HASH_GetError(HASH_HandleTypeDef *hhash);
592
601/* Private functions -----------------------------------------------------------*/
602
607/* Private functions */
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,
613 uint32_t Algorithm);
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,
619 uint32_t Algorithm);
620HAL_StatusTypeDef HMAC_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint32_t Algorithm);
621
629#endif /* HASH*/
635#ifdef __cplusplus
636}
637#endif
638
639
640#endif /* STM32H7xx_HAL_HASH_H */
641
#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