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