CARME-M4 BSP  V1.5
stm32f4xx_hash.h
Go to the documentation of this file.
1 
29 /* Define to prevent recursive inclusion -------------------------------------*/
30 #ifndef __STM32F4xx_HASH_H
31 #define __STM32F4xx_HASH_H
32 
33 #ifdef __cplusplus
34  extern "C" {
35 #endif
36 
37 /* Includes ------------------------------------------------------------------*/
38 #include "stm32f4xx.h"
39 
48 /* Exported types ------------------------------------------------------------*/
49 
53 typedef struct
54 {
55  uint32_t HASH_AlgoSelection;
57  uint32_t HASH_AlgoMode;
59  uint32_t HASH_DataType;
62  uint32_t HASH_HMACKeyType;
65 
69 typedef struct
70 {
71  uint32_t Data[8];
76 
80 typedef struct
81 {
82  uint32_t HASH_IMR;
83  uint32_t HASH_STR;
84  uint32_t HASH_CR;
85  uint32_t HASH_CSR[54];
87 
88 /* Exported constants --------------------------------------------------------*/
89 
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))
106 
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))
118 
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))
134 
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))
146 
153 #define IS_HASH_VALIDBITSNUMBER(VALIDBITS) ((VALIDBITS) <= 0x1F)
154 
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))
167 
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))
186 
187 #define IS_HASH_CLEAR_FLAG(FLAG)(((FLAG) == HASH_FLAG_DINIS) || \
188  ((FLAG) == HASH_FLAG_DCIS))
189 
198 /* Exported macro ------------------------------------------------------------*/
199 /* Exported functions --------------------------------------------------------*/
200 
201 /* Function used to set the HASH configuration to the default reset state ****/
202 void HASH_DeInit(void);
203 
204 /* HASH Configuration function ************************************************/
205 void HASH_Init(HASH_InitTypeDef* HASH_InitStruct);
206 void HASH_StructInit(HASH_InitTypeDef* HASH_InitStruct);
207 void HASH_Reset(void);
208 
209 /* HASH Message Digest generation functions ***********************************/
210 void HASH_DataIn(uint32_t Data);
211 uint8_t HASH_GetInFIFOWordsNbr(void);
212 void HASH_SetLastWordValidBitsNbr(uint16_t ValidNumber);
213 void HASH_StartDigest(void);
214 void HASH_AutoStartDigest(FunctionalState NewState);
215 void HASH_GetDigest(HASH_MsgDigest* HASH_MessageDigest);
216 
217 /* HASH Context swapping functions ********************************************/
218 void HASH_SaveContext(HASH_Context* HASH_ContextSave);
219 void HASH_RestoreContext(HASH_Context* HASH_ContextRestore);
220 
221 /* HASH DMA interface function ************************************************/
222 void HASH_DMACmd(FunctionalState NewState);
223 
224 /* HASH Interrupts and flags management functions *****************************/
225 void HASH_ITConfig(uint32_t HASH_IT, FunctionalState NewState);
226 FlagStatus HASH_GetFlagStatus(uint32_t HASH_FLAG);
227 void HASH_ClearFlag(uint32_t HASH_FLAG);
228 ITStatus HASH_GetITStatus(uint32_t HASH_IT);
229 void HASH_ClearITPendingBit(uint32_t HASH_IT);
230 
231 /* High Level SHA1 functions **************************************************/
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,
235  uint8_t Output[20]);
236 
237 /* High Level MD5 functions ***************************************************/
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,
241  uint8_t Output[16]);
242 
243 #ifdef __cplusplus
244 }
245 #endif
246 
247 #endif /*__STM32F4xx_HASH_H */
248 
257 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
FlagStatus HASH_GetFlagStatus(uint32_t HASH_FLAG)
Checks whether the specified HASH flag is set or not.
uint32_t HASH_AlgoMode
ErrorStatus HASH_SHA1(uint8_t *Input, uint32_t Ilen, uint8_t Output[20])
Compute the HASH SHA1 digest.
uint32_t HASH_DataType
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