You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

1031 lines
47 KiB

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