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