训练营PLSR题目
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

1041 rinda
47 KiB

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