2 ******************************************************************************
3 * @file stm32f4xx_hash.h
4 * @author MCD Application Team
7 * @brief This file contains all the functions prototypes for the HASH
9 ******************************************************************************
12 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
13 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
14 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
15 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
16 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
17 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
19 * <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
20 ******************************************************************************
23 /* Define to prevent recursive inclusion -------------------------------------*/
24 #ifndef __STM32F4xx_HASH_H
25 #define __STM32F4xx_HASH_H
31 /* Includes ------------------------------------------------------------------*/
32 #include "stm32f4xx.h"
34 /** @addtogroup STM32F4xx_StdPeriph_Driver
42 /* Exported types ------------------------------------------------------------*/
45 * @brief HASH Init structure definition
49 uint32_t HASH_AlgoSelection; /*!< SHA-1 or MD5. This parameter can be a value
50 of @ref HASH_Algo_Selection */
51 uint32_t HASH_AlgoMode; /*!< HASH or HMAC. This parameter can be a value
52 of @ref HASH_processor_Algorithm_Mode */
53 uint32_t HASH_DataType; /*!< 32-bit data, 16-bit data, 8-bit data or
54 bit-string. This parameter can be a value of
55 @ref HASH_Data_Type */
56 uint32_t HASH_HMACKeyType; /*!< HMAC Short key or HMAC Long Key. This parameter
57 can be a value of @ref HASH_HMAC_Long_key_only_for_HMAC_mode */
61 * @brief HASH message digest result structure definition
65 uint32_t Data[5]; /*!< Message digest result : 5x 32bit words for SHA1 or
66 4x 32bit words for MD5 */
70 * @brief HASH context swapping structure definition
77 uint32_t HASH_CSR[51];
80 /* Exported constants --------------------------------------------------------*/
82 /** @defgroup HASH_Exported_Constants
86 /** @defgroup HASH_Algo_Selection
89 #define HASH_AlgoSelection_SHA1 ((uint16_t)0x0000) /*!< HASH function is SHA1 */
90 #define HASH_AlgoSelection_MD5 ((uint16_t)0x0080) /*!< HASH function is MD5 */
92 #define IS_HASH_ALGOSELECTION(ALGOSELECTION) (((ALGOSELECTION) == HASH_AlgoSelection_SHA1) || \
93 ((ALGOSELECTION) == HASH_AlgoSelection_MD5))
98 /** @defgroup HASH_processor_Algorithm_Mode
101 #define HASH_AlgoMode_HASH ((uint16_t)0x0000) /*!< Algorithm is HASH */
102 #define HASH_AlgoMode_HMAC ((uint16_t)0x0040) /*!< Algorithm is HMAC */
104 #define IS_HASH_ALGOMODE(ALGOMODE) (((ALGOMODE) == HASH_AlgoMode_HASH) || \
105 ((ALGOMODE) == HASH_AlgoMode_HMAC))
110 /** @defgroup HASH_Data_Type
113 #define HASH_DataType_32b ((uint16_t)0x0000)
114 #define HASH_DataType_16b ((uint16_t)0x0010)
115 #define HASH_DataType_8b ((uint16_t)0x0020)
116 #define HASH_DataType_1b ((uint16_t)0x0030)
118 #define IS_HASH_DATATYPE(DATATYPE) (((DATATYPE) == HASH_DataType_32b)|| \
119 ((DATATYPE) == HASH_DataType_16b)|| \
120 ((DATATYPE) == HASH_DataType_8b)|| \
121 ((DATATYPE) == HASH_DataType_1b))
126 /** @defgroup HASH_HMAC_Long_key_only_for_HMAC_mode
129 #define HASH_HMACKeyType_ShortKey ((uint32_t)0x00000000) /*!< HMAC Key is <= 64 bytes */
130 #define HASH_HMACKeyType_LongKey ((uint32_t)0x00010000) /*!< HMAC Key is > 64 bytes */
132 #define IS_HASH_HMAC_KEYTYPE(KEYTYPE) (((KEYTYPE) == HASH_HMACKeyType_ShortKey) || \
133 ((KEYTYPE) == HASH_HMACKeyType_LongKey))
138 /** @defgroup Number_of_valid_bits_in_last_word_of_the_message
141 #define IS_HASH_VALIDBITSNUMBER(VALIDBITS) ((VALIDBITS) <= 0x1F)
147 /** @defgroup HASH_interrupts_definition
150 #define HASH_IT_DINI ((uint8_t)0x01) /*!< A new block can be entered into the input buffer (DIN)*/
151 #define HASH_IT_DCI ((uint8_t)0x02) /*!< Digest calculation complete */
153 #define IS_HASH_IT(IT) ((((IT) & (uint8_t)0xFC) == 0x00) && ((IT) != 0x00))
154 #define IS_HASH_GET_IT(IT) (((IT) == HASH_IT_DINI) || ((IT) == HASH_IT_DCI))
160 /** @defgroup HASH_flags_definition
163 #define HASH_FLAG_DINIS ((uint16_t)0x0001) /*!< 16 locations are free in the DIN : A new block can be entered into the input buffer.*/
164 #define HASH_FLAG_DCIS ((uint16_t)0x0002) /*!< Digest calculation complete */
165 #define HASH_FLAG_DMAS ((uint16_t)0x0004) /*!< DMA interface is enabled (DMAE=1) or a transfer is ongoing */
166 #define HASH_FLAG_BUSY ((uint16_t)0x0008) /*!< The hash core is Busy : processing a block of data */
167 #define HASH_FLAG_DINNE ((uint16_t)0x1000) /*!< DIN not empty : The input buffer contains at least one word of data */
169 #define IS_HASH_GET_FLAG(FLAG) (((FLAG) == HASH_FLAG_DINIS) || \
170 ((FLAG) == HASH_FLAG_DCIS) || \
171 ((FLAG) == HASH_FLAG_DMAS) || \
172 ((FLAG) == HASH_FLAG_BUSY) || \
173 ((FLAG) == HASH_FLAG_DINNE))
175 #define IS_HASH_CLEAR_FLAG(FLAG)(((FLAG) == HASH_FLAG_DINIS) || \
176 ((FLAG) == HASH_FLAG_DCIS))
186 /* Exported macro ------------------------------------------------------------*/
187 /* Exported functions --------------------------------------------------------*/
189 /* Function used to set the HASH configuration to the default reset state ****/
190 void HASH_DeInit(void);
192 /* HASH Configuration function ************************************************/
193 void HASH_Init(HASH_InitTypeDef* HASH_InitStruct);
194 void HASH_StructInit(HASH_InitTypeDef* HASH_InitStruct);
195 void HASH_Reset(void);
197 /* HASH Message Digest generation functions ***********************************/
198 void HASH_DataIn(uint32_t Data);
199 uint8_t HASH_GetInFIFOWordsNbr(void);
200 void HASH_SetLastWordValidBitsNbr(uint16_t ValidNumber);
201 void HASH_StartDigest(void);
202 void HASH_GetDigest(HASH_MsgDigest* HASH_MessageDigest);
204 /* HASH Context swapping functions ********************************************/
205 void HASH_SaveContext(HASH_Context* HASH_ContextSave);
206 void HASH_RestoreContext(HASH_Context* HASH_ContextRestore);
208 /* HASH's DMA interface function **********************************************/
209 void HASH_DMACmd(FunctionalState NewState);
211 /* HASH Interrupts and flags management functions *****************************/
212 void HASH_ITConfig(uint8_t HASH_IT, FunctionalState NewState);
213 FlagStatus HASH_GetFlagStatus(uint16_t HASH_FLAG);
214 void HASH_ClearFlag(uint16_t HASH_FLAG);
215 ITStatus HASH_GetITStatus(uint8_t HASH_IT);
216 void HASH_ClearITPendingBit(uint8_t HASH_IT);
218 /* High Level SHA1 functions **************************************************/
219 ErrorStatus HASH_SHA1(uint8_t *Input, uint32_t Ilen, uint8_t Output[20]);
220 ErrorStatus HMAC_SHA1(uint8_t *Key, uint32_t Keylen,
221 uint8_t *Input, uint32_t Ilen,
224 /* High Level MD5 functions ***************************************************/
225 ErrorStatus HASH_MD5(uint8_t *Input, uint32_t Ilen, uint8_t Output[16]);
226 ErrorStatus HMAC_MD5(uint8_t *Key, uint32_t Keylen,
227 uint8_t *Input, uint32_t Ilen,
234 #endif /*__STM32F4xx_HASH_H */
244 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/