30 #ifndef __STM32F4xx_HASH_H
31 #define __STM32F4xx_HASH_H
38 #include "stm32f4xx.h"
85 uint32_t HASH_CSR[54];
97 #define HASH_AlgoSelection_SHA1 ((uint32_t)0x0000)
98 #define HASH_AlgoSelection_SHA224 HASH_CR_ALGO_1
99 #define HASH_AlgoSelection_SHA256 HASH_CR_ALGO
100 #define HASH_AlgoSelection_MD5 HASH_CR_ALGO_0
102 #define IS_HASH_ALGOSELECTION(ALGOSELECTION) (((ALGOSELECTION) == HASH_AlgoSelection_SHA1) || \
103 ((ALGOSELECTION) == HASH_AlgoSelection_SHA224) || \
104 ((ALGOSELECTION) == HASH_AlgoSelection_SHA256) || \
105 ((ALGOSELECTION) == HASH_AlgoSelection_MD5))
113 #define HASH_AlgoMode_HASH ((uint32_t)0x00000000)
114 #define HASH_AlgoMode_HMAC HASH_CR_MODE
116 #define IS_HASH_ALGOMODE(ALGOMODE) (((ALGOMODE) == HASH_AlgoMode_HASH) || \
117 ((ALGOMODE) == HASH_AlgoMode_HMAC))
125 #define HASH_DataType_32b ((uint32_t)0x0000)
126 #define HASH_DataType_16b HASH_CR_DATATYPE_0
127 #define HASH_DataType_8b HASH_CR_DATATYPE_1
128 #define HASH_DataType_1b HASH_CR_DATATYPE
130 #define IS_HASH_DATATYPE(DATATYPE) (((DATATYPE) == HASH_DataType_32b)|| \
131 ((DATATYPE) == HASH_DataType_16b)|| \
132 ((DATATYPE) == HASH_DataType_8b) || \
133 ((DATATYPE) == HASH_DataType_1b))
141 #define HASH_HMACKeyType_ShortKey ((uint32_t)0x00000000)
142 #define HASH_HMACKeyType_LongKey HASH_CR_LKEY
144 #define IS_HASH_HMAC_KEYTYPE(KEYTYPE) (((KEYTYPE) == HASH_HMACKeyType_ShortKey) || \
145 ((KEYTYPE) == HASH_HMACKeyType_LongKey))
153 #define IS_HASH_VALIDBITSNUMBER(VALIDBITS) ((VALIDBITS) <= 0x1F)
162 #define HASH_IT_DINI HASH_IMR_DINIM
163 #define HASH_IT_DCI HASH_IMR_DCIM
165 #define IS_HASH_IT(IT) ((((IT) & (uint32_t)0xFFFFFFFC) == 0x00000000) && ((IT) != 0x00000000))
166 #define IS_HASH_GET_IT(IT) (((IT) == HASH_IT_DINI) || ((IT) == HASH_IT_DCI))
175 #define HASH_FLAG_DINIS HASH_SR_DINIS
176 #define HASH_FLAG_DCIS HASH_SR_DCIS
177 #define HASH_FLAG_DMAS HASH_SR_DMAS
178 #define HASH_FLAG_BUSY HASH_SR_BUSY
179 #define HASH_FLAG_DINNE HASH_CR_DINNE
181 #define IS_HASH_GET_FLAG(FLAG) (((FLAG) == HASH_FLAG_DINIS) || \
182 ((FLAG) == HASH_FLAG_DCIS) || \
183 ((FLAG) == HASH_FLAG_DMAS) || \
184 ((FLAG) == HASH_FLAG_BUSY) || \
185 ((FLAG) == HASH_FLAG_DINNE))
187 #define IS_HASH_CLEAR_FLAG(FLAG)(((FLAG) == HASH_FLAG_DINIS) || \
188 ((FLAG) == HASH_FLAG_DCIS))
225 void HASH_ITConfig(uint32_t HASH_IT, FunctionalState NewState);
232 ErrorStatus
HASH_SHA1(uint8_t *Input, uint32_t Ilen, uint8_t Output[20]);
233 ErrorStatus
HMAC_SHA1(uint8_t *Key, uint32_t Keylen,
234 uint8_t *Input, uint32_t Ilen,
238 ErrorStatus
HASH_MD5(uint8_t *Input, uint32_t Ilen, uint8_t Output[16]);
239 ErrorStatus
HMAC_MD5(uint8_t *Key, uint32_t Keylen,
240 uint8_t *Input, uint32_t Ilen,
FlagStatus HASH_GetFlagStatus(uint32_t HASH_FLAG)
Checks whether the specified HASH flag is set or not.
ErrorStatus HASH_SHA1(uint8_t *Input, uint32_t Ilen, uint8_t Output[20])
Compute the HASH SHA1 digest.
ErrorStatus HASH_MD5(uint8_t *Input, uint32_t Ilen, uint8_t Output[16])
Compute the HASH MD5 digest.
void HASH_ITConfig(uint32_t HASH_IT, FunctionalState NewState)
Enables or disables the specified HASH interrupts.
void HASH_StructInit(HASH_InitTypeDef *HASH_InitStruct)
Fills each HASH_InitStruct member with its default value.
void HASH_SaveContext(HASH_Context *HASH_ContextSave)
Save the Hash peripheral Context.
void HASH_DeInit(void)
De-initializes the HASH peripheral registers to their default reset values.
uint32_t HASH_AlgoSelection
void HASH_AutoStartDigest(FunctionalState NewState)
Enables or disables auto-start message padding and calculation of the final message digest at the end...
HASH context swapping structure definition.
ErrorStatus HMAC_SHA1(uint8_t *Key, uint32_t Keylen, uint8_t *Input, uint32_t Ilen, uint8_t Output[20])
Compute the HMAC SHA1 digest.
HASH message digest result structure definition.
void HASH_Init(HASH_InitTypeDef *HASH_InitStruct)
Initializes the HASH peripheral according to the specified parameters in the HASH_InitStruct structur...
void HASH_ClearITPendingBit(uint32_t HASH_IT)
Clears the HASH interrupt pending bit(s).
void HASH_Reset(void)
Resets the HASH processor core, so that the HASH will be ready to compute the message digest of a new...
void HASH_DMACmd(FunctionalState NewState)
Enables or disables the HASH DMA interface.
void HASH_StartDigest(void)
Starts the message padding and calculation of the final message.
void HASH_RestoreContext(HASH_Context *HASH_ContextRestore)
Restore the Hash peripheral Context.
void HASH_DataIn(uint32_t Data)
Writes data in the Data Input FIFO.
uint8_t HASH_GetInFIFOWordsNbr(void)
Returns the number of words already pushed into the IN FIFO.
void HASH_GetDigest(HASH_MsgDigest *HASH_MessageDigest)
Provides the message digest result.
void HASH_ClearFlag(uint32_t HASH_FLAG)
Clears the HASH flags.
HASH Init structure definition.
ITStatus HASH_GetITStatus(uint32_t HASH_IT)
Checks whether the specified HASH interrupt has occurred or not.
ErrorStatus HMAC_MD5(uint8_t *Key, uint32_t Keylen, uint8_t *Input, uint32_t Ilen, uint8_t Output[16])
Compute the HMAC MD5 digest.
void HASH_SetLastWordValidBitsNbr(uint16_t ValidNumber)
Configure the Number of valid bits in last word of the message.
uint32_t HASH_HMACKeyType