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