Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 

1038 строки
48 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, const uint8_t *const 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, const uint8_t *const 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, const uint8_t *const 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, const uint8_t *const 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, const uint8_t *const 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, const uint8_t *const 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, const uint8_t *const 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, const uint8_t *const 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, const uint8_t *const pInBuffer,
  299. uint32_t Size,
  300. uint8_t *pOutBuffer)
  301. {
  302. return HASH_Start_IT(hhash, pInBuffer, Size, pOutBuffer, HASH_ALGOSELECTION_SHA224);
  303. }
  304. /**
  305. * @brief Initialize the HASH peripheral in SHA256 mode, next process pInBuffer then
  306. * read the computed digest in interruption mode.
  307. * @note Digest is available in pOutBuffer.
  308. * @param hhash HASH handle.
  309. * @param pInBuffer pointer to the input buffer (buffer to be hashed).
  310. * @param Size length of the input buffer in bytes.
  311. * @param pOutBuffer pointer to the computed digest. Digest size is 32 bytes.
  312. * @retval HAL status
  313. */
  314. HAL_StatusTypeDef HAL_HASHEx_SHA256_Start_IT(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size,
  315. uint8_t *pOutBuffer)
  316. {
  317. return HASH_Start_IT(hhash, pInBuffer, Size, pOutBuffer, HASH_ALGOSELECTION_SHA256);
  318. }
  319. /**
  320. * @brief If not already done, initialize the HASH peripheral in SHA256 mode then
  321. * processes pInBuffer in interruption mode.
  322. * @note Consecutive calls to HAL_HASHEx_SHA256_Accmlt_IT() can be used to feed
  323. * several input buffers back-to-back to the Peripheral that will yield a single
  324. * HASH signature once all buffers have been entered. Wrap-up of input
  325. * buffers feeding and retrieval of digest is done by a call to
  326. * HAL_HASHEx_SHA256_Accmlt_End_IT().
  327. * @note Field hhash->Phase of HASH handle is tested to check whether or not
  328. * the Peripheral has already been initialized.
  329. * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the
  330. * HASH digest computation is corrupted. Only HAL_HASHEx_SHA256_Accmlt_End_IT() is able
  331. * to manage the ending buffer with a length in bytes not a multiple of 4.
  332. * @param hhash HASH handle.
  333. * @param pInBuffer pointer to the input buffer (buffer to be hashed).
  334. * @param Size length of the input buffer in bytes, must be a multiple of 4.
  335. * @retval HAL status
  336. */
  337. HAL_StatusTypeDef HAL_HASHEx_SHA256_Accmlt_IT(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size)
  338. {
  339. return HASH_Accumulate_IT(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA256);
  340. }
  341. /**
  342. * @brief End computation of a single HASH signature after several calls to HAL_HASHEx_SHA256_Accmlt_IT() API.
  343. * @note Digest is available in pOutBuffer.
  344. * @param hhash HASH handle.
  345. * @param pInBuffer pointer to the input buffer (buffer to be hashed).
  346. * @param Size length of the input buffer in bytes.
  347. * @param pOutBuffer pointer to the computed digest. Digest size is 32 bytes.
  348. * @retval HAL status
  349. */
  350. HAL_StatusTypeDef HAL_HASHEx_SHA256_Accmlt_End_IT(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer,
  351. uint32_t Size,
  352. uint8_t *pOutBuffer)
  353. {
  354. return HASH_Start_IT(hhash, pInBuffer, Size, pOutBuffer, HASH_ALGOSELECTION_SHA256);
  355. }
  356. /**
  357. * @}
  358. */
  359. /** @defgroup HASHEx_Exported_Functions_Group3 HASH extended processing functions in DMA mode
  360. * @brief HASH extended processing functions using DMA mode.
  361. *
  362. @verbatim
  363. ===============================================================================
  364. ##### DMA mode HASH extended processing functions #####
  365. ===============================================================================
  366. [..] This section provides functions allowing to calculate in DMA mode
  367. the hash value using one of the following algorithms:
  368. (+) SHA224
  369. (++) HAL_HASHEx_SHA224_Start_DMA()
  370. (++) HAL_HASHEx_SHA224_Finish()
  371. (+) SHA256
  372. (++) HAL_HASHEx_SHA256_Start_DMA()
  373. (++) HAL_HASHEx_SHA256_Finish()
  374. [..] When resorting to DMA mode to enter the data in the Peripheral, user must resort
  375. to HAL_HASHEx_xxx_Start_DMA() then read the resulting digest with
  376. HAL_HASHEx_xxx_Finish().
  377. [..] In case of multi-buffer HASH processing, MDMAT bit must first be set before
  378. the successive calls to HAL_HASHEx_xxx_Start_DMA(). Then, MDMAT bit needs to be
  379. reset before the last call to HAL_HASHEx_xxx_Start_DMA(). Digest is finally
  380. retrieved thanks to HAL_HASHEx_xxx_Finish().
  381. @endverbatim
  382. * @{
  383. */
  384. /**
  385. * @brief Initialize the HASH peripheral in SHA224 mode then initiate a DMA transfer
  386. * to feed the input buffer to the Peripheral.
  387. * @note Once the DMA transfer is finished, HAL_HASHEx_SHA224_Finish() API must
  388. * be called to retrieve the computed digest.
  389. * @param hhash HASH handle.
  390. * @param pInBuffer pointer to the input buffer (buffer to be hashed).
  391. * @param Size length of the input buffer in bytes.
  392. * @retval HAL status
  393. */
  394. HAL_StatusTypeDef HAL_HASHEx_SHA224_Start_DMA(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size)
  395. {
  396. return HASH_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA224);
  397. }
  398. /**
  399. * @brief Return the computed digest in SHA224 mode.
  400. * @note The API waits for DCIS to be set then reads the computed digest.
  401. * @note HAL_HASHEx_SHA224_Finish() can be used as well to retrieve the digest in
  402. * HMAC SHA224 mode.
  403. * @param hhash HASH handle.
  404. * @param pOutBuffer pointer to the computed digest. Digest size is 28 bytes.
  405. * @param Timeout Timeout value.
  406. * @retval HAL status
  407. */
  408. HAL_StatusTypeDef HAL_HASHEx_SHA224_Finish(HASH_HandleTypeDef *hhash, uint8_t *pOutBuffer, uint32_t Timeout)
  409. {
  410. return HASH_Finish(hhash, pOutBuffer, Timeout);
  411. }
  412. /**
  413. * @brief Initialize the HASH peripheral in SHA256 mode then initiate a DMA transfer
  414. * to feed the input buffer to the Peripheral.
  415. * @note Once the DMA transfer is finished, HAL_HASHEx_SHA256_Finish() API must
  416. * be called to retrieve the computed digest.
  417. * @param hhash HASH handle.
  418. * @param pInBuffer pointer to the input buffer (buffer to be hashed).
  419. * @param Size length of the input buffer in bytes.
  420. * @retval HAL status
  421. */
  422. HAL_StatusTypeDef HAL_HASHEx_SHA256_Start_DMA(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size)
  423. {
  424. return HASH_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA256);
  425. }
  426. /**
  427. * @brief Return the computed digest in SHA256 mode.
  428. * @note The API waits for DCIS to be set then reads the computed digest.
  429. * @note HAL_HASHEx_SHA256_Finish() can be used as well to retrieve the digest in
  430. * HMAC SHA256 mode.
  431. * @param hhash HASH handle.
  432. * @param pOutBuffer pointer to the computed digest. Digest size is 32 bytes.
  433. * @param Timeout Timeout value.
  434. * @retval HAL status
  435. */
  436. HAL_StatusTypeDef HAL_HASHEx_SHA256_Finish(HASH_HandleTypeDef *hhash, uint8_t *pOutBuffer, uint32_t Timeout)
  437. {
  438. return HASH_Finish(hhash, pOutBuffer, Timeout);
  439. }
  440. /**
  441. * @}
  442. */
  443. /** @defgroup HASHEx_Exported_Functions_Group4 HMAC extended processing functions in polling mode
  444. * @brief HMAC extended processing functions using polling mode.
  445. *
  446. @verbatim
  447. ===============================================================================
  448. ##### Polling mode HMAC extended processing functions #####
  449. ===============================================================================
  450. [..] This section provides functions allowing to calculate in polling mode
  451. the HMAC value using one of the following algorithms:
  452. (+) SHA224
  453. (++) HAL_HMACEx_SHA224_Start()
  454. (+) SHA256
  455. (++) HAL_HMACEx_SHA256_Start()
  456. @endverbatim
  457. * @{
  458. */
  459. /**
  460. * @brief Initialize the HASH peripheral in HMAC SHA224 mode, next process pInBuffer then
  461. * read the computed digest.
  462. * @note Digest is available in pOutBuffer.
  463. * @note Same key is used for the inner and the outer hash functions; pointer to key and
  464. * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
  465. * @param hhash HASH handle.
  466. * @param pInBuffer pointer to the input buffer (buffer to be hashed).
  467. * @param Size length of the input buffer in bytes.
  468. * @param pOutBuffer pointer to the computed digest. Digest size is 28 bytes.
  469. * @param Timeout Timeout value.
  470. * @retval HAL status
  471. */
  472. HAL_StatusTypeDef HAL_HMACEx_SHA224_Start(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size,
  473. uint8_t *pOutBuffer, uint32_t Timeout)
  474. {
  475. return HMAC_Start(hhash, pInBuffer, Size, pOutBuffer, Timeout, HASH_ALGOSELECTION_SHA224);
  476. }
  477. /**
  478. * @brief Initialize the HASH peripheral in HMAC SHA256 mode, next process pInBuffer then
  479. * read the computed digest.
  480. * @note Digest is available in pOutBuffer.
  481. * @note Same key is used for the inner and the outer hash functions; pointer to key and
  482. * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
  483. * @param hhash HASH handle.
  484. * @param pInBuffer pointer to the input buffer (buffer to be hashed).
  485. * @param Size length of the input buffer in bytes.
  486. * @param pOutBuffer pointer to the computed digest. Digest size is 32 bytes.
  487. * @param Timeout Timeout value.
  488. * @retval HAL status
  489. */
  490. HAL_StatusTypeDef HAL_HMACEx_SHA256_Start(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size,
  491. uint8_t *pOutBuffer, uint32_t Timeout)
  492. {
  493. return HMAC_Start(hhash, pInBuffer, Size, pOutBuffer, Timeout, HASH_ALGOSELECTION_SHA256);
  494. }
  495. /**
  496. * @}
  497. */
  498. /** @defgroup HASHEx_Exported_Functions_Group5 HMAC extended processing functions in interrupt mode
  499. * @brief HMAC extended processing functions using interruption mode.
  500. *
  501. @verbatim
  502. ===============================================================================
  503. ##### Interrupt mode HMAC extended processing functions #####
  504. ===============================================================================
  505. [..] This section provides functions allowing to calculate in interrupt mode
  506. the HMAC value using one of the following algorithms:
  507. (+) SHA224
  508. (++) HAL_HMACEx_SHA224_Start_IT()
  509. (+) SHA256
  510. (++) HAL_HMACEx_SHA256_Start_IT()
  511. @endverbatim
  512. * @{
  513. */
  514. /**
  515. * @brief Initialize the HASH peripheral in HMAC SHA224 mode, next process pInBuffer then
  516. * read the computed digest in interrupt mode.
  517. * @note Digest is available in pOutBuffer.
  518. * @note Same key is used for the inner and the outer hash functions; pointer to key and
  519. * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
  520. * @param hhash HASH handle.
  521. * @param pInBuffer pointer to the input buffer (buffer to be hashed).
  522. * @param Size length of the input buffer in bytes.
  523. * @param pOutBuffer pointer to the computed digest. Digest size is 28 bytes.
  524. * @retval HAL status
  525. */
  526. HAL_StatusTypeDef HAL_HMACEx_SHA224_Start_IT(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size,
  527. uint8_t *pOutBuffer)
  528. {
  529. return HMAC_Start_IT(hhash, pInBuffer, Size, pOutBuffer, HASH_ALGOSELECTION_SHA224);
  530. }
  531. /**
  532. * @brief Initialize the HASH peripheral in HMAC SHA256 mode, next process pInBuffer then
  533. * read the computed digest in interrupt mode.
  534. * @note Digest is available in pOutBuffer.
  535. * @note Same key is used for the inner and the outer hash functions; pointer to key and
  536. * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
  537. * @param hhash HASH handle.
  538. * @param pInBuffer pointer to the input buffer (buffer to be hashed).
  539. * @param Size length of the input buffer in bytes.
  540. * @param pOutBuffer pointer to the computed digest. Digest size is 32 bytes.
  541. * @retval HAL status
  542. */
  543. HAL_StatusTypeDef HAL_HMACEx_SHA256_Start_IT(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size,
  544. uint8_t *pOutBuffer)
  545. {
  546. return HMAC_Start_IT(hhash, pInBuffer, Size, pOutBuffer, HASH_ALGOSELECTION_SHA256);
  547. }
  548. /**
  549. * @}
  550. */
  551. /** @defgroup HASHEx_Exported_Functions_Group6 HMAC extended processing functions in DMA mode
  552. * @brief HMAC extended processing functions using DMA mode.
  553. *
  554. @verbatim
  555. ===============================================================================
  556. ##### DMA mode HMAC extended processing functions #####
  557. ===============================================================================
  558. [..] This section provides functions allowing to calculate in DMA mode
  559. the HMAC value using one of the following algorithms:
  560. (+) SHA224
  561. (++) HAL_HMACEx_SHA224_Start_DMA()
  562. (+) SHA256
  563. (++) HAL_HMACEx_SHA256_Start_DMA()
  564. [..] When resorting to DMA mode to enter the data in the Peripheral for HMAC processing,
  565. user must resort to HAL_HMACEx_xxx_Start_DMA() then read the resulting digest
  566. with HAL_HASHEx_xxx_Finish().
  567. @endverbatim
  568. * @{
  569. */
  570. /**
  571. * @brief Initialize the HASH peripheral in HMAC SHA224 mode then initiate the required
  572. * DMA transfers to feed the key and the input buffer to the Peripheral.
  573. * @note Once the DMA transfers are finished (indicated by hhash->State set back
  574. * to HAL_HASH_STATE_READY), HAL_HASHEx_SHA224_Finish() API must be called to retrieve
  575. * the computed digest.
  576. * @note Same key is used for the inner and the outer hash functions; pointer to key and
  577. * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
  578. * @note If MDMAT bit is set before calling this function (multi-buffer
  579. * HASH processing case), the input buffer size (in bytes) must be
  580. * a multiple of 4 otherwise, the HASH digest computation is corrupted.
  581. * For the processing of the last buffer of the thread, MDMAT bit must
  582. * be reset and the buffer length (in bytes) doesn't have to be a
  583. * multiple of 4.
  584. * @param hhash HASH handle.
  585. * @param pInBuffer pointer to the input buffer (buffer to be hashed).
  586. * @param Size length of the input buffer in bytes.
  587. * @retval HAL status
  588. */
  589. HAL_StatusTypeDef HAL_HMACEx_SHA224_Start_DMA(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size)
  590. {
  591. return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA224);
  592. }
  593. /**
  594. * @brief Initialize the HASH peripheral in HMAC SHA224 mode then initiate the required
  595. * DMA transfers to feed the key and the input buffer to the Peripheral.
  596. * @note Once the DMA transfers are finished (indicated by hhash->State set back
  597. * to HAL_HASH_STATE_READY), HAL_HASHEx_SHA256_Finish() API must be called to retrieve
  598. * the computed digest.
  599. * @note Same key is used for the inner and the outer hash functions; pointer to key and
  600. * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
  601. * @note If MDMAT bit is set before calling this function (multi-buffer
  602. * HASH processing case), the input buffer size (in bytes) must be
  603. * a multiple of 4 otherwise, the HASH digest computation is corrupted.
  604. * For the processing of the last buffer of the thread, MDMAT bit must
  605. * be reset and the buffer length (in bytes) doesn't have to be a
  606. * multiple of 4.
  607. * @param hhash HASH handle.
  608. * @param pInBuffer pointer to the input buffer (buffer to be hashed).
  609. * @param Size length of the input buffer in bytes.
  610. * @retval HAL status
  611. */
  612. HAL_StatusTypeDef HAL_HMACEx_SHA256_Start_DMA(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size)
  613. {
  614. return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA256);
  615. }
  616. /**
  617. * @}
  618. */
  619. /** @defgroup HASHEx_Exported_Functions_Group7 Multi-buffer HMAC extended processing functions in DMA mode
  620. * @brief HMAC extended processing functions in multi-buffer DMA mode.
  621. *
  622. @verbatim
  623. ===============================================================================
  624. ##### Multi-buffer DMA mode HMAC extended processing functions #####
  625. ===============================================================================
  626. [..] This section provides functions to manage HMAC multi-buffer
  627. DMA-based processing for MD5, SHA1, SHA224 and SHA256 algorithms.
  628. (+) MD5
  629. (++) HAL_HMACEx_MD5_Step1_2_DMA()
  630. (++) HAL_HMACEx_MD5_Step2_DMA()
  631. (++) HAL_HMACEx_MD5_Step2_3_DMA()
  632. (+) SHA1
  633. (++) HAL_HMACEx_SHA1_Step1_2_DMA()
  634. (++) HAL_HMACEx_SHA1_Step2_DMA()
  635. (++) HAL_HMACEx_SHA1_Step2_3_DMA()
  636. (+) SHA256
  637. (++) HAL_HMACEx_SHA224_Step1_2_DMA()
  638. (++) HAL_HMACEx_SHA224_Step2_DMA()
  639. (++) HAL_HMACEx_SHA224_Step2_3_DMA()
  640. (+) SHA256
  641. (++) HAL_HMACEx_SHA256_Step1_2_DMA()
  642. (++) HAL_HMACEx_SHA256_Step2_DMA()
  643. (++) HAL_HMACEx_SHA256_Step2_3_DMA()
  644. [..] User must first start-up the multi-buffer DMA-based HMAC computation in
  645. calling HAL_HMACEx_xxx_Step1_2_DMA(). This carries out HMAC step 1 and
  646. intiates step 2 with the first input buffer.
  647. [..] The following buffers are next fed to the Peripheral with a call to the API
  648. HAL_HMACEx_xxx_Step2_DMA(). There may be several consecutive calls
  649. to this API.
  650. [..] Multi-buffer DMA-based HMAC computation is wrapped up by a call to
  651. HAL_HMACEx_xxx_Step2_3_DMA(). This finishes step 2 in feeding the last input
  652. buffer to the Peripheral then carries out step 3.
  653. [..] Digest is retrieved by a call to HAL_HASH_xxx_Finish() for MD-5 or
  654. SHA-1, to HAL_HASHEx_xxx_Finish() for SHA-224 or SHA-256.
  655. [..] If only two buffers need to be consecutively processed, a call to
  656. HAL_HMACEx_xxx_Step1_2_DMA() followed by a call to HAL_HMACEx_xxx_Step2_3_DMA()
  657. is sufficient.
  658. @endverbatim
  659. * @{
  660. */
  661. /**
  662. * @brief MD5 HMAC step 1 completion and step 2 start in multi-buffer DMA mode.
  663. * @note Step 1 consists in writing the inner hash function key in the Peripheral,
  664. * step 2 consists in writing the message text.
  665. * @note The API carries out the HMAC step 1 then starts step 2 with
  666. * the first buffer entered to the Peripheral. DCAL bit is not automatically set after
  667. * the message buffer feeding, allowing other messages DMA transfers to occur.
  668. * @note Same key is used for the inner and the outer hash functions; pointer to key and
  669. * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
  670. * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the
  671. * HASH digest computation is corrupted.
  672. * @param hhash HASH handle.
  673. * @param pInBuffer pointer to the input buffer (message buffer).
  674. * @param Size length of the input buffer in bytes.
  675. * @retval HAL status
  676. */
  677. HAL_StatusTypeDef HAL_HMACEx_MD5_Step1_2_DMA(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size)
  678. {
  679. hhash->DigestCalculationDisable = SET;
  680. return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_MD5);
  681. }
  682. /**
  683. * @brief MD5 HMAC step 2 in multi-buffer DMA mode.
  684. * @note Step 2 consists in writing the message text in the Peripheral.
  685. * @note The API carries on the HMAC step 2, applied to the buffer entered as input
  686. * parameter. DCAL bit is not automatically set after the message buffer feeding,
  687. * allowing other messages DMA transfers to occur.
  688. * @note Same key is used for the inner and the outer hash functions; pointer to key and
  689. * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
  690. * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the
  691. * HASH digest computation is corrupted.
  692. * @param hhash HASH handle.
  693. * @param pInBuffer pointer to the input buffer (message buffer).
  694. * @param Size length of the input buffer in bytes.
  695. * @retval HAL status
  696. */
  697. HAL_StatusTypeDef HAL_HMACEx_MD5_Step2_DMA(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size)
  698. {
  699. if (hhash->DigestCalculationDisable != SET)
  700. {
  701. return HAL_ERROR;
  702. }
  703. return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_MD5);
  704. }
  705. /**
  706. * @brief MD5 HMAC step 2 wrap-up and step 3 completion in multi-buffer DMA mode.
  707. * @note Step 2 consists in writing the message text in the Peripheral,
  708. * step 3 consists in writing the outer hash function key.
  709. * @note The API wraps up the HMAC step 2 in processing the buffer entered as input
  710. * parameter (the input buffer must be the last one of the multi-buffer thread)
  711. * then carries out HMAC step 3.
  712. * @note Same key is used for the inner and the outer hash functions; pointer to key and
  713. * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
  714. * @note Once the DMA transfers are finished (indicated by hhash->State set back
  715. * to HAL_HASH_STATE_READY), HAL_HASHEx_SHA256_Finish() API must be called to retrieve
  716. * the computed digest.
  717. * @param hhash HASH handle.
  718. * @param pInBuffer pointer to the input buffer (message buffer).
  719. * @param Size length of the input buffer in bytes.
  720. * @retval HAL status
  721. */
  722. HAL_StatusTypeDef HAL_HMACEx_MD5_Step2_3_DMA(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size)
  723. {
  724. hhash->DigestCalculationDisable = RESET;
  725. return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_MD5);
  726. }
  727. /**
  728. * @brief SHA1 HMAC step 1 completion and step 2 start in multi-buffer DMA mode.
  729. * @note Step 1 consists in writing the inner hash function key in the Peripheral,
  730. * step 2 consists in writing the message text.
  731. * @note The API carries out the HMAC step 1 then starts step 2 with
  732. * the first buffer entered to the Peripheral. DCAL bit is not automatically set after
  733. * the message buffer feeding, allowing other messages DMA transfers to occur.
  734. * @note Same key is used for the inner and the outer hash functions; pointer to key and
  735. * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
  736. * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the
  737. * HASH digest computation is corrupted.
  738. * @param hhash HASH handle.
  739. * @param pInBuffer pointer to the input buffer (message buffer).
  740. * @param Size length of the input buffer in bytes.
  741. * @retval HAL status
  742. */
  743. HAL_StatusTypeDef HAL_HMACEx_SHA1_Step1_2_DMA(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size)
  744. {
  745. hhash->DigestCalculationDisable = SET;
  746. return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA1);
  747. }
  748. /**
  749. * @brief SHA1 HMAC step 2 in multi-buffer DMA mode.
  750. * @note Step 2 consists in writing the message text in the Peripheral.
  751. * @note The API carries on the HMAC step 2, applied to the buffer entered as input
  752. * parameter. DCAL bit is not automatically set after the message buffer feeding,
  753. * allowing other messages DMA transfers to occur.
  754. * @note Same key is used for the inner and the outer hash functions; pointer to key and
  755. * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
  756. * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the
  757. * HASH digest computation is corrupted.
  758. * @param hhash HASH handle.
  759. * @param pInBuffer pointer to the input buffer (message buffer).
  760. * @param Size length of the input buffer in bytes.
  761. * @retval HAL status
  762. */
  763. HAL_StatusTypeDef HAL_HMACEx_SHA1_Step2_DMA(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size)
  764. {
  765. if (hhash->DigestCalculationDisable != SET)
  766. {
  767. return HAL_ERROR;
  768. }
  769. return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA1);
  770. }
  771. /**
  772. * @brief SHA1 HMAC step 2 wrap-up and step 3 completion in multi-buffer DMA mode.
  773. * @note Step 2 consists in writing the message text in the Peripheral,
  774. * step 3 consists in writing the outer hash function key.
  775. * @note The API wraps up the HMAC step 2 in processing the buffer entered as input
  776. * parameter (the input buffer must be the last one of the multi-buffer thread)
  777. * then carries out HMAC step 3.
  778. * @note Same key is used for the inner and the outer hash functions; pointer to key and
  779. * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
  780. * @note Once the DMA transfers are finished (indicated by hhash->State set back
  781. * to HAL_HASH_STATE_READY), HAL_HASHEx_SHA256_Finish() API must be called to retrieve
  782. * the computed digest.
  783. * @param hhash HASH handle.
  784. * @param pInBuffer pointer to the input buffer (message buffer).
  785. * @param Size length of the input buffer in bytes.
  786. * @retval HAL status
  787. */
  788. HAL_StatusTypeDef HAL_HMACEx_SHA1_Step2_3_DMA(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size)
  789. {
  790. hhash->DigestCalculationDisable = RESET;
  791. return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA1);
  792. }
  793. /**
  794. * @brief SHA224 HMAC step 1 completion and step 2 start in multi-buffer DMA mode.
  795. * @note Step 1 consists in writing the inner hash function key in the Peripheral,
  796. * step 2 consists in writing the message text.
  797. * @note The API carries out the HMAC step 1 then starts step 2 with
  798. * the first buffer entered to the Peripheral. DCAL bit is not automatically set after
  799. * the message buffer feeding, allowing other messages DMA transfers to occur.
  800. * @note Same key is used for the inner and the outer hash functions; pointer to key and
  801. * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
  802. * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the
  803. * HASH digest computation is corrupted.
  804. * @param hhash HASH handle.
  805. * @param pInBuffer pointer to the input buffer (message buffer).
  806. * @param Size length of the input buffer in bytes.
  807. * @retval HAL status
  808. */
  809. HAL_StatusTypeDef HAL_HMACEx_SHA224_Step1_2_DMA(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer,
  810. uint32_t Size)
  811. {
  812. hhash->DigestCalculationDisable = SET;
  813. return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA224);
  814. }
  815. /**
  816. * @brief SHA224 HMAC step 2 in multi-buffer DMA mode.
  817. * @note Step 2 consists in writing the message text in the Peripheral.
  818. * @note The API carries on the HMAC step 2, applied to the buffer entered as input
  819. * parameter. DCAL bit is not automatically set after the message buffer feeding,
  820. * allowing other messages DMA transfers to occur.
  821. * @note Same key is used for the inner and the outer hash functions; pointer to key and
  822. * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
  823. * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the
  824. * HASH digest computation is corrupted.
  825. * @param hhash HASH handle.
  826. * @param pInBuffer pointer to the input buffer (message buffer).
  827. * @param Size length of the input buffer in bytes.
  828. * @retval HAL status
  829. */
  830. HAL_StatusTypeDef HAL_HMACEx_SHA224_Step2_DMA(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size)
  831. {
  832. if (hhash->DigestCalculationDisable != SET)
  833. {
  834. return HAL_ERROR;
  835. }
  836. return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA224);
  837. }
  838. /**
  839. * @brief SHA224 HMAC step 2 wrap-up and step 3 completion in multi-buffer DMA mode.
  840. * @note Step 2 consists in writing the message text in the Peripheral,
  841. * step 3 consists in writing the outer hash function key.
  842. * @note The API wraps up the HMAC step 2 in processing the buffer entered as input
  843. * parameter (the input buffer must be the last one of the multi-buffer thread)
  844. * then carries out HMAC step 3.
  845. * @note Same key is used for the inner and the outer hash functions; pointer to key and
  846. * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
  847. * @note Once the DMA transfers are finished (indicated by hhash->State set back
  848. * to HAL_HASH_STATE_READY), HAL_HASHEx_SHA256_Finish() API must be called to retrieve
  849. * the computed digest.
  850. * @param hhash HASH handle.
  851. * @param pInBuffer pointer to the input buffer (message buffer).
  852. * @param Size length of the input buffer in bytes.
  853. * @retval HAL status
  854. */
  855. HAL_StatusTypeDef HAL_HMACEx_SHA224_Step2_3_DMA(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer,
  856. uint32_t Size)
  857. {
  858. hhash->DigestCalculationDisable = RESET;
  859. return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA224);
  860. }
  861. /**
  862. * @brief SHA256 HMAC step 1 completion and step 2 start in multi-buffer DMA mode.
  863. * @note Step 1 consists in writing the inner hash function key in the Peripheral,
  864. * step 2 consists in writing the message text.
  865. * @note The API carries out the HMAC step 1 then starts step 2 with
  866. * the first buffer entered to the Peripheral. DCAL bit is not automatically set after
  867. * the message buffer feeding, allowing other messages DMA transfers to occur.
  868. * @note Same key is used for the inner and the outer hash functions; pointer to key and
  869. * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
  870. * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the
  871. * HASH digest computation is corrupted.
  872. * @param hhash HASH handle.
  873. * @param pInBuffer pointer to the input buffer (message buffer).
  874. * @param Size length of the input buffer in bytes.
  875. * @retval HAL status
  876. */
  877. HAL_StatusTypeDef HAL_HMACEx_SHA256_Step1_2_DMA(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer,
  878. uint32_t Size)
  879. {
  880. hhash->DigestCalculationDisable = SET;
  881. return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA256);
  882. }
  883. /**
  884. * @brief SHA256 HMAC step 2 in multi-buffer DMA mode.
  885. * @note Step 2 consists in writing the message text in the Peripheral.
  886. * @note The API carries on the HMAC step 2, applied to the buffer entered as input
  887. * parameter. DCAL bit is not automatically set after the message buffer feeding,
  888. * allowing other messages DMA transfers to occur.
  889. * @note Same key is used for the inner and the outer hash functions; pointer to key and
  890. * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
  891. * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the
  892. * HASH digest computation is corrupted.
  893. * @param hhash HASH handle.
  894. * @param pInBuffer pointer to the input buffer (message buffer).
  895. * @param Size length of the input buffer in bytes.
  896. * @retval HAL status
  897. */
  898. HAL_StatusTypeDef HAL_HMACEx_SHA256_Step2_DMA(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size)
  899. {
  900. if (hhash->DigestCalculationDisable != SET)
  901. {
  902. return HAL_ERROR;
  903. }
  904. return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA256);
  905. }
  906. /**
  907. * @brief SHA256 HMAC step 2 wrap-up and step 3 completion in multi-buffer DMA mode.
  908. * @note Step 2 consists in writing the message text in the Peripheral,
  909. * step 3 consists in writing the outer hash function key.
  910. * @note The API wraps up the HMAC step 2 in processing the buffer entered as input
  911. * parameter (the input buffer must be the last one of the multi-buffer thread)
  912. * then carries out HMAC step 3.
  913. * @note Same key is used for the inner and the outer hash functions; pointer to key and
  914. * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
  915. * @note Once the DMA transfers are finished (indicated by hhash->State set back
  916. * to HAL_HASH_STATE_READY), HAL_HASHEx_SHA256_Finish() API must be called to retrieve
  917. * the computed digest.
  918. * @param hhash HASH handle.
  919. * @param pInBuffer pointer to the input buffer (message buffer).
  920. * @param Size length of the input buffer in bytes.
  921. * @retval HAL status
  922. */
  923. HAL_StatusTypeDef HAL_HMACEx_SHA256_Step2_3_DMA(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer,
  924. uint32_t Size)
  925. {
  926. hhash->DigestCalculationDisable = RESET;
  927. return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA256);
  928. }
  929. /**
  930. * @}
  931. */
  932. #endif /* MDMA defined*/
  933. /**
  934. * @}
  935. */
  936. #endif /* HAL_HASH_MODULE_ENABLED */
  937. /**
  938. * @}
  939. */
  940. #endif /* HASH*/
  941. /**
  942. * @}
  943. */