stm32l4xx_hal_hash_ex.c 44 KB

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