comparison Common/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_hash.h @ 128:c78bcbd5deda FlipDisplay

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