STM32F2 Standard Peripheral bibliotheek  1.0
ST Microelectronics bibliotheek documentatie voor de STM32F2 Standard Peripheral Library
 All Data Structures Files Functions Variables Enumerations Enumerator Groups
stm32f2xx_hash.h
Go to the documentation of this file.
1 
29 /* Define to prevent recursive inclusion -------------------------------------*/
30 #ifndef __STM32F2xx_HASH_H
31 #define __STM32F2xx_HASH_H
32 
33 #ifdef __cplusplus
34  extern "C" {
35 #endif
36 
37 /* Includes ------------------------------------------------------------------*/
38 #include "stm32f2xx.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[5];
74 
78 typedef struct
79 {
80  uint32_t HASH_IMR;
81  uint32_t HASH_STR;
82  uint32_t HASH_CR;
83  uint32_t HASH_CSR[51];
85 
86 /* Exported constants --------------------------------------------------------*/
87 
95 #define HASH_AlgoSelection_SHA1 ((uint16_t)0x0000)
96 #define HASH_AlgoSelection_MD5 ((uint16_t)0x0080)
98 #define IS_HASH_ALGOSELECTION(ALGOSELECTION) (((ALGOSELECTION) == HASH_AlgoSelection_SHA1) || \
99  ((ALGOSELECTION) == HASH_AlgoSelection_MD5))
100 
107 #define HASH_AlgoMode_HASH ((uint16_t)0x0000)
108 #define HASH_AlgoMode_HMAC ((uint16_t)0x0040)
110 #define IS_HASH_ALGOMODE(ALGOMODE) (((ALGOMODE) == HASH_AlgoMode_HASH) || \
111  ((ALGOMODE) == HASH_AlgoMode_HMAC))
112 
119 #define HASH_DataType_32b ((uint16_t)0x0000)
120 #define HASH_DataType_16b ((uint16_t)0x0010)
121 #define HASH_DataType_8b ((uint16_t)0x0020)
122 #define HASH_DataType_1b ((uint16_t)0x0030)
123 
124 #define IS_HASH_DATATYPE(DATATYPE) (((DATATYPE) == HASH_DataType_32b)|| \
125  ((DATATYPE) == HASH_DataType_16b)|| \
126  ((DATATYPE) == HASH_DataType_8b)|| \
127  ((DATATYPE) == HASH_DataType_1b))
128 
135 #define HASH_HMACKeyType_ShortKey ((uint32_t)0x00000000)
136 #define HASH_HMACKeyType_LongKey ((uint32_t)0x00010000)
138 #define IS_HASH_HMAC_KEYTYPE(KEYTYPE) (((KEYTYPE) == HASH_HMACKeyType_ShortKey) || \
139  ((KEYTYPE) == HASH_HMACKeyType_LongKey))
140 
147 #define IS_HASH_VALIDBITSNUMBER(VALIDBITS) ((VALIDBITS) <= 0x1F)
148 
156 #define HASH_IT_DINI ((uint8_t)0x01)
157 #define HASH_IT_DCI ((uint8_t)0x02)
159 #define IS_HASH_IT(IT) ((((IT) & (uint8_t)0xFC) == 0x00) && ((IT) != 0x00))
160 #define IS_HASH_GET_IT(IT) (((IT) == HASH_IT_DINI) || ((IT) == HASH_IT_DCI))
161 
169 #define HASH_FLAG_DINIS ((uint16_t)0x0001)
170 #define HASH_FLAG_DCIS ((uint16_t)0x0002)
171 #define HASH_FLAG_DMAS ((uint16_t)0x0004)
172 #define HASH_FLAG_BUSY ((uint16_t)0x0008)
173 #define HASH_FLAG_DINNE ((uint16_t)0x1000)
175 #define IS_HASH_GET_FLAG(FLAG) (((FLAG) == HASH_FLAG_DINIS) || \
176  ((FLAG) == HASH_FLAG_DCIS) || \
177  ((FLAG) == HASH_FLAG_DMAS) || \
178  ((FLAG) == HASH_FLAG_BUSY) || \
179  ((FLAG) == HASH_FLAG_DINNE))
180 
181 #define IS_HASH_CLEAR_FLAG(FLAG)(((FLAG) == HASH_FLAG_DINIS) || \
182  ((FLAG) == HASH_FLAG_DCIS))
183 
192 /* Exported macro ------------------------------------------------------------*/
193 /* Exported functions --------------------------------------------------------*/
194 
195 /* Function used to set the HASH configuration to the default reset state ****/
196 void HASH_DeInit(void);
197 
198 /* HASH Configuration function ************************************************/
199 void HASH_Init(HASH_InitTypeDef* HASH_InitStruct);
200 void HASH_StructInit(HASH_InitTypeDef* HASH_InitStruct);
201 void HASH_Reset(void);
202 
203 /* HASH Message Digest generation functions ***********************************/
204 void HASH_DataIn(uint32_t Data);
205 uint8_t HASH_GetInFIFOWordsNbr(void);
206 void HASH_SetLastWordValidBitsNbr(uint16_t ValidNumber);
207 void HASH_StartDigest(void);
208 void HASH_GetDigest(HASH_MsgDigest* HASH_MessageDigest);
209 
210 /* HASH Context swapping functions ********************************************/
211 void HASH_SaveContext(HASH_Context* HASH_ContextSave);
212 void HASH_RestoreContext(HASH_Context* HASH_ContextRestore);
213 
214 /* HASH's DMA interface function **********************************************/
215 void HASH_DMACmd(FunctionalState NewState);
216 
217 /* HASH Interrupts and flags management functions *****************************/
218 void HASH_ITConfig(uint8_t HASH_IT, FunctionalState NewState);
219 FlagStatus HASH_GetFlagStatus(uint16_t HASH_FLAG);
220 void HASH_ClearFlag(uint16_t HASH_FLAG);
221 ITStatus HASH_GetITStatus(uint8_t HASH_IT);
222 void HASH_ClearITPendingBit(uint8_t HASH_IT);
223 
224 /* High Level SHA1 functions **************************************************/
225 ErrorStatus HASH_SHA1(uint8_t *Input, uint32_t Ilen, uint8_t Output[20]);
226 ErrorStatus HMAC_SHA1(uint8_t *Key, uint32_t Keylen,
227  uint8_t *Input, uint32_t Ilen,
228  uint8_t Output[20]);
229 
230 /* High Level MD5 functions ***************************************************/
231 ErrorStatus HASH_MD5(uint8_t *Input, uint32_t Ilen, uint8_t Output[16]);
232 ErrorStatus HMAC_MD5(uint8_t *Key, uint32_t Keylen,
233  uint8_t *Input, uint32_t Ilen,
234  uint8_t Output[16]);
235 
236 #ifdef __cplusplus
237 }
238 #endif
239 
240 #endif /*__STM32F2xx_HASH_H */
241 
250 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/