Mercurial > public > ostc4
comparison Common/Drivers/STM32F4xx_HAL_DRIVER_v120/Inc/stm32f4xx_hal_hash.h @ 38:5f11787b4f42
include in ostc4 repository
author | heinrichsweikamp |
---|---|
date | Sat, 28 Apr 2018 11:52:34 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
37:ccc45c0e1ea2 | 38:5f11787b4f42 |
---|---|
1 /** | |
2 ****************************************************************************** | |
3 * @file stm32f4xx_hal_hash.h | |
4 * @author MCD Application Team | |
5 * @version V1.2.0 | |
6 * @date 26-December-2014 | |
7 * @brief Header file of HASH HAL module. | |
8 ****************************************************************************** | |
9 * @attention | |
10 * | |
11 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> | |
12 * | |
13 * Redistribution and use in source and binary forms, with or without modification, | |
14 * are permitted provided that the following conditions are met: | |
15 * 1. Redistributions of source code must retain the above copyright notice, | |
16 * this list of conditions and the following disclaimer. | |
17 * 2. Redistributions in binary form must reproduce the above copyright notice, | |
18 * this list of conditions and the following disclaimer in the documentation | |
19 * and/or other materials provided with the distribution. | |
20 * 3. Neither the name of STMicroelectronics nor the names of its contributors | |
21 * may be used to endorse or promote products derived from this software | |
22 * without specific prior written permission. | |
23 * | |
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
34 * | |
35 ****************************************************************************** | |
36 */ | |
37 | |
38 /* Define to prevent recursive inclusion -------------------------------------*/ | |
39 #ifndef __STM32F4xx_HAL_HASH_H | |
40 #define __STM32F4xx_HAL_HASH_H | |
41 | |
42 #ifdef __cplusplus | |
43 extern "C" { | |
44 #endif | |
45 | |
46 #if defined(STM32F415xx) || defined(STM32F417xx) || defined(STM32F437xx) || defined(STM32F439xx) | |
47 | |
48 /* Includes ------------------------------------------------------------------*/ | |
49 #include "stm32f4xx_hal_def.h" | |
50 | |
51 /** @addtogroup STM32F4xx_HAL_Driver | |
52 * @{ | |
53 */ | |
54 | |
55 /** @addtogroup HASH | |
56 * @brief HASH HAL module driver | |
57 * @{ | |
58 */ | |
59 | |
60 /* Exported types ------------------------------------------------------------*/ | |
61 /** @defgroup HASH_Exported_Types HASH Exported Types | |
62 * @{ | |
63 */ | |
64 | |
65 /** @defgroup HASH_Exported_Types_Group1 HASH Configuration Structure definition | |
66 * @{ | |
67 */ | |
68 | |
69 typedef struct | |
70 { | |
71 uint32_t DataType; /*!< 32-bit data, 16-bit data, 8-bit data or 1-bit string. | |
72 This parameter can be a value of @ref HASH DataType */ | |
73 | |
74 uint32_t KeySize; /*!< The key size is used only in HMAC operation */ | |
75 | |
76 uint8_t* pKey; /*!< The key is used only in HMAC operation */ | |
77 }HASH_InitTypeDef; | |
78 | |
79 /** | |
80 * @} | |
81 */ | |
82 | |
83 /** @defgroup HASH_Exported_Types_Group2 HASH State structures definition | |
84 * @{ | |
85 */ | |
86 | |
87 typedef enum | |
88 { | |
89 HAL_HASH_STATE_RESET = 0x00, /*!< HASH not yet initialized or disabled */ | |
90 HAL_HASH_STATE_READY = 0x01, /*!< HASH initialized and ready for use */ | |
91 HAL_HASH_STATE_BUSY = 0x02, /*!< HASH internal process is ongoing */ | |
92 HAL_HASH_STATE_TIMEOUT = 0x03, /*!< HASH timeout state */ | |
93 HAL_HASH_STATE_ERROR = 0x04 /*!< HASH error state */ | |
94 }HAL_HASH_STATETypeDef; | |
95 | |
96 /** | |
97 * @} | |
98 */ | |
99 | |
100 /** @defgroup HASH_Exported_Types_Group3 HASH phase structures definition | |
101 * @{ | |
102 */ | |
103 | |
104 typedef enum | |
105 { | |
106 HAL_HASH_PHASE_READY = 0x01, /*!< HASH peripheral is ready for initialization */ | |
107 HAL_HASH_PHASE_PROCESS = 0x02, /*!< HASH peripheral is in processing phase */ | |
108 }HAL_HASHPhaseTypeDef; | |
109 | |
110 /** | |
111 * @} | |
112 */ | |
113 | |
114 /** @defgroup HASH_Exported_Types_Group4 HASH Handle structures definition | |
115 * @{ | |
116 */ | |
117 | |
118 typedef struct | |
119 { | |
120 HASH_InitTypeDef Init; /*!< HASH required parameters */ | |
121 | |
122 uint8_t *pHashInBuffPtr; /*!< Pointer to input buffer */ | |
123 | |
124 uint8_t *pHashOutBuffPtr; /*!< Pointer to input buffer */ | |
125 | |
126 __IO uint32_t HashBuffSize; /*!< Size of buffer to be processed */ | |
127 | |
128 __IO uint32_t HashInCount; /*!< Counter of inputed data */ | |
129 | |
130 __IO uint32_t HashITCounter; /*!< Counter of issued interrupts */ | |
131 | |
132 HAL_StatusTypeDef Status; /*!< HASH peripheral status */ | |
133 | |
134 HAL_HASHPhaseTypeDef Phase; /*!< HASH peripheral phase */ | |
135 | |
136 DMA_HandleTypeDef *hdmain; /*!< HASH In DMA handle parameters */ | |
137 | |
138 HAL_LockTypeDef Lock; /*!< HASH locking object */ | |
139 | |
140 __IO HAL_HASH_STATETypeDef State; /*!< HASH peripheral state */ | |
141 } HASH_HandleTypeDef; | |
142 | |
143 /** | |
144 * @} | |
145 */ | |
146 | |
147 | |
148 /** | |
149 * @} | |
150 */ | |
151 | |
152 /* Exported constants --------------------------------------------------------*/ | |
153 /** @defgroup HASH_Exported_Constants HASH Exported Constants | |
154 * @{ | |
155 */ | |
156 | |
157 /** @defgroup HASH_Exported_Constants_Group1 HASH Algorithm Selection | |
158 * @{ | |
159 */ | |
160 #define HASH_ALGOSELECTION_SHA1 ((uint32_t)0x0000) /*!< HASH function is SHA1 */ | |
161 #define HASH_ALGOSELECTION_SHA224 HASH_CR_ALGO_1 /*!< HASH function is SHA224 */ | |
162 #define HASH_ALGOSELECTION_SHA256 HASH_CR_ALGO /*!< HASH function is SHA256 */ | |
163 #define HASH_ALGOSELECTION_MD5 HASH_CR_ALGO_0 /*!< HASH function is MD5 */ | |
164 /** | |
165 * @} | |
166 */ | |
167 | |
168 /** @defgroup HASH_Exported_Constants_Group2 HASH Algorithm Mode | |
169 * @{ | |
170 */ | |
171 #define HASH_ALGOMODE_HASH ((uint32_t)0x00000000) /*!< Algorithm is HASH */ | |
172 #define HASH_ALGOMODE_HMAC HASH_CR_MODE /*!< Algorithm is HMAC */ | |
173 /** | |
174 * @} | |
175 */ | |
176 | |
177 /** @defgroup HASH_Exported_Constants_Group3 HASH DataType | |
178 * @{ | |
179 */ | |
180 #define HASH_DATATYPE_32B ((uint32_t)0x0000) /*!< 32-bit data. No swapping */ | |
181 #define HASH_DATATYPE_16B HASH_CR_DATATYPE_0 /*!< 16-bit data. Each half word is swapped */ | |
182 #define HASH_DATATYPE_8B HASH_CR_DATATYPE_1 /*!< 8-bit data. All bytes are swapped */ | |
183 #define HASH_DATATYPE_1B HASH_CR_DATATYPE /*!< 1-bit data. In the word all bits are swapped */ | |
184 /** | |
185 * @} | |
186 */ | |
187 | |
188 /** @defgroup HASH_Exported_Constants_Group4 HASH HMAC Long key | |
189 * @brief HASH HMAC Long key used only for HMAC mode | |
190 * @{ | |
191 */ | |
192 #define HASH_HMAC_KEYTYPE_SHORTKEY ((uint32_t)0x00000000) /*!< HMAC Key is <= 64 bytes */ | |
193 #define HASH_HMAC_KEYTYPE_LONGKEY HASH_CR_LKEY /*!< HMAC Key is > 64 bytes */ | |
194 /** | |
195 * @} | |
196 */ | |
197 | |
198 /** @defgroup HASH_Exported_Constants_Group5 HASH Flags definition | |
199 * @{ | |
200 */ | |
201 #define HASH_FLAG_DINIS HASH_SR_DINIS /*!< 16 locations are free in the DIN : A new block can be entered into the input buffer */ | |
202 #define HASH_FLAG_DCIS HASH_SR_DCIS /*!< Digest calculation complete */ | |
203 #define HASH_FLAG_DMAS HASH_SR_DMAS /*!< DMA interface is enabled (DMAE=1) or a transfer is ongoing */ | |
204 #define HASH_FLAG_BUSY HASH_SR_BUSY /*!< The hash core is Busy : processing a block of data */ | |
205 #define HASH_FLAG_DINNE HASH_CR_DINNE /*!< DIN not empty : The input buffer contains at least one word of data */ | |
206 /** | |
207 * @} | |
208 */ | |
209 | |
210 /** @defgroup HASH_Exported_Constants_Group6 HASH Interrupts definition | |
211 * @{ | |
212 */ | |
213 #define HASH_IT_DINI HASH_IMR_DINIM /*!< A new block can be entered into the input buffer (DIN) */ | |
214 #define HASH_IT_DCI HASH_IMR_DCIM /*!< Digest calculation complete */ | |
215 /** | |
216 * @} | |
217 */ | |
218 | |
219 /** | |
220 * @} | |
221 */ | |
222 | |
223 /* Exported macro ------------------------------------------------------------*/ | |
224 /** @defgroup HASH_Exported_Macros HASH Exported Macros | |
225 * @{ | |
226 */ | |
227 | |
228 /** @brief Reset HASH handle state | |
229 * @param __HANDLE__: specifies the HASH handle. | |
230 * @retval None | |
231 */ | |
232 #define __HAL_HASH_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_HASH_STATE_RESET) | |
233 | |
234 /** @brief Check whether the specified HASH flag is set or not. | |
235 * @param __FLAG__: specifies the flag to check. | |
236 * This parameter can be one of the following values: | |
237 * @arg HASH_FLAG_DINIS: A new block can be entered into the input buffer. | |
238 * @arg HASH_FLAG_DCIS: Digest calculation complete | |
239 * @arg HASH_FLAG_DMAS: DMA interface is enabled (DMAE=1) or a transfer is ongoing | |
240 * @arg HASH_FLAG_BUSY: The hash core is Busy : processing a block of data | |
241 * @arg HASH_FLAG_DINNE: DIN not empty : The input buffer contains at least one word of data | |
242 * @retval The new state of __FLAG__ (TRUE or FALSE). | |
243 */ | |
244 #define __HAL_HASH_GET_FLAG(__FLAG__) ((HASH->SR & (__FLAG__)) == (__FLAG__)) | |
245 | |
246 /** | |
247 * @brief Enable the multiple DMA mode. | |
248 * This feature is available only in STM32F429x and STM32F439x devices. | |
249 * @retval None | |
250 */ | |
251 #define __HAL_HASH_SET_MDMAT() HASH->CR |= HASH_CR_MDMAT | |
252 | |
253 /** | |
254 * @brief Disable the multiple DMA mode. | |
255 * @retval None | |
256 */ | |
257 #define __HAL_HASH_RESET_MDMAT() HASH->CR &= (uint32_t)(~HASH_CR_MDMAT) | |
258 | |
259 /** | |
260 * @brief Start the digest computation | |
261 * @retval None | |
262 */ | |
263 #define __HAL_HASH_START_DIGEST() HASH->STR |= HASH_STR_DCAL | |
264 | |
265 /** | |
266 * @brief Set the number of valid bits in last word written in Data register | |
267 * @param SIZE: size in byte of last data written in Data register. | |
268 * @retval None | |
269 */ | |
270 #define __HAL_HASH_SET_NBVALIDBITS(SIZE) do{HASH->STR &= ~(HASH_STR_NBW);\ | |
271 HASH->STR |= 8 * ((SIZE) % 4);\ | |
272 }while(0) | |
273 | |
274 /** | |
275 * @} | |
276 */ | |
277 | |
278 /* Include HASH HAL Extension module */ | |
279 #include "stm32f4xx_hal_hash_ex.h" | |
280 /* Exported functions --------------------------------------------------------*/ | |
281 | |
282 /** @defgroup HASH_Exported_Functions HASH Exported Functions | |
283 * @{ | |
284 */ | |
285 | |
286 /** @addtogroup HASH_Exported_Functions_Group1 | |
287 * @{ | |
288 */ | |
289 HAL_StatusTypeDef HAL_HASH_Init(HASH_HandleTypeDef *hhash); | |
290 HAL_StatusTypeDef HAL_HASH_DeInit(HASH_HandleTypeDef *hhash); | |
291 /** | |
292 * @} | |
293 */ | |
294 | |
295 /** @addtogroup HASH_Exported_Functions_Group2 | |
296 * @{ | |
297 */ | |
298 HAL_StatusTypeDef HAL_HASH_SHA1_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer, uint32_t Timeout); | |
299 HAL_StatusTypeDef HAL_HASH_MD5_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer, uint32_t Timeout); | |
300 HAL_StatusTypeDef HAL_HASH_MD5_Accumulate(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size); | |
301 HAL_StatusTypeDef HAL_HASH_SHA1_Accumulate(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size); | |
302 /** | |
303 * @} | |
304 */ | |
305 | |
306 /** @addtogroup HASH_Exported_Functions_Group3 | |
307 * @{ | |
308 */ | |
309 HAL_StatusTypeDef HAL_HMAC_SHA1_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer, uint32_t Timeout); | |
310 HAL_StatusTypeDef HAL_HMAC_MD5_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer, uint32_t Timeout); | |
311 /** | |
312 * @} | |
313 */ | |
314 | |
315 /** @addtogroup HASH_Exported_Functions_Group4 | |
316 * @{ | |
317 */ | |
318 HAL_StatusTypeDef HAL_HASH_SHA1_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer); | |
319 HAL_StatusTypeDef HAL_HASH_MD5_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer); | |
320 /** | |
321 * @} | |
322 */ | |
323 | |
324 /** @addtogroup HASH_Exported_Functions_Group5 | |
325 * @{ | |
326 */ | |
327 HAL_StatusTypeDef HAL_HASH_SHA1_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size); | |
328 HAL_StatusTypeDef HAL_HASH_SHA1_Finish(HASH_HandleTypeDef *hhash, uint8_t* pOutBuffer, uint32_t Timeout); | |
329 HAL_StatusTypeDef HAL_HASH_MD5_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size); | |
330 HAL_StatusTypeDef HAL_HASH_MD5_Finish(HASH_HandleTypeDef *hhash, uint8_t* pOutBuffer, uint32_t Timeout); | |
331 /** | |
332 * @} | |
333 */ | |
334 | |
335 /** @addtogroup HASH_Exported_Functions_Group6 | |
336 * @{ | |
337 */ | |
338 HAL_StatusTypeDef HAL_HMAC_SHA1_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size); | |
339 HAL_StatusTypeDef HAL_HMAC_MD5_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size); | |
340 /** | |
341 * @} | |
342 */ | |
343 | |
344 /** @addtogroup HASH_Exported_Functions_Group7 | |
345 * @{ | |
346 */ | |
347 void HAL_HASH_IRQHandler(HASH_HandleTypeDef *hhash); | |
348 /** | |
349 * @} | |
350 */ | |
351 | |
352 /** @addtogroup HASH_Exported_Functions_Group8 | |
353 * @{ | |
354 */ | |
355 HAL_HASH_STATETypeDef HAL_HASH_GetState(HASH_HandleTypeDef *hhash); | |
356 void HAL_HASH_MspInit(HASH_HandleTypeDef *hhash); | |
357 void HAL_HASH_MspDeInit(HASH_HandleTypeDef *hhash); | |
358 void HAL_HASH_InCpltCallback(HASH_HandleTypeDef *hhash); | |
359 void HAL_HASH_DgstCpltCallback(HASH_HandleTypeDef *hhash); | |
360 void HAL_HASH_ErrorCallback(HASH_HandleTypeDef *hhash); | |
361 /** | |
362 * @} | |
363 */ | |
364 | |
365 /** | |
366 * @} | |
367 */ | |
368 | |
369 /* Private types -------------------------------------------------------------*/ | |
370 /** @defgroup HASH_Private_Types HASH Private Types | |
371 * @{ | |
372 */ | |
373 | |
374 /** | |
375 * @} | |
376 */ | |
377 | |
378 /* Private variables ---------------------------------------------------------*/ | |
379 /** @defgroup HASH_Private_Variables HASH Private Variables | |
380 * @{ | |
381 */ | |
382 | |
383 /** | |
384 * @} | |
385 */ | |
386 | |
387 /* Private constants ---------------------------------------------------------*/ | |
388 /** @defgroup HASH_Private_Constants HASH Private Constants | |
389 * @{ | |
390 */ | |
391 | |
392 /** | |
393 * @} | |
394 */ | |
395 | |
396 /* Private macros ------------------------------------------------------------*/ | |
397 /** @defgroup HASH_Private_Macros HASH Private Macros | |
398 * @{ | |
399 */ | |
400 #define IS_HASH_ALGOSELECTION(__ALGOSELECTION__) (((__ALGOSELECTION__) == HASH_ALGOSELECTION_SHA1) || \ | |
401 ((__ALGOSELECTION__) == HASH_ALGOSELECTION_SHA224) || \ | |
402 ((__ALGOSELECTION__) == HASH_ALGOSELECTION_SHA256) || \ | |
403 ((__ALGOSELECTION__) == HASH_ALGOSELECTION_MD5)) | |
404 | |
405 | |
406 #define IS_HASH_ALGOMODE(__ALGOMODE__) (((__ALGOMODE__) == HASH_ALGOMODE_HASH) || \ | |
407 ((__ALGOMODE__) == HASH_ALGOMODE_HMAC)) | |
408 | |
409 | |
410 #define IS_HASH_DATATYPE(__DATATYPE__) (((__DATATYPE__) == HASH_DATATYPE_32B)|| \ | |
411 ((__DATATYPE__) == HASH_DATATYPE_16B)|| \ | |
412 ((__DATATYPE__) == HASH_DATATYPE_8B) || \ | |
413 ((__DATATYPE__) == HASH_DATATYPE_1B)) | |
414 | |
415 | |
416 #define IS_HASH_HMAC_KEYTYPE(__KEYTYPE__) (((__KEYTYPE__) == HASH_HMAC_KEYTYPE_SHORTKEY) || \ | |
417 ((__KEYTYPE__) == HASH_HMAC_KEYTYPE_LONGKEY)) | |
418 | |
419 /** | |
420 * @} | |
421 */ | |
422 | |
423 /* Private functions ---------------------------------------------------------*/ | |
424 /** @defgroup HASH_Private_Functions HASH Private Functions | |
425 * @{ | |
426 */ | |
427 | |
428 /** | |
429 * @} | |
430 */ | |
431 | |
432 #endif /* STM32F415xx || STM32F417xx || STM32F437xx || STM32F439xx */ | |
433 /** | |
434 * @} | |
435 */ | |
436 | |
437 /** | |
438 * @} | |
439 */ | |
440 | |
441 #ifdef __cplusplus | |
442 } | |
443 #endif | |
444 | |
445 | |
446 #endif /* __STM32F4xx_HAL_HASH_H */ | |
447 | |
448 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |