1 /**
2 ******************************************************************************
3 * @file stm32h7xx_hal_hash_ex.c
4 * @author MCD Application Team
5 * @brief Extended HASH HAL module driver.
6 * This file provides firmware functions to manage the following
7 * functionalities of the HASH peripheral for SHA-224 and SHA-256
8 * algorithms:
9 * + HASH or HMAC processing in polling mode
10 * + HASH or HMAC processing in interrupt mode
11 * + HASH or HMAC processing in DMA mode
12 * Additionally, this file provides functions to manage HMAC
13 * multi-buffer DMA-based processing for MD-5, SHA-1, SHA-224
14 * and SHA-256.
15 *
16 *
17 ******************************************************************************
18 * @attention
19 *
20 * Copyright (c) 2017 STMicroelectronics.
21 * All rights reserved.
22 *
23 * This software is licensed under terms that can be found in the LICENSE file
24 * in the root directory of this software component.
25 * If no LICENSE file comes with this software, it is provided AS-IS.
26 *
27 ******************************************************************************
28 @verbatim
29 ===============================================================================
30 ##### HASH peripheral extended features #####
31 ===============================================================================
32 [..]
33 The SHA-224 and SHA-256 HASH and HMAC processing can be carried out exactly
34 the same way as for SHA-1 or MD-5 algorithms.
35 (#) Three modes are available.
36 (##) Polling mode: processing APIs are blocking functions
37 i.e. they process the data and wait till the digest computation is finished,
38 e.g. HAL_HASHEx_xxx_Start()
39 (##) Interrupt mode: processing APIs are not blocking functions
40 i.e. they process the data under interrupt,
41 e.g. HAL_HASHEx_xxx_Start_IT()
42 (##) DMA mode: processing APIs are not blocking functions and the CPU is
43 not used for data transfer i.e. the data transfer is ensured by DMA,
44 e.g. HAL_HASHEx_xxx_Start_DMA(). Note that in DMA mode, a call to
45 HAL_HASHEx_xxx_Finish() is then required to retrieve the digest.
46
47 (#)Multi-buffer processing is possible in polling, interrupt and DMA modes.
48 (##) In polling mode, only multi-buffer HASH processing is possible.
49 API HAL_HASHEx_xxx_Accumulate() must be called for each input buffer, except for the last one.
50 User must resort to HAL_HASHEx_xxx_Accumulate_End() to enter the last one and retrieve as
51 well the computed digest.
52
53 (##) In interrupt mode, API HAL_HASHEx_xxx_Accumulate_IT() must be called for each input buffer,
54 except for the last one.
55 User must resort to HAL_HASHEx_xxx_Accumulate_End_IT() to enter the last one and retrieve as
56 well the computed digest.
57
58 (##) In DMA mode, multi-buffer HASH and HMAC processing are possible.
59
60 (+++) HASH processing: once initialization is done, MDMAT bit must be set through
61 __HAL_HASH_SET_MDMAT() macro.
62 From that point, each buffer can be fed to the Peripheral through HAL_HASHEx_xxx_Start_DMA() API.
63 Before entering the last buffer, reset the MDMAT bit with __HAL_HASH_RESET_MDMAT()
64 macro then wrap-up the HASH processing in feeding the last input buffer through the
65 same API HAL_HASHEx_xxx_Start_DMA(). The digest can then be retrieved with a call to
66 API HAL_HASHEx_xxx_Finish().
67
68 (+++) HMAC processing (MD-5, SHA-1, SHA-224 and SHA-256 must all resort to
69 extended functions): after initialization, the key and the first input buffer are entered
70 in the Peripheral with the API HAL_HMACEx_xxx_Step1_2_DMA(). This carries out HMAC step 1 and
71 starts step 2.
72 The following buffers are next entered with the API HAL_HMACEx_xxx_Step2_DMA(). At this
73 point, the HMAC processing is still carrying out step 2.
74 Then, step 2 for the last input buffer and step 3 are carried out by a single call
75 to HAL_HMACEx_xxx_Step2_3_DMA().
76
77 The digest can finally be retrieved with a call to API HAL_HASH_xxx_Finish() for
78 MD-5 and SHA-1, to HAL_HASHEx_xxx_Finish() for SHA-224 and SHA-256.
79
80
81 @endverbatim
82 ******************************************************************************
83 */
84
85 /* Includes ------------------------------------------------------------------*/
86 #include "stm32h7xx_hal.h"
87
88
89 /** @addtogroup STM32H7xx_HAL_Driver
90 * @{
91 */
92 #if defined (HASH)
93
94 /** @defgroup HASHEx HASHEx
95 * @brief HASH HAL extended module driver.
96 * @{
97 */
98 #ifdef HAL_HASH_MODULE_ENABLED
99 /* Private typedef -----------------------------------------------------------*/
100 /* Private define ------------------------------------------------------------*/
101 /* Private functions ---------------------------------------------------------*/
102
103
104 /** @defgroup HASHEx_Exported_Functions HASH Extended Exported Functions
105 * @{
106 */
107
108 /** @defgroup HASHEx_Exported_Functions_Group1 HASH extended processing functions in polling mode
109 * @brief HASH extended processing functions using polling mode.
110 *
111 @verbatim
112 ===============================================================================
113 ##### Polling mode HASH extended processing functions #####
114 ===============================================================================
115 [..] This section provides functions allowing to calculate in polling mode
116 the hash value using one of the following algorithms:
117 (+) SHA224
118 (++) HAL_HASHEx_SHA224_Start()
119 (++) HAL_HASHEx_SHA224_Accmlt()
120 (++) HAL_HASHEx_SHA224_Accmlt_End()
121 (+) SHA256
122 (++) HAL_HASHEx_SHA256_Start()
123 (++) HAL_HASHEx_SHA256_Accmlt()
124 (++) HAL_HASHEx_SHA256_Accmlt_End()
125
126 [..] For a single buffer to be hashed, user can resort to HAL_HASH_xxx_Start().
127
128 [..] In case of multi-buffer HASH processing (a single digest is computed while
129 several buffers are fed to the Peripheral), the user can resort to successive calls
130 to HAL_HASHEx_xxx_Accumulate() and wrap-up the digest computation by a call
131 to HAL_HASHEx_xxx_Accumulate_End().
132
133 @endverbatim
134 * @{
135 */
136
137
138 /**
139 * @brief Initialize the HASH peripheral in SHA224 mode, next process pInBuffer then
140 * read the computed digest.
141 * @note Digest is available in pOutBuffer.
142 * @param hhash HASH handle.
143 * @param pInBuffer pointer to the input buffer (buffer to be hashed).
144 * @param Size length of the input buffer in bytes.
145 * @param pOutBuffer pointer to the computed digest. Digest size is 28 bytes.
146 * @param Timeout Timeout value
147 * @retval HAL status
148 */
HAL_HASHEx_SHA224_Start(HASH_HandleTypeDef * hhash,const uint8_t * const pInBuffer,uint32_t Size,uint8_t * pOutBuffer,uint32_t Timeout)149 HAL_StatusTypeDef HAL_HASHEx_SHA224_Start(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size,
150 uint8_t *pOutBuffer, uint32_t Timeout)
151 {
152 return HASH_Start(hhash, pInBuffer, Size, pOutBuffer, Timeout, HASH_ALGOSELECTION_SHA224);
153 }
154
155 /**
156 * @brief If not already done, initialize the HASH peripheral in SHA224 mode then
157 * processes pInBuffer.
158 * @note Consecutive calls to HAL_HASHEx_SHA224_Accmlt() can be used to feed
159 * several input buffers back-to-back to the Peripheral that will yield a single
160 * HASH signature once all buffers have been entered. Wrap-up of input
161 * buffers feeding and retrieval of digest is done by a call to
162 * HAL_HASHEx_SHA224_Accmlt_End().
163 * @note Field hhash->Phase of HASH handle is tested to check whether or not
164 * the Peripheral has already been initialized.
165 * @note Digest is not retrieved by this API, user must resort to HAL_HASHEx_SHA224_Accmlt_End()
166 * to read it, feeding at the same time the last input buffer to the Peripheral.
167 * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the
168 * HASH digest computation is corrupted. Only HAL_HASHEx_SHA224_Accmlt_End() is able
169 * to manage the ending buffer with a length in bytes not a multiple of 4.
170 * @param hhash HASH handle.
171 * @param pInBuffer pointer to the input buffer (buffer to be hashed).
172 * @param Size length of the input buffer in bytes, must be a multiple of 4.
173 * @retval HAL status
174 */
HAL_HASHEx_SHA224_Accmlt(HASH_HandleTypeDef * hhash,const uint8_t * const pInBuffer,uint32_t Size)175 HAL_StatusTypeDef HAL_HASHEx_SHA224_Accmlt(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size)
176 {
177 return HASH_Accumulate(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA224);
178 }
179
180 /**
181 * @brief End computation of a single HASH signature after several calls to HAL_HASHEx_SHA224_Accmlt() API.
182 * @note Digest is available in pOutBuffer.
183 * @param hhash HASH handle.
184 * @param pInBuffer pointer to the input buffer (buffer to be hashed).
185 * @param Size length of the input buffer in bytes.
186 * @param pOutBuffer pointer to the computed digest. Digest size is 28 bytes.
187 * @param Timeout Timeout value
188 * @retval HAL status
189 */
HAL_HASHEx_SHA224_Accmlt_End(HASH_HandleTypeDef * hhash,const uint8_t * const pInBuffer,uint32_t Size,uint8_t * pOutBuffer,uint32_t Timeout)190 HAL_StatusTypeDef HAL_HASHEx_SHA224_Accmlt_End(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size,
191 uint8_t *pOutBuffer, uint32_t Timeout)
192 {
193 return HASH_Start(hhash, pInBuffer, Size, pOutBuffer, Timeout, HASH_ALGOSELECTION_SHA224);
194 }
195
196 /**
197 * @brief Initialize the HASH peripheral in SHA256 mode, next process pInBuffer then
198 * read the computed digest.
199 * @note Digest is available in pOutBuffer.
200 * @param hhash HASH handle.
201 * @param pInBuffer pointer to the input buffer (buffer to be hashed).
202 * @param Size length of the input buffer in bytes.
203 * @param pOutBuffer pointer to the computed digest. Digest size is 32 bytes.
204 * @param Timeout Timeout value
205 * @retval HAL status
206 */
HAL_HASHEx_SHA256_Start(HASH_HandleTypeDef * hhash,const uint8_t * const pInBuffer,uint32_t Size,uint8_t * pOutBuffer,uint32_t Timeout)207 HAL_StatusTypeDef HAL_HASHEx_SHA256_Start(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size,
208 uint8_t *pOutBuffer, uint32_t Timeout)
209 {
210 return HASH_Start(hhash, pInBuffer, Size, pOutBuffer, Timeout, HASH_ALGOSELECTION_SHA256);
211 }
212
213 /**
214 * @brief If not already done, initialize the HASH peripheral in SHA256 mode then
215 * processes pInBuffer.
216 * @note Consecutive calls to HAL_HASHEx_SHA256_Accmlt() can be used to feed
217 * several input buffers back-to-back to the Peripheral that will yield a single
218 * HASH signature once all buffers have been entered. Wrap-up of input
219 * buffers feeding and retrieval of digest is done by a call to
220 * HAL_HASHEx_SHA256_Accmlt_End().
221 * @note Field hhash->Phase of HASH handle is tested to check whether or not
222 * the Peripheral has already been initialized.
223 * @note Digest is not retrieved by this API, user must resort to HAL_HASHEx_SHA256_Accmlt_End()
224 * to read it, feeding at the same time the last input buffer to the Peripheral.
225 * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the
226 * HASH digest computation is corrupted. Only HAL_HASHEx_SHA256_Accmlt_End() is able
227 * to manage the ending buffer with a length in bytes not a multiple of 4.
228 * @param hhash HASH handle.
229 * @param pInBuffer pointer to the input buffer (buffer to be hashed).
230 * @param Size length of the input buffer in bytes, must be a multiple of 4.
231 * @retval HAL status
232 */
HAL_HASHEx_SHA256_Accmlt(HASH_HandleTypeDef * hhash,const uint8_t * const pInBuffer,uint32_t Size)233 HAL_StatusTypeDef HAL_HASHEx_SHA256_Accmlt(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size)
234 {
235 return HASH_Accumulate(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA256);
236 }
237
238 /**
239 * @brief End computation of a single HASH signature after several calls to HAL_HASHEx_SHA256_Accmlt() API.
240 * @note Digest is available in pOutBuffer.
241 * @param hhash HASH handle.
242 * @param pInBuffer pointer to the input buffer (buffer to be hashed).
243 * @param Size length of the input buffer in bytes.
244 * @param pOutBuffer pointer to the computed digest. Digest size is 32 bytes.
245 * @param Timeout Timeout value
246 * @retval HAL status
247 */
HAL_HASHEx_SHA256_Accmlt_End(HASH_HandleTypeDef * hhash,const uint8_t * const pInBuffer,uint32_t Size,uint8_t * pOutBuffer,uint32_t Timeout)248 HAL_StatusTypeDef HAL_HASHEx_SHA256_Accmlt_End(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size,
249 uint8_t *pOutBuffer, uint32_t Timeout)
250 {
251 return HASH_Start(hhash, pInBuffer, Size, pOutBuffer, Timeout, HASH_ALGOSELECTION_SHA256);
252 }
253
254 /**
255 * @}
256 */
257
258 /** @defgroup HASHEx_Exported_Functions_Group2 HASH extended processing functions in interrupt mode
259 * @brief HASH extended processing functions using interrupt mode.
260 *
261 @verbatim
262 ===============================================================================
263 ##### Interruption mode HASH extended processing functions #####
264 ===============================================================================
265 [..] This section provides functions allowing to calculate in interrupt mode
266 the hash value using one of the following algorithms:
267 (+) SHA224
268 (++) HAL_HASHEx_SHA224_Start_IT()
269 (++) HAL_HASHEx_SHA224_Accmlt_IT()
270 (++) HAL_HASHEx_SHA224_Accmlt_End_IT()
271 (+) SHA256
272 (++) HAL_HASHEx_SHA256_Start_IT()
273 (++) HAL_HASHEx_SHA256_Accmlt_IT()
274 (++) HAL_HASHEx_SHA256_Accmlt_End_IT()
275
276 @endverbatim
277 * @{
278 */
279
280
281 /**
282 * @brief Initialize the HASH peripheral in SHA224 mode, next process pInBuffer then
283 * read the computed digest in interruption mode.
284 * @note Digest is available in pOutBuffer.
285 * @param hhash HASH handle.
286 * @param pInBuffer pointer to the input buffer (buffer to be hashed).
287 * @param Size length of the input buffer in bytes.
288 * @param pOutBuffer pointer to the computed digest. Digest size is 28 bytes.
289 * @retval HAL status
290 */
HAL_HASHEx_SHA224_Start_IT(HASH_HandleTypeDef * hhash,const uint8_t * const pInBuffer,uint32_t Size,uint8_t * pOutBuffer)291 HAL_StatusTypeDef HAL_HASHEx_SHA224_Start_IT(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size,
292 uint8_t *pOutBuffer)
293 {
294 return HASH_Start_IT(hhash, pInBuffer, Size, pOutBuffer, HASH_ALGOSELECTION_SHA224);
295 }
296
297 /**
298 * @brief If not already done, initialize the HASH peripheral in SHA224 mode then
299 * processes pInBuffer in interruption mode.
300 * @note Consecutive calls to HAL_HASHEx_SHA224_Accmlt_IT() can be used to feed
301 * several input buffers back-to-back to the Peripheral that will yield a single
302 * HASH signature once all buffers have been entered. Wrap-up of input
303 * buffers feeding and retrieval of digest is done by a call to
304 * HAL_HASHEx_SHA224_Accmlt_End_IT().
305 * @note Field hhash->Phase of HASH handle is tested to check whether or not
306 * the Peripheral has already been initialized.
307 * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the
308 * HASH digest computation is corrupted. Only HAL_HASHEx_SHA224_Accmlt_End_IT() is able
309 * to manage the ending buffer with a length in bytes not a multiple of 4.
310 * @param hhash HASH handle.
311 * @param pInBuffer pointer to the input buffer (buffer to be hashed).
312 * @param Size length of the input buffer in bytes, must be a multiple of 4.
313 * @retval HAL status
314 */
HAL_HASHEx_SHA224_Accmlt_IT(HASH_HandleTypeDef * hhash,const uint8_t * const pInBuffer,uint32_t Size)315 HAL_StatusTypeDef HAL_HASHEx_SHA224_Accmlt_IT(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size)
316 {
317 return HASH_Accumulate_IT(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA224);
318 }
319
320 /**
321 * @brief End computation of a single HASH signature after several calls to HAL_HASHEx_SHA224_Accmlt_IT() API.
322 * @note Digest is available in pOutBuffer.
323 * @param hhash HASH handle.
324 * @param pInBuffer pointer to the input buffer (buffer to be hashed).
325 * @param Size length of the input buffer in bytes.
326 * @param pOutBuffer pointer to the computed digest. Digest size is 28 bytes.
327 * @retval HAL status
328 */
HAL_HASHEx_SHA224_Accmlt_End_IT(HASH_HandleTypeDef * hhash,const uint8_t * const pInBuffer,uint32_t Size,uint8_t * pOutBuffer)329 HAL_StatusTypeDef HAL_HASHEx_SHA224_Accmlt_End_IT(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer,
330 uint32_t Size,
331 uint8_t *pOutBuffer)
332 {
333 return HASH_Start_IT(hhash, pInBuffer, Size, pOutBuffer, HASH_ALGOSELECTION_SHA224);
334 }
335
336 /**
337 * @brief Initialize the HASH peripheral in SHA256 mode, next process pInBuffer then
338 * read the computed digest in interruption mode.
339 * @note Digest is available in pOutBuffer.
340 * @param hhash HASH handle.
341 * @param pInBuffer pointer to the input buffer (buffer to be hashed).
342 * @param Size length of the input buffer in bytes.
343 * @param pOutBuffer pointer to the computed digest. Digest size is 32 bytes.
344 * @retval HAL status
345 */
HAL_HASHEx_SHA256_Start_IT(HASH_HandleTypeDef * hhash,const uint8_t * const pInBuffer,uint32_t Size,uint8_t * pOutBuffer)346 HAL_StatusTypeDef HAL_HASHEx_SHA256_Start_IT(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size,
347 uint8_t *pOutBuffer)
348 {
349 return HASH_Start_IT(hhash, pInBuffer, Size, pOutBuffer, HASH_ALGOSELECTION_SHA256);
350 }
351
352 /**
353 * @brief If not already done, initialize the HASH peripheral in SHA256 mode then
354 * processes pInBuffer in interruption mode.
355 * @note Consecutive calls to HAL_HASHEx_SHA256_Accmlt_IT() can be used to feed
356 * several input buffers back-to-back to the Peripheral that will yield a single
357 * HASH signature once all buffers have been entered. Wrap-up of input
358 * buffers feeding and retrieval of digest is done by a call to
359 * HAL_HASHEx_SHA256_Accmlt_End_IT().
360 * @note Field hhash->Phase of HASH handle is tested to check whether or not
361 * the Peripheral has already been initialized.
362 * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the
363 * HASH digest computation is corrupted. Only HAL_HASHEx_SHA256_Accmlt_End_IT() is able
364 * to manage the ending buffer with a length in bytes not a multiple of 4.
365 * @param hhash HASH handle.
366 * @param pInBuffer pointer to the input buffer (buffer to be hashed).
367 * @param Size length of the input buffer in bytes, must be a multiple of 4.
368 * @retval HAL status
369 */
HAL_HASHEx_SHA256_Accmlt_IT(HASH_HandleTypeDef * hhash,const uint8_t * const pInBuffer,uint32_t Size)370 HAL_StatusTypeDef HAL_HASHEx_SHA256_Accmlt_IT(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size)
371 {
372 return HASH_Accumulate_IT(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA256);
373 }
374
375 /**
376 * @brief End computation of a single HASH signature after several calls to HAL_HASHEx_SHA256_Accmlt_IT() API.
377 * @note Digest is available in pOutBuffer.
378 * @param hhash HASH handle.
379 * @param pInBuffer pointer to the input buffer (buffer to be hashed).
380 * @param Size length of the input buffer in bytes.
381 * @param pOutBuffer pointer to the computed digest. Digest size is 32 bytes.
382 * @retval HAL status
383 */
HAL_HASHEx_SHA256_Accmlt_End_IT(HASH_HandleTypeDef * hhash,const uint8_t * const pInBuffer,uint32_t Size,uint8_t * pOutBuffer)384 HAL_StatusTypeDef HAL_HASHEx_SHA256_Accmlt_End_IT(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer,
385 uint32_t Size,
386 uint8_t *pOutBuffer)
387 {
388 return HASH_Start_IT(hhash, pInBuffer, Size, pOutBuffer, HASH_ALGOSELECTION_SHA256);
389 }
390
391 /**
392 * @}
393 */
394
395 /** @defgroup HASHEx_Exported_Functions_Group3 HASH extended processing functions in DMA mode
396 * @brief HASH extended processing functions using DMA mode.
397 *
398 @verbatim
399 ===============================================================================
400 ##### DMA mode HASH extended processing functions #####
401 ===============================================================================
402 [..] This section provides functions allowing to calculate in DMA mode
403 the hash value using one of the following algorithms:
404 (+) SHA224
405 (++) HAL_HASHEx_SHA224_Start_DMA()
406 (++) HAL_HASHEx_SHA224_Finish()
407 (+) SHA256
408 (++) HAL_HASHEx_SHA256_Start_DMA()
409 (++) HAL_HASHEx_SHA256_Finish()
410
411 [..] When resorting to DMA mode to enter the data in the Peripheral, user must resort
412 to HAL_HASHEx_xxx_Start_DMA() then read the resulting digest with
413 HAL_HASHEx_xxx_Finish().
414
415 [..] In case of multi-buffer HASH processing, MDMAT bit must first be set before
416 the successive calls to HAL_HASHEx_xxx_Start_DMA(). Then, MDMAT bit needs to be
417 reset before the last call to HAL_HASHEx_xxx_Start_DMA(). Digest is finally
418 retrieved thanks to HAL_HASHEx_xxx_Finish().
419
420 @endverbatim
421 * @{
422 */
423
424
425 /**
426 * @brief Initialize the HASH peripheral in SHA224 mode then initiate a DMA transfer
427 * to feed the input buffer to the Peripheral.
428 * @note Once the DMA transfer is finished, HAL_HASHEx_SHA224_Finish() API must
429 * be called to retrieve the computed digest.
430 * @param hhash HASH handle.
431 * @param pInBuffer pointer to the input buffer (buffer to be hashed).
432 * @param Size length of the input buffer in bytes.
433 * @retval HAL status
434 */
HAL_HASHEx_SHA224_Start_DMA(HASH_HandleTypeDef * hhash,const uint8_t * const pInBuffer,uint32_t Size)435 HAL_StatusTypeDef HAL_HASHEx_SHA224_Start_DMA(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size)
436 {
437 return HASH_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA224);
438 }
439
440 /**
441 * @brief Return the computed digest in SHA224 mode.
442 * @note The API waits for DCIS to be set then reads the computed digest.
443 * @note HAL_HASHEx_SHA224_Finish() can be used as well to retrieve the digest in
444 * HMAC SHA224 mode.
445 * @param hhash HASH handle.
446 * @param pOutBuffer pointer to the computed digest. Digest size is 28 bytes.
447 * @param Timeout Timeout value.
448 * @retval HAL status
449 */
HAL_HASHEx_SHA224_Finish(HASH_HandleTypeDef * hhash,uint8_t * pOutBuffer,uint32_t Timeout)450 HAL_StatusTypeDef HAL_HASHEx_SHA224_Finish(HASH_HandleTypeDef *hhash, uint8_t *pOutBuffer, uint32_t Timeout)
451 {
452 return HASH_Finish(hhash, pOutBuffer, Timeout);
453 }
454
455 /**
456 * @brief Initialize the HASH peripheral in SHA256 mode then initiate a DMA transfer
457 * to feed the input buffer to the Peripheral.
458 * @note Once the DMA transfer is finished, HAL_HASHEx_SHA256_Finish() API must
459 * be called to retrieve the computed digest.
460 * @param hhash HASH handle.
461 * @param pInBuffer pointer to the input buffer (buffer to be hashed).
462 * @param Size length of the input buffer in bytes.
463 * @retval HAL status
464 */
HAL_HASHEx_SHA256_Start_DMA(HASH_HandleTypeDef * hhash,const uint8_t * const pInBuffer,uint32_t Size)465 HAL_StatusTypeDef HAL_HASHEx_SHA256_Start_DMA(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size)
466 {
467 return HASH_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA256);
468 }
469
470 /**
471 * @brief Return the computed digest in SHA256 mode.
472 * @note The API waits for DCIS to be set then reads the computed digest.
473 * @note HAL_HASHEx_SHA256_Finish() can be used as well to retrieve the digest in
474 * HMAC SHA256 mode.
475 * @param hhash HASH handle.
476 * @param pOutBuffer pointer to the computed digest. Digest size is 32 bytes.
477 * @param Timeout Timeout value.
478 * @retval HAL status
479 */
HAL_HASHEx_SHA256_Finish(HASH_HandleTypeDef * hhash,uint8_t * pOutBuffer,uint32_t Timeout)480 HAL_StatusTypeDef HAL_HASHEx_SHA256_Finish(HASH_HandleTypeDef *hhash, uint8_t *pOutBuffer, uint32_t Timeout)
481 {
482 return HASH_Finish(hhash, pOutBuffer, Timeout);
483 }
484
485 /**
486 * @}
487 */
488
489 /** @defgroup HASHEx_Exported_Functions_Group4 HMAC extended processing functions in polling mode
490 * @brief HMAC extended processing functions using polling mode.
491 *
492 @verbatim
493 ===============================================================================
494 ##### Polling mode HMAC extended processing functions #####
495 ===============================================================================
496 [..] This section provides functions allowing to calculate in polling mode
497 the HMAC value using one of the following algorithms:
498 (+) SHA224
499 (++) HAL_HMACEx_SHA224_Start()
500 (+) SHA256
501 (++) HAL_HMACEx_SHA256_Start()
502
503 @endverbatim
504 * @{
505 */
506
507
508 /**
509 * @brief Initialize the HASH peripheral in HMAC SHA224 mode, next process pInBuffer then
510 * read the computed digest.
511 * @note Digest is available in pOutBuffer.
512 * @note Same key is used for the inner and the outer hash functions; pointer to key and
513 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
514 * @param hhash HASH handle.
515 * @param pInBuffer pointer to the input buffer (buffer to be hashed).
516 * @param Size length of the input buffer in bytes.
517 * @param pOutBuffer pointer to the computed digest. Digest size is 28 bytes.
518 * @param Timeout Timeout value.
519 * @retval HAL status
520 */
HAL_HMACEx_SHA224_Start(HASH_HandleTypeDef * hhash,const uint8_t * const pInBuffer,uint32_t Size,uint8_t * pOutBuffer,uint32_t Timeout)521 HAL_StatusTypeDef HAL_HMACEx_SHA224_Start(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size,
522 uint8_t *pOutBuffer, uint32_t Timeout)
523 {
524 return HMAC_Start(hhash, pInBuffer, Size, pOutBuffer, Timeout, HASH_ALGOSELECTION_SHA224);
525 }
526
527 /**
528 * @brief Initialize the HASH peripheral in HMAC SHA256 mode, next process pInBuffer then
529 * read the computed digest.
530 * @note Digest is available in pOutBuffer.
531 * @note Same key is used for the inner and the outer hash functions; pointer to key and
532 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
533 * @param hhash HASH handle.
534 * @param pInBuffer pointer to the input buffer (buffer to be hashed).
535 * @param Size length of the input buffer in bytes.
536 * @param pOutBuffer pointer to the computed digest. Digest size is 32 bytes.
537 * @param Timeout Timeout value.
538 * @retval HAL status
539 */
HAL_HMACEx_SHA256_Start(HASH_HandleTypeDef * hhash,const uint8_t * const pInBuffer,uint32_t Size,uint8_t * pOutBuffer,uint32_t Timeout)540 HAL_StatusTypeDef HAL_HMACEx_SHA256_Start(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size,
541 uint8_t *pOutBuffer, uint32_t Timeout)
542 {
543 return HMAC_Start(hhash, pInBuffer, Size, pOutBuffer, Timeout, HASH_ALGOSELECTION_SHA256);
544 }
545
546 /**
547 * @}
548 */
549
550
551 /** @defgroup HASHEx_Exported_Functions_Group5 HMAC extended processing functions in interrupt mode
552 * @brief HMAC extended processing functions using interruption mode.
553 *
554 @verbatim
555 ===============================================================================
556 ##### Interrupt mode HMAC extended processing functions #####
557 ===============================================================================
558 [..] This section provides functions allowing to calculate in interrupt mode
559 the HMAC value using one of the following algorithms:
560 (+) SHA224
561 (++) HAL_HMACEx_SHA224_Start_IT()
562 (+) SHA256
563 (++) HAL_HMACEx_SHA256_Start_IT()
564
565 @endverbatim
566 * @{
567 */
568
569
570 /**
571 * @brief Initialize the HASH peripheral in HMAC SHA224 mode, next process pInBuffer then
572 * read the computed digest in interrupt mode.
573 * @note Digest is available in pOutBuffer.
574 * @note Same key is used for the inner and the outer hash functions; pointer to key and
575 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
576 * @param hhash HASH handle.
577 * @param pInBuffer pointer to the input buffer (buffer to be hashed).
578 * @param Size length of the input buffer in bytes.
579 * @param pOutBuffer pointer to the computed digest. Digest size is 28 bytes.
580 * @retval HAL status
581 */
HAL_HMACEx_SHA224_Start_IT(HASH_HandleTypeDef * hhash,const uint8_t * const pInBuffer,uint32_t Size,uint8_t * pOutBuffer)582 HAL_StatusTypeDef HAL_HMACEx_SHA224_Start_IT(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size,
583 uint8_t *pOutBuffer)
584 {
585 return HMAC_Start_IT(hhash, pInBuffer, Size, pOutBuffer, HASH_ALGOSELECTION_SHA224);
586 }
587
588 /**
589 * @brief Initialize the HASH peripheral in HMAC SHA256 mode, next process pInBuffer then
590 * read the computed digest in interrupt mode.
591 * @note Digest is available in pOutBuffer.
592 * @note Same key is used for the inner and the outer hash functions; pointer to key and
593 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
594 * @param hhash HASH handle.
595 * @param pInBuffer pointer to the input buffer (buffer to be hashed).
596 * @param Size length of the input buffer in bytes.
597 * @param pOutBuffer pointer to the computed digest. Digest size is 32 bytes.
598 * @retval HAL status
599 */
HAL_HMACEx_SHA256_Start_IT(HASH_HandleTypeDef * hhash,const uint8_t * const pInBuffer,uint32_t Size,uint8_t * pOutBuffer)600 HAL_StatusTypeDef HAL_HMACEx_SHA256_Start_IT(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size,
601 uint8_t *pOutBuffer)
602 {
603 return HMAC_Start_IT(hhash, pInBuffer, Size, pOutBuffer, HASH_ALGOSELECTION_SHA256);
604 }
605
606
607 /**
608 * @}
609 */
610
611
612 /** @defgroup HASHEx_Exported_Functions_Group6 HMAC extended processing functions in DMA mode
613 * @brief HMAC extended processing functions using DMA mode.
614 *
615 @verbatim
616 ===============================================================================
617 ##### DMA mode HMAC extended processing functions #####
618 ===============================================================================
619 [..] This section provides functions allowing to calculate in DMA mode
620 the HMAC value using one of the following algorithms:
621 (+) SHA224
622 (++) HAL_HMACEx_SHA224_Start_DMA()
623 (+) SHA256
624 (++) HAL_HMACEx_SHA256_Start_DMA()
625
626 [..] When resorting to DMA mode to enter the data in the Peripheral for HMAC processing,
627 user must resort to HAL_HMACEx_xxx_Start_DMA() then read the resulting digest
628 with HAL_HASHEx_xxx_Finish().
629
630
631 @endverbatim
632 * @{
633 */
634
635
636 /**
637 * @brief Initialize the HASH peripheral in HMAC SHA224 mode then initiate the required
638 * DMA transfers to feed the key and the input buffer to the Peripheral.
639 * @note Once the DMA transfers are finished (indicated by hhash->State set back
640 * to HAL_HASH_STATE_READY), HAL_HASHEx_SHA224_Finish() API must be called to retrieve
641 * the computed digest.
642 * @note Same key is used for the inner and the outer hash functions; pointer to key and
643 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
644 * @note If MDMAT bit is set before calling this function (multi-buffer
645 * HASH processing case), the input buffer size (in bytes) must be
646 * a multiple of 4 otherwise, the HASH digest computation is corrupted.
647 * For the processing of the last buffer of the thread, MDMAT bit must
648 * be reset and the buffer length (in bytes) doesn't have to be a
649 * multiple of 4.
650 * @param hhash HASH handle.
651 * @param pInBuffer pointer to the input buffer (buffer to be hashed).
652 * @param Size length of the input buffer in bytes.
653 * @retval HAL status
654 */
HAL_HMACEx_SHA224_Start_DMA(HASH_HandleTypeDef * hhash,const uint8_t * const pInBuffer,uint32_t Size)655 HAL_StatusTypeDef HAL_HMACEx_SHA224_Start_DMA(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size)
656 {
657 return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA224);
658 }
659
660 /**
661 * @brief Initialize the HASH peripheral in HMAC SHA224 mode then initiate the required
662 * DMA transfers to feed the key and the input buffer to the Peripheral.
663 * @note Once the DMA transfers are finished (indicated by hhash->State set back
664 * to HAL_HASH_STATE_READY), HAL_HASHEx_SHA256_Finish() API must be called to retrieve
665 * the computed digest.
666 * @note Same key is used for the inner and the outer hash functions; pointer to key and
667 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
668 * @note If MDMAT bit is set before calling this function (multi-buffer
669 * HASH processing case), the input buffer size (in bytes) must be
670 * a multiple of 4 otherwise, the HASH digest computation is corrupted.
671 * For the processing of the last buffer of the thread, MDMAT bit must
672 * be reset and the buffer length (in bytes) doesn't have to be a
673 * multiple of 4.
674 * @param hhash HASH handle.
675 * @param pInBuffer pointer to the input buffer (buffer to be hashed).
676 * @param Size length of the input buffer in bytes.
677 * @retval HAL status
678 */
HAL_HMACEx_SHA256_Start_DMA(HASH_HandleTypeDef * hhash,const uint8_t * const pInBuffer,uint32_t Size)679 HAL_StatusTypeDef HAL_HMACEx_SHA256_Start_DMA(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size)
680 {
681 return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA256);
682 }
683
684
685 /**
686 * @}
687 */
688
689 /** @defgroup HASHEx_Exported_Functions_Group7 Multi-buffer HMAC extended processing functions in DMA mode
690 * @brief HMAC extended processing functions in multi-buffer DMA mode.
691 *
692 @verbatim
693 ===============================================================================
694 ##### Multi-buffer DMA mode HMAC extended processing functions #####
695 ===============================================================================
696 [..] This section provides functions to manage HMAC multi-buffer
697 DMA-based processing for MD5, SHA1, SHA224 and SHA256 algorithms.
698 (+) MD5
699 (++) HAL_HMACEx_MD5_Step1_2_DMA()
700 (++) HAL_HMACEx_MD5_Step2_DMA()
701 (++) HAL_HMACEx_MD5_Step2_3_DMA()
702 (+) SHA1
703 (++) HAL_HMACEx_SHA1_Step1_2_DMA()
704 (++) HAL_HMACEx_SHA1_Step2_DMA()
705 (++) HAL_HMACEx_SHA1_Step2_3_DMA()
706
707 (+) SHA256
708 (++) HAL_HMACEx_SHA224_Step1_2_DMA()
709 (++) HAL_HMACEx_SHA224_Step2_DMA()
710 (++) HAL_HMACEx_SHA224_Step2_3_DMA()
711 (+) SHA256
712 (++) HAL_HMACEx_SHA256_Step1_2_DMA()
713 (++) HAL_HMACEx_SHA256_Step2_DMA()
714 (++) HAL_HMACEx_SHA256_Step2_3_DMA()
715
716 [..] User must first start-up the multi-buffer DMA-based HMAC computation in
717 calling HAL_HMACEx_xxx_Step1_2_DMA(). This carries out HMAC step 1 and
718 intiates step 2 with the first input buffer.
719
720 [..] The following buffers are next fed to the Peripheral with a call to the API
721 HAL_HMACEx_xxx_Step2_DMA(). There may be several consecutive calls
722 to this API.
723
724 [..] Multi-buffer DMA-based HMAC computation is wrapped up by a call to
725 HAL_HMACEx_xxx_Step2_3_DMA(). This finishes step 2 in feeding the last input
726 buffer to the Peripheral then carries out step 3.
727
728 [..] Digest is retrieved by a call to HAL_HASH_xxx_Finish() for MD-5 or
729 SHA-1, to HAL_HASHEx_xxx_Finish() for SHA-224 or SHA-256.
730
731 [..] If only two buffers need to be consecutively processed, a call to
732 HAL_HMACEx_xxx_Step1_2_DMA() followed by a call to HAL_HMACEx_xxx_Step2_3_DMA()
733 is sufficient.
734
735 @endverbatim
736 * @{
737 */
738
739 /**
740 * @brief MD5 HMAC step 1 completion and step 2 start in multi-buffer DMA mode.
741 * @note Step 1 consists in writing the inner hash function key in the Peripheral,
742 * step 2 consists in writing the message text.
743 * @note The API carries out the HMAC step 1 then starts step 2 with
744 * the first buffer entered to the Peripheral. DCAL bit is not automatically set after
745 * the message buffer feeding, allowing other messages DMA transfers to occur.
746 * @note Same key is used for the inner and the outer hash functions; pointer to key and
747 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
748 * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the
749 * HASH digest computation is corrupted.
750 * @param hhash HASH handle.
751 * @param pInBuffer pointer to the input buffer (message buffer).
752 * @param Size length of the input buffer in bytes.
753 * @retval HAL status
754 */
HAL_HMACEx_MD5_Step1_2_DMA(HASH_HandleTypeDef * hhash,const uint8_t * const pInBuffer,uint32_t Size)755 HAL_StatusTypeDef HAL_HMACEx_MD5_Step1_2_DMA(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size)
756 {
757 hhash->DigestCalculationDisable = SET;
758 return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_MD5);
759 }
760
761 /**
762 * @brief MD5 HMAC step 2 in multi-buffer DMA mode.
763 * @note Step 2 consists in writing the message text in the Peripheral.
764 * @note The API carries on the HMAC step 2, applied to the buffer entered as input
765 * parameter. DCAL bit is not automatically set after the message buffer feeding,
766 * allowing other messages DMA transfers to occur.
767 * @note Same key is used for the inner and the outer hash functions; pointer to key and
768 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
769 * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the
770 * HASH digest computation is corrupted.
771 * @param hhash HASH handle.
772 * @param pInBuffer pointer to the input buffer (message buffer).
773 * @param Size length of the input buffer in bytes.
774 * @retval HAL status
775 */
HAL_HMACEx_MD5_Step2_DMA(HASH_HandleTypeDef * hhash,const uint8_t * const pInBuffer,uint32_t Size)776 HAL_StatusTypeDef HAL_HMACEx_MD5_Step2_DMA(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size)
777 {
778 if (hhash->DigestCalculationDisable != SET)
779 {
780 return HAL_ERROR;
781 }
782 return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_MD5);
783 }
784
785 /**
786 * @brief MD5 HMAC step 2 wrap-up and step 3 completion in multi-buffer DMA mode.
787 * @note Step 2 consists in writing the message text in the Peripheral,
788 * step 3 consists in writing the outer hash function key.
789 * @note The API wraps up the HMAC step 2 in processing the buffer entered as input
790 * parameter (the input buffer must be the last one of the multi-buffer thread)
791 * then carries out HMAC step 3.
792 * @note Same key is used for the inner and the outer hash functions; pointer to key and
793 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
794 * @note Once the DMA transfers are finished (indicated by hhash->State set back
795 * to HAL_HASH_STATE_READY), HAL_HASHEx_SHA256_Finish() API must be called to retrieve
796 * the computed digest.
797 * @param hhash HASH handle.
798 * @param pInBuffer pointer to the input buffer (message buffer).
799 * @param Size length of the input buffer in bytes.
800 * @retval HAL status
801 */
HAL_HMACEx_MD5_Step2_3_DMA(HASH_HandleTypeDef * hhash,const uint8_t * const pInBuffer,uint32_t Size)802 HAL_StatusTypeDef HAL_HMACEx_MD5_Step2_3_DMA(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size)
803 {
804 hhash->DigestCalculationDisable = RESET;
805 return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_MD5);
806 }
807
808
809 /**
810 * @brief SHA1 HMAC step 1 completion and step 2 start in multi-buffer DMA mode.
811 * @note Step 1 consists in writing the inner hash function key in the Peripheral,
812 * step 2 consists in writing the message text.
813 * @note The API carries out the HMAC step 1 then starts step 2 with
814 * the first buffer entered to the Peripheral. DCAL bit is not automatically set after
815 * the message buffer feeding, allowing other messages DMA transfers to occur.
816 * @note Same key is used for the inner and the outer hash functions; pointer to key and
817 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
818 * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the
819 * HASH digest computation is corrupted.
820 * @param hhash HASH handle.
821 * @param pInBuffer pointer to the input buffer (message buffer).
822 * @param Size length of the input buffer in bytes.
823 * @retval HAL status
824 */
HAL_HMACEx_SHA1_Step1_2_DMA(HASH_HandleTypeDef * hhash,const uint8_t * const pInBuffer,uint32_t Size)825 HAL_StatusTypeDef HAL_HMACEx_SHA1_Step1_2_DMA(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size)
826 {
827 hhash->DigestCalculationDisable = SET;
828 return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA1);
829 }
830
831 /**
832 * @brief SHA1 HMAC step 2 in multi-buffer DMA mode.
833 * @note Step 2 consists in writing the message text in the Peripheral.
834 * @note The API carries on the HMAC step 2, applied to the buffer entered as input
835 * parameter. DCAL bit is not automatically set after the message buffer feeding,
836 * allowing other messages DMA transfers to occur.
837 * @note Same key is used for the inner and the outer hash functions; pointer to key and
838 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
839 * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the
840 * HASH digest computation is corrupted.
841 * @param hhash HASH handle.
842 * @param pInBuffer pointer to the input buffer (message buffer).
843 * @param Size length of the input buffer in bytes.
844 * @retval HAL status
845 */
HAL_HMACEx_SHA1_Step2_DMA(HASH_HandleTypeDef * hhash,const uint8_t * const pInBuffer,uint32_t Size)846 HAL_StatusTypeDef HAL_HMACEx_SHA1_Step2_DMA(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size)
847 {
848 if (hhash->DigestCalculationDisable != SET)
849 {
850 return HAL_ERROR;
851 }
852 return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA1);
853 }
854
855 /**
856 * @brief SHA1 HMAC step 2 wrap-up and step 3 completion in multi-buffer DMA mode.
857 * @note Step 2 consists in writing the message text in the Peripheral,
858 * step 3 consists in writing the outer hash function key.
859 * @note The API wraps up the HMAC step 2 in processing the buffer entered as input
860 * parameter (the input buffer must be the last one of the multi-buffer thread)
861 * then carries out HMAC step 3.
862 * @note Same key is used for the inner and the outer hash functions; pointer to key and
863 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
864 * @note Once the DMA transfers are finished (indicated by hhash->State set back
865 * to HAL_HASH_STATE_READY), HAL_HASHEx_SHA256_Finish() API must be called to retrieve
866 * the computed digest.
867 * @param hhash HASH handle.
868 * @param pInBuffer pointer to the input buffer (message buffer).
869 * @param Size length of the input buffer in bytes.
870 * @retval HAL status
871 */
HAL_HMACEx_SHA1_Step2_3_DMA(HASH_HandleTypeDef * hhash,const uint8_t * const pInBuffer,uint32_t Size)872 HAL_StatusTypeDef HAL_HMACEx_SHA1_Step2_3_DMA(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size)
873 {
874 hhash->DigestCalculationDisable = RESET;
875 return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA1);
876 }
877
878 /**
879 * @brief SHA224 HMAC step 1 completion and step 2 start in multi-buffer DMA mode.
880 * @note Step 1 consists in writing the inner hash function key in the Peripheral,
881 * step 2 consists in writing the message text.
882 * @note The API carries out the HMAC step 1 then starts step 2 with
883 * the first buffer entered to the Peripheral. DCAL bit is not automatically set after
884 * the message buffer feeding, allowing other messages DMA transfers to occur.
885 * @note Same key is used for the inner and the outer hash functions; pointer to key and
886 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
887 * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the
888 * HASH digest computation is corrupted.
889 * @param hhash HASH handle.
890 * @param pInBuffer pointer to the input buffer (message buffer).
891 * @param Size length of the input buffer in bytes.
892 * @retval HAL status
893 */
HAL_HMACEx_SHA224_Step1_2_DMA(HASH_HandleTypeDef * hhash,const uint8_t * const pInBuffer,uint32_t Size)894 HAL_StatusTypeDef HAL_HMACEx_SHA224_Step1_2_DMA(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer,
895 uint32_t Size)
896 {
897 hhash->DigestCalculationDisable = SET;
898 return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA224);
899 }
900
901 /**
902 * @brief SHA224 HMAC step 2 in multi-buffer DMA mode.
903 * @note Step 2 consists in writing the message text in the Peripheral.
904 * @note The API carries on the HMAC step 2, applied to the buffer entered as input
905 * parameter. DCAL bit is not automatically set after the message buffer feeding,
906 * allowing other messages DMA transfers to occur.
907 * @note Same key is used for the inner and the outer hash functions; pointer to key and
908 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
909 * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the
910 * HASH digest computation is corrupted.
911 * @param hhash HASH handle.
912 * @param pInBuffer pointer to the input buffer (message buffer).
913 * @param Size length of the input buffer in bytes.
914 * @retval HAL status
915 */
HAL_HMACEx_SHA224_Step2_DMA(HASH_HandleTypeDef * hhash,const uint8_t * const pInBuffer,uint32_t Size)916 HAL_StatusTypeDef HAL_HMACEx_SHA224_Step2_DMA(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size)
917 {
918 if (hhash->DigestCalculationDisable != SET)
919 {
920 return HAL_ERROR;
921 }
922 return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA224);
923 }
924
925 /**
926 * @brief SHA224 HMAC step 2 wrap-up and step 3 completion in multi-buffer DMA mode.
927 * @note Step 2 consists in writing the message text in the Peripheral,
928 * step 3 consists in writing the outer hash function key.
929 * @note The API wraps up the HMAC step 2 in processing the buffer entered as input
930 * parameter (the input buffer must be the last one of the multi-buffer thread)
931 * then carries out HMAC step 3.
932 * @note Same key is used for the inner and the outer hash functions; pointer to key and
933 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
934 * @note Once the DMA transfers are finished (indicated by hhash->State set back
935 * to HAL_HASH_STATE_READY), HAL_HASHEx_SHA256_Finish() API must be called to retrieve
936 * the computed digest.
937 * @param hhash HASH handle.
938 * @param pInBuffer pointer to the input buffer (message buffer).
939 * @param Size length of the input buffer in bytes.
940 * @retval HAL status
941 */
HAL_HMACEx_SHA224_Step2_3_DMA(HASH_HandleTypeDef * hhash,const uint8_t * const pInBuffer,uint32_t Size)942 HAL_StatusTypeDef HAL_HMACEx_SHA224_Step2_3_DMA(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer,
943 uint32_t Size)
944 {
945 hhash->DigestCalculationDisable = RESET;
946 return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA224);
947 }
948
949 /**
950 * @brief SHA256 HMAC step 1 completion and step 2 start in multi-buffer DMA mode.
951 * @note Step 1 consists in writing the inner hash function key in the Peripheral,
952 * step 2 consists in writing the message text.
953 * @note The API carries out the HMAC step 1 then starts step 2 with
954 * the first buffer entered to the Peripheral. DCAL bit is not automatically set after
955 * the message buffer feeding, allowing other messages DMA transfers to occur.
956 * @note Same key is used for the inner and the outer hash functions; pointer to key and
957 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
958 * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the
959 * HASH digest computation is corrupted.
960 * @param hhash HASH handle.
961 * @param pInBuffer pointer to the input buffer (message buffer).
962 * @param Size length of the input buffer in bytes.
963 * @retval HAL status
964 */
HAL_HMACEx_SHA256_Step1_2_DMA(HASH_HandleTypeDef * hhash,const uint8_t * const pInBuffer,uint32_t Size)965 HAL_StatusTypeDef HAL_HMACEx_SHA256_Step1_2_DMA(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer,
966 uint32_t Size)
967 {
968 hhash->DigestCalculationDisable = SET;
969 return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA256);
970 }
971
972 /**
973 * @brief SHA256 HMAC step 2 in multi-buffer DMA mode.
974 * @note Step 2 consists in writing the message text in the Peripheral.
975 * @note The API carries on the HMAC step 2, applied to the buffer entered as input
976 * parameter. DCAL bit is not automatically set after the message buffer feeding,
977 * allowing other messages DMA transfers to occur.
978 * @note Same key is used for the inner and the outer hash functions; pointer to key and
979 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
980 * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the
981 * HASH digest computation is corrupted.
982 * @param hhash HASH handle.
983 * @param pInBuffer pointer to the input buffer (message buffer).
984 * @param Size length of the input buffer in bytes.
985 * @retval HAL status
986 */
HAL_HMACEx_SHA256_Step2_DMA(HASH_HandleTypeDef * hhash,const uint8_t * const pInBuffer,uint32_t Size)987 HAL_StatusTypeDef HAL_HMACEx_SHA256_Step2_DMA(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size)
988 {
989 if (hhash->DigestCalculationDisable != SET)
990 {
991 return HAL_ERROR;
992 }
993 return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA256);
994 }
995
996 /**
997 * @brief SHA256 HMAC step 2 wrap-up and step 3 completion in multi-buffer DMA mode.
998 * @note Step 2 consists in writing the message text in the Peripheral,
999 * step 3 consists in writing the outer hash function key.
1000 * @note The API wraps up the HMAC step 2 in processing the buffer entered as input
1001 * parameter (the input buffer must be the last one of the multi-buffer thread)
1002 * then carries out HMAC step 3.
1003 * @note Same key is used for the inner and the outer hash functions; pointer to key and
1004 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
1005 * @note Once the DMA transfers are finished (indicated by hhash->State set back
1006 * to HAL_HASH_STATE_READY), HAL_HASHEx_SHA256_Finish() API must be called to retrieve
1007 * the computed digest.
1008 * @param hhash HASH handle.
1009 * @param pInBuffer pointer to the input buffer (message buffer).
1010 * @param Size length of the input buffer in bytes.
1011 * @retval HAL status
1012 */
HAL_HMACEx_SHA256_Step2_3_DMA(HASH_HandleTypeDef * hhash,const uint8_t * const pInBuffer,uint32_t Size)1013 HAL_StatusTypeDef HAL_HMACEx_SHA256_Step2_3_DMA(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer,
1014 uint32_t Size)
1015 {
1016 hhash->DigestCalculationDisable = RESET;
1017 return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA256);
1018 }
1019
1020 /**
1021 * @}
1022 */
1023
1024
1025 /**
1026 * @}
1027 */
1028 #endif /* HAL_HASH_MODULE_ENABLED */
1029
1030 /**
1031 * @}
1032 */
1033 #endif /* HASH*/
1034 /**
1035 * @}
1036 */
1037
1038