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