![]() |
|
|||
File indexing completed on 2025-05-11 08:23:07
0001 /** 0002 ****************************************************************************** 0003 * @file stm32h7xx_hal_hash_ex.c 0004 * @author MCD Application Team 0005 * @brief Extended HASH HAL module driver. 0006 * This file provides firmware functions to manage the following 0007 * functionalities of the HASH peripheral for SHA-224 and SHA-256 0008 * algorithms: 0009 * + HASH or HMAC processing in polling mode 0010 * + HASH or HMAC processing in interrupt mode 0011 * + HASH or HMAC processing in DMA mode 0012 * Additionally, this file provides functions to manage HMAC 0013 * multi-buffer DMA-based processing for MD-5, SHA-1, SHA-224 0014 * and SHA-256. 0015 * 0016 * 0017 ****************************************************************************** 0018 * @attention 0019 * 0020 * Copyright (c) 2017 STMicroelectronics. 0021 * All rights reserved. 0022 * 0023 * This software is licensed under terms that can be found in the LICENSE file 0024 * in the root directory of this software component. 0025 * If no LICENSE file comes with this software, it is provided AS-IS. 0026 * 0027 ****************************************************************************** 0028 @verbatim 0029 =============================================================================== 0030 ##### HASH peripheral extended features ##### 0031 =============================================================================== 0032 [..] 0033 The SHA-224 and SHA-256 HASH and HMAC processing can be carried out exactly 0034 the same way as for SHA-1 or MD-5 algorithms. 0035 (#) Three modes are available. 0036 (##) Polling mode: processing APIs are blocking functions 0037 i.e. they process the data and wait till the digest computation is finished, 0038 e.g. HAL_HASHEx_xxx_Start() 0039 (##) Interrupt mode: processing APIs are not blocking functions 0040 i.e. they process the data under interrupt, 0041 e.g. HAL_HASHEx_xxx_Start_IT() 0042 (##) DMA mode: processing APIs are not blocking functions and the CPU is 0043 not used for data transfer i.e. the data transfer is ensured by DMA, 0044 e.g. HAL_HASHEx_xxx_Start_DMA(). Note that in DMA mode, a call to 0045 HAL_HASHEx_xxx_Finish() is then required to retrieve the digest. 0046 0047 (#)Multi-buffer processing is possible in polling, interrupt and DMA modes. 0048 (##) In polling mode, only multi-buffer HASH processing is possible. 0049 API HAL_HASHEx_xxx_Accumulate() must be called for each input buffer, except for the last one. 0050 User must resort to HAL_HASHEx_xxx_Accumulate_End() to enter the last one and retrieve as 0051 well the computed digest. 0052 0053 (##) In interrupt mode, API HAL_HASHEx_xxx_Accumulate_IT() must be called for each input buffer, 0054 except for the last one. 0055 User must resort to HAL_HASHEx_xxx_Accumulate_End_IT() to enter the last one and retrieve as 0056 well the computed digest. 0057 0058 (##) In DMA mode, multi-buffer HASH and HMAC processing are possible. 0059 0060 (+++) HASH processing: once initialization is done, MDMAT bit must be set through 0061 __HAL_HASH_SET_MDMAT() macro. 0062 From that point, each buffer can be fed to the Peripheral through HAL_HASHEx_xxx_Start_DMA() API. 0063 Before entering the last buffer, reset the MDMAT bit with __HAL_HASH_RESET_MDMAT() 0064 macro then wrap-up the HASH processing in feeding the last input buffer through the 0065 same API HAL_HASHEx_xxx_Start_DMA(). The digest can then be retrieved with a call to 0066 API HAL_HASHEx_xxx_Finish(). 0067 0068 (+++) HMAC processing (MD-5, SHA-1, SHA-224 and SHA-256 must all resort to 0069 extended functions): after initialization, the key and the first input buffer are entered 0070 in the Peripheral with the API HAL_HMACEx_xxx_Step1_2_DMA(). This carries out HMAC step 1 and 0071 starts step 2. 0072 The following buffers are next entered with the API HAL_HMACEx_xxx_Step2_DMA(). At this 0073 point, the HMAC processing is still carrying out step 2. 0074 Then, step 2 for the last input buffer and step 3 are carried out by a single call 0075 to HAL_HMACEx_xxx_Step2_3_DMA(). 0076 0077 The digest can finally be retrieved with a call to API HAL_HASH_xxx_Finish() for 0078 MD-5 and SHA-1, to HAL_HASHEx_xxx_Finish() for SHA-224 and SHA-256. 0079 0080 0081 @endverbatim 0082 ****************************************************************************** 0083 */ 0084 0085 /* Includes ------------------------------------------------------------------*/ 0086 #include "stm32h7xx_hal.h" 0087 0088 0089 0090 0091 /** @addtogroup STM32H7xx_HAL_Driver 0092 * @{ 0093 */ 0094 #if defined (HASH) 0095 0096 /** @defgroup HASHEx HASHEx 0097 * @ingroup RTEMSBSPsARMSTM32H7 0098 * @brief HASH HAL extended module driver. 0099 * @{ 0100 */ 0101 #ifdef HAL_HASH_MODULE_ENABLED 0102 /* Private typedef -----------------------------------------------------------*/ 0103 /* Private define ------------------------------------------------------------*/ 0104 /* Private functions ---------------------------------------------------------*/ 0105 0106 0107 /** @defgroup HASHEx_Exported_Functions HASH Extended Exported Functions 0108 * @ingroup RTEMSBSPsARMSTM32H7 0109 * @{ 0110 */ 0111 0112 /** @defgroup HASHEx_Exported_Functions_Group1 HASH extended processing functions in polling mode 0113 * @ingroup RTEMSBSPsARMSTM32H7 0114 * @brief HASH extended processing functions using polling mode. 0115 * 0116 @verbatim 0117 =============================================================================== 0118 ##### Polling mode HASH extended processing functions ##### 0119 =============================================================================== 0120 [..] This section provides functions allowing to calculate in polling mode 0121 the hash value using one of the following algorithms: 0122 (+) SHA224 0123 (++) HAL_HASHEx_SHA224_Start() 0124 (++) HAL_HASHEx_SHA224_Accmlt() 0125 (++) HAL_HASHEx_SHA224_Accmlt_End() 0126 (+) SHA256 0127 (++) HAL_HASHEx_SHA256_Start() 0128 (++) HAL_HASHEx_SHA256_Accmlt() 0129 (++) HAL_HASHEx_SHA256_Accmlt_End() 0130 0131 [..] For a single buffer to be hashed, user can resort to HAL_HASH_xxx_Start(). 0132 0133 [..] In case of multi-buffer HASH processing (a single digest is computed while 0134 several buffers are fed to the Peripheral), the user can resort to successive calls 0135 to HAL_HASHEx_xxx_Accumulate() and wrap-up the digest computation by a call 0136 to HAL_HASHEx_xxx_Accumulate_End(). 0137 0138 @endverbatim 0139 * @{ 0140 */ 0141 0142 0143 /** 0144 * @brief Initialize the HASH peripheral in SHA224 mode, next process pInBuffer then 0145 * read the computed digest. 0146 * @note Digest is available in pOutBuffer. 0147 * @param hhash HASH handle. 0148 * @param pInBuffer pointer to the input buffer (buffer to be hashed). 0149 * @param Size length of the input buffer in bytes. 0150 * @param pOutBuffer pointer to the computed digest. Digest size is 28 bytes. 0151 * @param Timeout Timeout value 0152 * @retval HAL status 0153 */ 0154 HAL_StatusTypeDef HAL_HASHEx_SHA224_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, 0155 uint8_t *pOutBuffer, uint32_t Timeout) 0156 { 0157 return HASH_Start(hhash, pInBuffer, Size, pOutBuffer, Timeout, HASH_ALGOSELECTION_SHA224); 0158 } 0159 0160 /** 0161 * @brief If not already done, initialize the HASH peripheral in SHA224 mode then 0162 * processes pInBuffer. 0163 * @note Consecutive calls to HAL_HASHEx_SHA224_Accmlt() can be used to feed 0164 * several input buffers back-to-back to the Peripheral that will yield a single 0165 * HASH signature once all buffers have been entered. Wrap-up of input 0166 * buffers feeding and retrieval of digest is done by a call to 0167 * HAL_HASHEx_SHA224_Accmlt_End(). 0168 * @note Field hhash->Phase of HASH handle is tested to check whether or not 0169 * the Peripheral has already been initialized. 0170 * @note Digest is not retrieved by this API, user must resort to HAL_HASHEx_SHA224_Accmlt_End() 0171 * to read it, feeding at the same time the last input buffer to the Peripheral. 0172 * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the 0173 * HASH digest computation is corrupted. Only HAL_HASHEx_SHA224_Accmlt_End() is able 0174 * to manage the ending buffer with a length in bytes not a multiple of 4. 0175 * @param hhash HASH handle. 0176 * @param pInBuffer pointer to the input buffer (buffer to be hashed). 0177 * @param Size length of the input buffer in bytes, must be a multiple of 4. 0178 * @retval HAL status 0179 */ 0180 HAL_StatusTypeDef HAL_HASHEx_SHA224_Accmlt(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) 0181 { 0182 return HASH_Accumulate(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA224); 0183 } 0184 0185 /** 0186 * @brief End computation of a single HASH signature after several calls to HAL_HASHEx_SHA224_Accmlt() API. 0187 * @note Digest is available in pOutBuffer. 0188 * @param hhash HASH handle. 0189 * @param pInBuffer pointer to the input buffer (buffer to be hashed). 0190 * @param Size length of the input buffer in bytes. 0191 * @param pOutBuffer pointer to the computed digest. Digest size is 28 bytes. 0192 * @param Timeout Timeout value 0193 * @retval HAL status 0194 */ 0195 HAL_StatusTypeDef HAL_HASHEx_SHA224_Accmlt_End(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, 0196 uint8_t *pOutBuffer, uint32_t Timeout) 0197 { 0198 return HASH_Start(hhash, pInBuffer, Size, pOutBuffer, Timeout, HASH_ALGOSELECTION_SHA224); 0199 } 0200 0201 /** 0202 * @brief Initialize the HASH peripheral in SHA256 mode, next process pInBuffer then 0203 * read the computed digest. 0204 * @note Digest is available in pOutBuffer. 0205 * @param hhash HASH handle. 0206 * @param pInBuffer pointer to the input buffer (buffer to be hashed). 0207 * @param Size length of the input buffer in bytes. 0208 * @param pOutBuffer pointer to the computed digest. Digest size is 32 bytes. 0209 * @param Timeout Timeout value 0210 * @retval HAL status 0211 */ 0212 HAL_StatusTypeDef HAL_HASHEx_SHA256_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, 0213 uint8_t *pOutBuffer, uint32_t Timeout) 0214 { 0215 return HASH_Start(hhash, pInBuffer, Size, pOutBuffer, Timeout, HASH_ALGOSELECTION_SHA256); 0216 } 0217 0218 /** 0219 * @brief If not already done, initialize the HASH peripheral in SHA256 mode then 0220 * processes pInBuffer. 0221 * @note Consecutive calls to HAL_HASHEx_SHA256_Accmlt() can be used to feed 0222 * several input buffers back-to-back to the Peripheral that will yield a single 0223 * HASH signature once all buffers have been entered. Wrap-up of input 0224 * buffers feeding and retrieval of digest is done by a call to 0225 * HAL_HASHEx_SHA256_Accmlt_End(). 0226 * @note Field hhash->Phase of HASH handle is tested to check whether or not 0227 * the Peripheral has already been initialized. 0228 * @note Digest is not retrieved by this API, user must resort to HAL_HASHEx_SHA256_Accmlt_End() 0229 * to read it, feeding at the same time the last input buffer to the Peripheral. 0230 * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the 0231 * HASH digest computation is corrupted. Only HAL_HASHEx_SHA256_Accmlt_End() is able 0232 * to manage the ending buffer with a length in bytes not a multiple of 4. 0233 * @param hhash HASH handle. 0234 * @param pInBuffer pointer to the input buffer (buffer to be hashed). 0235 * @param Size length of the input buffer in bytes, must be a multiple of 4. 0236 * @retval HAL status 0237 */ 0238 HAL_StatusTypeDef HAL_HASHEx_SHA256_Accmlt(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) 0239 { 0240 return HASH_Accumulate(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA256); 0241 } 0242 0243 /** 0244 * @brief End computation of a single HASH signature after several calls to HAL_HASHEx_SHA256_Accmlt() API. 0245 * @note Digest is available in pOutBuffer. 0246 * @param hhash HASH handle. 0247 * @param pInBuffer pointer to the input buffer (buffer to be hashed). 0248 * @param Size length of the input buffer in bytes. 0249 * @param pOutBuffer pointer to the computed digest. Digest size is 32 bytes. 0250 * @param Timeout Timeout value 0251 * @retval HAL status 0252 */ 0253 HAL_StatusTypeDef HAL_HASHEx_SHA256_Accmlt_End(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, 0254 uint8_t *pOutBuffer, uint32_t Timeout) 0255 { 0256 return HASH_Start(hhash, pInBuffer, Size, pOutBuffer, Timeout, HASH_ALGOSELECTION_SHA256); 0257 } 0258 0259 /** 0260 * @} 0261 */ 0262 0263 /** @defgroup HASHEx_Exported_Functions_Group2 HASH extended processing functions in interrupt mode 0264 * @ingroup RTEMSBSPsARMSTM32H7 0265 * @brief HASH extended processing functions using interrupt mode. 0266 * 0267 @verbatim 0268 =============================================================================== 0269 ##### Interruption mode HASH extended processing functions ##### 0270 =============================================================================== 0271 [..] This section provides functions allowing to calculate in interrupt mode 0272 the hash value using one of the following algorithms: 0273 (+) SHA224 0274 (++) HAL_HASHEx_SHA224_Start_IT() 0275 (++) HAL_HASHEx_SHA224_Accmlt_IT() 0276 (++) HAL_HASHEx_SHA224_Accmlt_End_IT() 0277 (+) SHA256 0278 (++) HAL_HASHEx_SHA256_Start_IT() 0279 (++) HAL_HASHEx_SHA256_Accmlt_IT() 0280 (++) HAL_HASHEx_SHA256_Accmlt_End_IT() 0281 0282 @endverbatim 0283 * @{ 0284 */ 0285 0286 0287 /** 0288 * @brief Initialize the HASH peripheral in SHA224 mode, next process pInBuffer then 0289 * read the computed digest in interruption mode. 0290 * @note Digest is available in pOutBuffer. 0291 * @param hhash HASH handle. 0292 * @param pInBuffer pointer to the input buffer (buffer to be hashed). 0293 * @param Size length of the input buffer in bytes. 0294 * @param pOutBuffer pointer to the computed digest. Digest size is 28 bytes. 0295 * @retval HAL status 0296 */ 0297 HAL_StatusTypeDef HAL_HASHEx_SHA224_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, 0298 uint8_t *pOutBuffer) 0299 { 0300 return HASH_Start_IT(hhash, pInBuffer, Size, pOutBuffer, HASH_ALGOSELECTION_SHA224); 0301 } 0302 0303 /** 0304 * @brief If not already done, initialize the HASH peripheral in SHA224 mode then 0305 * processes pInBuffer in interruption mode. 0306 * @note Consecutive calls to HAL_HASHEx_SHA224_Accmlt_IT() can be used to feed 0307 * several input buffers back-to-back to the Peripheral that will yield a single 0308 * HASH signature once all buffers have been entered. Wrap-up of input 0309 * buffers feeding and retrieval of digest is done by a call to 0310 * HAL_HASHEx_SHA224_Accmlt_End_IT(). 0311 * @note Field hhash->Phase of HASH handle is tested to check whether or not 0312 * the Peripheral has already been initialized. 0313 * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the 0314 * HASH digest computation is corrupted. Only HAL_HASHEx_SHA224_Accmlt_End_IT() is able 0315 * to manage the ending buffer with a length in bytes not a multiple of 4. 0316 * @param hhash HASH handle. 0317 * @param pInBuffer pointer to the input buffer (buffer to be hashed). 0318 * @param Size length of the input buffer in bytes, must be a multiple of 4. 0319 * @retval HAL status 0320 */ 0321 HAL_StatusTypeDef HAL_HASHEx_SHA224_Accmlt_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) 0322 { 0323 return HASH_Accumulate_IT(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA224); 0324 } 0325 0326 /** 0327 * @brief End computation of a single HASH signature after several calls to HAL_HASHEx_SHA224_Accmlt_IT() API. 0328 * @note Digest is available in pOutBuffer. 0329 * @param hhash HASH handle. 0330 * @param pInBuffer pointer to the input buffer (buffer to be hashed). 0331 * @param Size length of the input buffer in bytes. 0332 * @param pOutBuffer pointer to the computed digest. Digest size is 28 bytes. 0333 * @retval HAL status 0334 */ 0335 HAL_StatusTypeDef HAL_HASHEx_SHA224_Accmlt_End_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, 0336 uint8_t *pOutBuffer) 0337 { 0338 return HASH_Start_IT(hhash, pInBuffer, Size, pOutBuffer, HASH_ALGOSELECTION_SHA224); 0339 } 0340 0341 /** 0342 * @brief Initialize the HASH peripheral in SHA256 mode, next process pInBuffer then 0343 * read the computed digest in interruption mode. 0344 * @note Digest is available in pOutBuffer. 0345 * @param hhash HASH handle. 0346 * @param pInBuffer pointer to the input buffer (buffer to be hashed). 0347 * @param Size length of the input buffer in bytes. 0348 * @param pOutBuffer pointer to the computed digest. Digest size is 32 bytes. 0349 * @retval HAL status 0350 */ 0351 HAL_StatusTypeDef HAL_HASHEx_SHA256_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, 0352 uint8_t *pOutBuffer) 0353 { 0354 return HASH_Start_IT(hhash, pInBuffer, Size, pOutBuffer, HASH_ALGOSELECTION_SHA256); 0355 } 0356 0357 /** 0358 * @brief If not already done, initialize the HASH peripheral in SHA256 mode then 0359 * processes pInBuffer in interruption mode. 0360 * @note Consecutive calls to HAL_HASHEx_SHA256_Accmlt_IT() can be used to feed 0361 * several input buffers back-to-back to the Peripheral that will yield a single 0362 * HASH signature once all buffers have been entered. Wrap-up of input 0363 * buffers feeding and retrieval of digest is done by a call to 0364 * HAL_HASHEx_SHA256_Accmlt_End_IT(). 0365 * @note Field hhash->Phase of HASH handle is tested to check whether or not 0366 * the Peripheral has already been initialized. 0367 * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the 0368 * HASH digest computation is corrupted. Only HAL_HASHEx_SHA256_Accmlt_End_IT() is able 0369 * to manage the ending buffer with a length in bytes not a multiple of 4. 0370 * @param hhash HASH handle. 0371 * @param pInBuffer pointer to the input buffer (buffer to be hashed). 0372 * @param Size length of the input buffer in bytes, must be a multiple of 4. 0373 * @retval HAL status 0374 */ 0375 HAL_StatusTypeDef HAL_HASHEx_SHA256_Accmlt_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) 0376 { 0377 return HASH_Accumulate_IT(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA256); 0378 } 0379 0380 /** 0381 * @brief End computation of a single HASH signature after several calls to HAL_HASHEx_SHA256_Accmlt_IT() API. 0382 * @note Digest is available in pOutBuffer. 0383 * @param hhash HASH handle. 0384 * @param pInBuffer pointer to the input buffer (buffer to be hashed). 0385 * @param Size length of the input buffer in bytes. 0386 * @param pOutBuffer pointer to the computed digest. Digest size is 32 bytes. 0387 * @retval HAL status 0388 */ 0389 HAL_StatusTypeDef HAL_HASHEx_SHA256_Accmlt_End_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, 0390 uint8_t *pOutBuffer) 0391 { 0392 return HASH_Start_IT(hhash, pInBuffer, Size, pOutBuffer, HASH_ALGOSELECTION_SHA256); 0393 } 0394 0395 /** 0396 * @} 0397 */ 0398 0399 /** @defgroup HASHEx_Exported_Functions_Group3 HASH extended processing functions in DMA mode 0400 * @ingroup RTEMSBSPsARMSTM32H7 0401 * @brief HASH extended processing functions using DMA mode. 0402 * 0403 @verbatim 0404 =============================================================================== 0405 ##### DMA mode HASH extended processing functions ##### 0406 =============================================================================== 0407 [..] This section provides functions allowing to calculate in DMA mode 0408 the hash value using one of the following algorithms: 0409 (+) SHA224 0410 (++) HAL_HASHEx_SHA224_Start_DMA() 0411 (++) HAL_HASHEx_SHA224_Finish() 0412 (+) SHA256 0413 (++) HAL_HASHEx_SHA256_Start_DMA() 0414 (++) HAL_HASHEx_SHA256_Finish() 0415 0416 [..] When resorting to DMA mode to enter the data in the Peripheral, user must resort 0417 to HAL_HASHEx_xxx_Start_DMA() then read the resulting digest with 0418 HAL_HASHEx_xxx_Finish(). 0419 0420 [..] In case of multi-buffer HASH processing, MDMAT bit must first be set before 0421 the successive calls to HAL_HASHEx_xxx_Start_DMA(). Then, MDMAT bit needs to be 0422 reset before the last call to HAL_HASHEx_xxx_Start_DMA(). Digest is finally 0423 retrieved thanks to HAL_HASHEx_xxx_Finish(). 0424 0425 @endverbatim 0426 * @{ 0427 */ 0428 0429 0430 0431 0432 /** 0433 * @brief Initialize the HASH peripheral in SHA224 mode then initiate a DMA transfer 0434 * to feed the input buffer to the Peripheral. 0435 * @note Once the DMA transfer is finished, HAL_HASHEx_SHA224_Finish() API must 0436 * be called to retrieve the computed digest. 0437 * @param hhash HASH handle. 0438 * @param pInBuffer pointer to the input buffer (buffer to be hashed). 0439 * @param Size length of the input buffer in bytes. 0440 * @retval HAL status 0441 */ 0442 HAL_StatusTypeDef HAL_HASHEx_SHA224_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) 0443 { 0444 return HASH_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA224); 0445 } 0446 0447 /** 0448 * @brief Return the computed digest in SHA224 mode. 0449 * @note The API waits for DCIS to be set then reads the computed digest. 0450 * @note HAL_HASHEx_SHA224_Finish() can be used as well to retrieve the digest in 0451 * HMAC SHA224 mode. 0452 * @param hhash HASH handle. 0453 * @param pOutBuffer pointer to the computed digest. Digest size is 28 bytes. 0454 * @param Timeout Timeout value. 0455 * @retval HAL status 0456 */ 0457 HAL_StatusTypeDef HAL_HASHEx_SHA224_Finish(HASH_HandleTypeDef *hhash, uint8_t *pOutBuffer, uint32_t Timeout) 0458 { 0459 return HASH_Finish(hhash, pOutBuffer, Timeout); 0460 } 0461 0462 /** 0463 * @brief Initialize the HASH peripheral in SHA256 mode then initiate a DMA transfer 0464 * to feed the input buffer to the Peripheral. 0465 * @note Once the DMA transfer is finished, HAL_HASHEx_SHA256_Finish() API must 0466 * be called to retrieve the computed digest. 0467 * @param hhash HASH handle. 0468 * @param pInBuffer pointer to the input buffer (buffer to be hashed). 0469 * @param Size length of the input buffer in bytes. 0470 * @retval HAL status 0471 */ 0472 HAL_StatusTypeDef HAL_HASHEx_SHA256_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) 0473 { 0474 return HASH_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA256); 0475 } 0476 0477 /** 0478 * @brief Return the computed digest in SHA256 mode. 0479 * @note The API waits for DCIS to be set then reads the computed digest. 0480 * @note HAL_HASHEx_SHA256_Finish() can be used as well to retrieve the digest in 0481 * HMAC SHA256 mode. 0482 * @param hhash HASH handle. 0483 * @param pOutBuffer pointer to the computed digest. Digest size is 32 bytes. 0484 * @param Timeout Timeout value. 0485 * @retval HAL status 0486 */ 0487 HAL_StatusTypeDef HAL_HASHEx_SHA256_Finish(HASH_HandleTypeDef *hhash, uint8_t *pOutBuffer, uint32_t Timeout) 0488 { 0489 return HASH_Finish(hhash, pOutBuffer, Timeout); 0490 } 0491 0492 /** 0493 * @} 0494 */ 0495 0496 /** @defgroup HASHEx_Exported_Functions_Group4 HMAC extended processing functions in polling mode 0497 * @ingroup RTEMSBSPsARMSTM32H7 0498 * @brief HMAC extended processing functions using polling mode. 0499 * 0500 @verbatim 0501 =============================================================================== 0502 ##### Polling mode HMAC extended processing functions ##### 0503 =============================================================================== 0504 [..] This section provides functions allowing to calculate in polling mode 0505 the HMAC value using one of the following algorithms: 0506 (+) SHA224 0507 (++) HAL_HMACEx_SHA224_Start() 0508 (+) SHA256 0509 (++) HAL_HMACEx_SHA256_Start() 0510 0511 @endverbatim 0512 * @{ 0513 */ 0514 0515 0516 0517 /** 0518 * @brief Initialize the HASH peripheral in HMAC SHA224 mode, next process pInBuffer then 0519 * read the computed digest. 0520 * @note Digest is available in pOutBuffer. 0521 * @note Same key is used for the inner and the outer hash functions; pointer to key and 0522 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize. 0523 * @param hhash HASH handle. 0524 * @param pInBuffer pointer to the input buffer (buffer to be hashed). 0525 * @param Size length of the input buffer in bytes. 0526 * @param pOutBuffer pointer to the computed digest. Digest size is 28 bytes. 0527 * @param Timeout Timeout value. 0528 * @retval HAL status 0529 */ 0530 HAL_StatusTypeDef HAL_HMACEx_SHA224_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, 0531 uint8_t *pOutBuffer, uint32_t Timeout) 0532 { 0533 return HMAC_Start(hhash, pInBuffer, Size, pOutBuffer, Timeout, HASH_ALGOSELECTION_SHA224); 0534 } 0535 0536 /** 0537 * @brief Initialize the HASH peripheral in HMAC SHA256 mode, next process pInBuffer then 0538 * read the computed digest. 0539 * @note Digest is available in pOutBuffer. 0540 * @note Same key is used for the inner and the outer hash functions; pointer to key and 0541 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize. 0542 * @param hhash HASH handle. 0543 * @param pInBuffer pointer to the input buffer (buffer to be hashed). 0544 * @param Size length of the input buffer in bytes. 0545 * @param pOutBuffer pointer to the computed digest. Digest size is 32 bytes. 0546 * @param Timeout Timeout value. 0547 * @retval HAL status 0548 */ 0549 HAL_StatusTypeDef HAL_HMACEx_SHA256_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, 0550 uint8_t *pOutBuffer, uint32_t Timeout) 0551 { 0552 return HMAC_Start(hhash, pInBuffer, Size, pOutBuffer, Timeout, HASH_ALGOSELECTION_SHA256); 0553 } 0554 0555 /** 0556 * @} 0557 */ 0558 0559 0560 /** @defgroup HASHEx_Exported_Functions_Group5 HMAC extended processing functions in interrupt mode 0561 * @ingroup RTEMSBSPsARMSTM32H7 0562 * @brief HMAC extended processing functions using interruption mode. 0563 * 0564 @verbatim 0565 =============================================================================== 0566 ##### Interrupt mode HMAC extended processing functions ##### 0567 =============================================================================== 0568 [..] This section provides functions allowing to calculate in interrupt mode 0569 the HMAC value using one of the following algorithms: 0570 (+) SHA224 0571 (++) HAL_HMACEx_SHA224_Start_IT() 0572 (+) SHA256 0573 (++) HAL_HMACEx_SHA256_Start_IT() 0574 0575 @endverbatim 0576 * @{ 0577 */ 0578 0579 0580 0581 /** 0582 * @brief Initialize the HASH peripheral in HMAC SHA224 mode, next process pInBuffer then 0583 * read the computed digest in interrupt mode. 0584 * @note Digest is available in pOutBuffer. 0585 * @note Same key is used for the inner and the outer hash functions; pointer to key and 0586 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize. 0587 * @param hhash HASH handle. 0588 * @param pInBuffer pointer to the input buffer (buffer to be hashed). 0589 * @param Size length of the input buffer in bytes. 0590 * @param pOutBuffer pointer to the computed digest. Digest size is 28 bytes. 0591 * @retval HAL status 0592 */ 0593 HAL_StatusTypeDef HAL_HMACEx_SHA224_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, 0594 uint8_t *pOutBuffer) 0595 { 0596 return HMAC_Start_IT(hhash, pInBuffer, Size, pOutBuffer, HASH_ALGOSELECTION_SHA224); 0597 } 0598 0599 /** 0600 * @brief Initialize the HASH peripheral in HMAC SHA256 mode, next process pInBuffer then 0601 * read the computed digest in interrupt mode. 0602 * @note Digest is available in pOutBuffer. 0603 * @note Same key is used for the inner and the outer hash functions; pointer to key and 0604 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize. 0605 * @param hhash HASH handle. 0606 * @param pInBuffer pointer to the input buffer (buffer to be hashed). 0607 * @param Size length of the input buffer in bytes. 0608 * @param pOutBuffer pointer to the computed digest. Digest size is 32 bytes. 0609 * @retval HAL status 0610 */ 0611 HAL_StatusTypeDef HAL_HMACEx_SHA256_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, 0612 uint8_t *pOutBuffer) 0613 { 0614 return HMAC_Start_IT(hhash, pInBuffer, Size, pOutBuffer, HASH_ALGOSELECTION_SHA256); 0615 } 0616 0617 0618 0619 0620 /** 0621 * @} 0622 */ 0623 0624 0625 /** @defgroup HASHEx_Exported_Functions_Group6 HMAC extended processing functions in DMA mode 0626 * @ingroup RTEMSBSPsARMSTM32H7 0627 * @brief HMAC extended processing functions using DMA mode. 0628 * 0629 @verbatim 0630 =============================================================================== 0631 ##### DMA mode HMAC extended processing functions ##### 0632 =============================================================================== 0633 [..] This section provides functions allowing to calculate in DMA mode 0634 the HMAC value using one of the following algorithms: 0635 (+) SHA224 0636 (++) HAL_HMACEx_SHA224_Start_DMA() 0637 (+) SHA256 0638 (++) HAL_HMACEx_SHA256_Start_DMA() 0639 0640 [..] When resorting to DMA mode to enter the data in the Peripheral for HMAC processing, 0641 user must resort to HAL_HMACEx_xxx_Start_DMA() then read the resulting digest 0642 with HAL_HASHEx_xxx_Finish(). 0643 0644 0645 @endverbatim 0646 * @{ 0647 */ 0648 0649 0650 0651 /** 0652 * @brief Initialize the HASH peripheral in HMAC SHA224 mode then initiate the required 0653 * DMA transfers to feed the key and the input buffer to the Peripheral. 0654 * @note Once the DMA transfers are finished (indicated by hhash->State set back 0655 * to HAL_HASH_STATE_READY), HAL_HASHEx_SHA224_Finish() API must be called to retrieve 0656 * the computed digest. 0657 * @note Same key is used for the inner and the outer hash functions; pointer to key and 0658 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize. 0659 * @note If MDMAT bit is set before calling this function (multi-buffer 0660 * HASH processing case), the input buffer size (in bytes) must be 0661 * a multiple of 4 otherwise, the HASH digest computation is corrupted. 0662 * For the processing of the last buffer of the thread, MDMAT bit must 0663 * be reset and the buffer length (in bytes) doesn't have to be a 0664 * multiple of 4. 0665 * @param hhash HASH handle. 0666 * @param pInBuffer pointer to the input buffer (buffer to be hashed). 0667 * @param Size length of the input buffer in bytes. 0668 * @retval HAL status 0669 */ 0670 HAL_StatusTypeDef HAL_HMACEx_SHA224_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) 0671 { 0672 return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA224); 0673 } 0674 0675 /** 0676 * @brief Initialize the HASH peripheral in HMAC SHA224 mode then initiate the required 0677 * DMA transfers to feed the key and the input buffer to the Peripheral. 0678 * @note Once the DMA transfers are finished (indicated by hhash->State set back 0679 * to HAL_HASH_STATE_READY), HAL_HASHEx_SHA256_Finish() API must be called to retrieve 0680 * the computed digest. 0681 * @note Same key is used for the inner and the outer hash functions; pointer to key and 0682 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize. 0683 * @note If MDMAT bit is set before calling this function (multi-buffer 0684 * HASH processing case), the input buffer size (in bytes) must be 0685 * a multiple of 4 otherwise, the HASH digest computation is corrupted. 0686 * For the processing of the last buffer of the thread, MDMAT bit must 0687 * be reset and the buffer length (in bytes) doesn't have to be a 0688 * multiple of 4. 0689 * @param hhash HASH handle. 0690 * @param pInBuffer pointer to the input buffer (buffer to be hashed). 0691 * @param Size length of the input buffer in bytes. 0692 * @retval HAL status 0693 */ 0694 HAL_StatusTypeDef HAL_HMACEx_SHA256_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) 0695 { 0696 return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA256); 0697 } 0698 0699 0700 /** 0701 * @} 0702 */ 0703 0704 /** @defgroup HASHEx_Exported_Functions_Group7 Multi-buffer HMAC extended processing functions in DMA mode 0705 * @ingroup RTEMSBSPsARMSTM32H7 0706 * @brief HMAC extended processing functions in multi-buffer DMA mode. 0707 * 0708 @verbatim 0709 =============================================================================== 0710 ##### Multi-buffer DMA mode HMAC extended processing functions ##### 0711 =============================================================================== 0712 [..] This section provides functions to manage HMAC multi-buffer 0713 DMA-based processing for MD5, SHA1, SHA224 and SHA256 algorithms. 0714 (+) MD5 0715 (++) HAL_HMACEx_MD5_Step1_2_DMA() 0716 (++) HAL_HMACEx_MD5_Step2_DMA() 0717 (++) HAL_HMACEx_MD5_Step2_3_DMA() 0718 (+) SHA1 0719 (++) HAL_HMACEx_SHA1_Step1_2_DMA() 0720 (++) HAL_HMACEx_SHA1_Step2_DMA() 0721 (++) HAL_HMACEx_SHA1_Step2_3_DMA() 0722 0723 (+) SHA256 0724 (++) HAL_HMACEx_SHA224_Step1_2_DMA() 0725 (++) HAL_HMACEx_SHA224_Step2_DMA() 0726 (++) HAL_HMACEx_SHA224_Step2_3_DMA() 0727 (+) SHA256 0728 (++) HAL_HMACEx_SHA256_Step1_2_DMA() 0729 (++) HAL_HMACEx_SHA256_Step2_DMA() 0730 (++) HAL_HMACEx_SHA256_Step2_3_DMA() 0731 0732 [..] User must first start-up the multi-buffer DMA-based HMAC computation in 0733 calling HAL_HMACEx_xxx_Step1_2_DMA(). This carries out HMAC step 1 and 0734 intiates step 2 with the first input buffer. 0735 0736 [..] The following buffers are next fed to the Peripheral with a call to the API 0737 HAL_HMACEx_xxx_Step2_DMA(). There may be several consecutive calls 0738 to this API. 0739 0740 [..] Multi-buffer DMA-based HMAC computation is wrapped up by a call to 0741 HAL_HMACEx_xxx_Step2_3_DMA(). This finishes step 2 in feeding the last input 0742 buffer to the Peripheral then carries out step 3. 0743 0744 [..] Digest is retrieved by a call to HAL_HASH_xxx_Finish() for MD-5 or 0745 SHA-1, to HAL_HASHEx_xxx_Finish() for SHA-224 or SHA-256. 0746 0747 [..] If only two buffers need to be consecutively processed, a call to 0748 HAL_HMACEx_xxx_Step1_2_DMA() followed by a call to HAL_HMACEx_xxx_Step2_3_DMA() 0749 is sufficient. 0750 0751 @endverbatim 0752 * @{ 0753 */ 0754 0755 /** 0756 * @brief MD5 HMAC step 1 completion and step 2 start in multi-buffer DMA mode. 0757 * @note Step 1 consists in writing the inner hash function key in the Peripheral, 0758 * step 2 consists in writing the message text. 0759 * @note The API carries out the HMAC step 1 then starts step 2 with 0760 * the first buffer entered to the Peripheral. DCAL bit is not automatically set after 0761 * the message buffer feeding, allowing other messages DMA transfers to occur. 0762 * @note Same key is used for the inner and the outer hash functions; pointer to key and 0763 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize. 0764 * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the 0765 * HASH digest computation is corrupted. 0766 * @param hhash HASH handle. 0767 * @param pInBuffer pointer to the input buffer (message buffer). 0768 * @param Size length of the input buffer in bytes. 0769 * @retval HAL status 0770 */ 0771 HAL_StatusTypeDef HAL_HMACEx_MD5_Step1_2_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) 0772 { 0773 hhash->DigestCalculationDisable = SET; 0774 return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_MD5); 0775 } 0776 0777 /** 0778 * @brief MD5 HMAC step 2 in multi-buffer DMA mode. 0779 * @note Step 2 consists in writing the message text in the Peripheral. 0780 * @note The API carries on the HMAC step 2, applied to the buffer entered as input 0781 * parameter. DCAL bit is not automatically set after the message buffer feeding, 0782 * allowing other messages DMA transfers to occur. 0783 * @note Same key is used for the inner and the outer hash functions; pointer to key and 0784 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize. 0785 * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the 0786 * HASH digest computation is corrupted. 0787 * @param hhash HASH handle. 0788 * @param pInBuffer pointer to the input buffer (message buffer). 0789 * @param Size length of the input buffer in bytes. 0790 * @retval HAL status 0791 */ 0792 HAL_StatusTypeDef HAL_HMACEx_MD5_Step2_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) 0793 { 0794 if (hhash->DigestCalculationDisable != SET) 0795 { 0796 return HAL_ERROR; 0797 } 0798 return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_MD5); 0799 } 0800 0801 /** 0802 * @brief MD5 HMAC step 2 wrap-up and step 3 completion in multi-buffer DMA mode. 0803 * @note Step 2 consists in writing the message text in the Peripheral, 0804 * step 3 consists in writing the outer hash function key. 0805 * @note The API wraps up the HMAC step 2 in processing the buffer entered as input 0806 * parameter (the input buffer must be the last one of the multi-buffer thread) 0807 * then carries out HMAC step 3. 0808 * @note Same key is used for the inner and the outer hash functions; pointer to key and 0809 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize. 0810 * @note Once the DMA transfers are finished (indicated by hhash->State set back 0811 * to HAL_HASH_STATE_READY), HAL_HASHEx_SHA256_Finish() API must be called to retrieve 0812 * the computed digest. 0813 * @param hhash HASH handle. 0814 * @param pInBuffer pointer to the input buffer (message buffer). 0815 * @param Size length of the input buffer in bytes. 0816 * @retval HAL status 0817 */ 0818 HAL_StatusTypeDef HAL_HMACEx_MD5_Step2_3_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) 0819 { 0820 hhash->DigestCalculationDisable = RESET; 0821 return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_MD5); 0822 } 0823 0824 0825 /** 0826 * @brief SHA1 HMAC step 1 completion and step 2 start in multi-buffer DMA mode. 0827 * @note Step 1 consists in writing the inner hash function key in the Peripheral, 0828 * step 2 consists in writing the message text. 0829 * @note The API carries out the HMAC step 1 then starts step 2 with 0830 * the first buffer entered to the Peripheral. DCAL bit is not automatically set after 0831 * the message buffer feeding, allowing other messages DMA transfers to occur. 0832 * @note Same key is used for the inner and the outer hash functions; pointer to key and 0833 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize. 0834 * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the 0835 * HASH digest computation is corrupted. 0836 * @param hhash HASH handle. 0837 * @param pInBuffer pointer to the input buffer (message buffer). 0838 * @param Size length of the input buffer in bytes. 0839 * @retval HAL status 0840 */ 0841 HAL_StatusTypeDef HAL_HMACEx_SHA1_Step1_2_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) 0842 { 0843 hhash->DigestCalculationDisable = SET; 0844 return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA1); 0845 } 0846 0847 /** 0848 * @brief SHA1 HMAC step 2 in multi-buffer DMA mode. 0849 * @note Step 2 consists in writing the message text in the Peripheral. 0850 * @note The API carries on the HMAC step 2, applied to the buffer entered as input 0851 * parameter. DCAL bit is not automatically set after the message buffer feeding, 0852 * allowing other messages DMA transfers to occur. 0853 * @note Same key is used for the inner and the outer hash functions; pointer to key and 0854 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize. 0855 * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the 0856 * HASH digest computation is corrupted. 0857 * @param hhash HASH handle. 0858 * @param pInBuffer pointer to the input buffer (message buffer). 0859 * @param Size length of the input buffer in bytes. 0860 * @retval HAL status 0861 */ 0862 HAL_StatusTypeDef HAL_HMACEx_SHA1_Step2_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) 0863 { 0864 if (hhash->DigestCalculationDisable != SET) 0865 { 0866 return HAL_ERROR; 0867 } 0868 return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA1); 0869 } 0870 0871 /** 0872 * @brief SHA1 HMAC step 2 wrap-up and step 3 completion in multi-buffer DMA mode. 0873 * @note Step 2 consists in writing the message text in the Peripheral, 0874 * step 3 consists in writing the outer hash function key. 0875 * @note The API wraps up the HMAC step 2 in processing the buffer entered as input 0876 * parameter (the input buffer must be the last one of the multi-buffer thread) 0877 * then carries out HMAC step 3. 0878 * @note Same key is used for the inner and the outer hash functions; pointer to key and 0879 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize. 0880 * @note Once the DMA transfers are finished (indicated by hhash->State set back 0881 * to HAL_HASH_STATE_READY), HAL_HASHEx_SHA256_Finish() API must be called to retrieve 0882 * the computed digest. 0883 * @param hhash HASH handle. 0884 * @param pInBuffer pointer to the input buffer (message buffer). 0885 * @param Size length of the input buffer in bytes. 0886 * @retval HAL status 0887 */ 0888 HAL_StatusTypeDef HAL_HMACEx_SHA1_Step2_3_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) 0889 { 0890 hhash->DigestCalculationDisable = RESET; 0891 return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA1); 0892 } 0893 0894 /** 0895 * @brief SHA224 HMAC step 1 completion and step 2 start in multi-buffer DMA mode. 0896 * @note Step 1 consists in writing the inner hash function key in the Peripheral, 0897 * step 2 consists in writing the message text. 0898 * @note The API carries out the HMAC step 1 then starts step 2 with 0899 * the first buffer entered to the Peripheral. DCAL bit is not automatically set after 0900 * the message buffer feeding, allowing other messages DMA transfers to occur. 0901 * @note Same key is used for the inner and the outer hash functions; pointer to key and 0902 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize. 0903 * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the 0904 * HASH digest computation is corrupted. 0905 * @param hhash HASH handle. 0906 * @param pInBuffer pointer to the input buffer (message buffer). 0907 * @param Size length of the input buffer in bytes. 0908 * @retval HAL status 0909 */ 0910 HAL_StatusTypeDef HAL_HMACEx_SHA224_Step1_2_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) 0911 { 0912 hhash->DigestCalculationDisable = SET; 0913 return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA224); 0914 } 0915 0916 /** 0917 * @brief SHA224 HMAC step 2 in multi-buffer DMA mode. 0918 * @note Step 2 consists in writing the message text in the Peripheral. 0919 * @note The API carries on the HMAC step 2, applied to the buffer entered as input 0920 * parameter. DCAL bit is not automatically set after the message buffer feeding, 0921 * allowing other messages DMA transfers to occur. 0922 * @note Same key is used for the inner and the outer hash functions; pointer to key and 0923 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize. 0924 * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the 0925 * HASH digest computation is corrupted. 0926 * @param hhash HASH handle. 0927 * @param pInBuffer pointer to the input buffer (message buffer). 0928 * @param Size length of the input buffer in bytes. 0929 * @retval HAL status 0930 */ 0931 HAL_StatusTypeDef HAL_HMACEx_SHA224_Step2_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) 0932 { 0933 if (hhash->DigestCalculationDisable != SET) 0934 { 0935 return HAL_ERROR; 0936 } 0937 return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA224); 0938 } 0939 0940 /** 0941 * @brief SHA224 HMAC step 2 wrap-up and step 3 completion in multi-buffer DMA mode. 0942 * @note Step 2 consists in writing the message text in the Peripheral, 0943 * step 3 consists in writing the outer hash function key. 0944 * @note The API wraps up the HMAC step 2 in processing the buffer entered as input 0945 * parameter (the input buffer must be the last one of the multi-buffer thread) 0946 * then carries out HMAC step 3. 0947 * @note Same key is used for the inner and the outer hash functions; pointer to key and 0948 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize. 0949 * @note Once the DMA transfers are finished (indicated by hhash->State set back 0950 * to HAL_HASH_STATE_READY), HAL_HASHEx_SHA256_Finish() API must be called to retrieve 0951 * the computed digest. 0952 * @param hhash HASH handle. 0953 * @param pInBuffer pointer to the input buffer (message buffer). 0954 * @param Size length of the input buffer in bytes. 0955 * @retval HAL status 0956 */ 0957 HAL_StatusTypeDef HAL_HMACEx_SHA224_Step2_3_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) 0958 { 0959 hhash->DigestCalculationDisable = RESET; 0960 return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA224); 0961 } 0962 0963 /** 0964 * @brief SHA256 HMAC step 1 completion and step 2 start in multi-buffer DMA mode. 0965 * @note Step 1 consists in writing the inner hash function key in the Peripheral, 0966 * step 2 consists in writing the message text. 0967 * @note The API carries out the HMAC step 1 then starts step 2 with 0968 * the first buffer entered to the Peripheral. DCAL bit is not automatically set after 0969 * the message buffer feeding, allowing other messages DMA transfers to occur. 0970 * @note Same key is used for the inner and the outer hash functions; pointer to key and 0971 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize. 0972 * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the 0973 * HASH digest computation is corrupted. 0974 * @param hhash HASH handle. 0975 * @param pInBuffer pointer to the input buffer (message buffer). 0976 * @param Size length of the input buffer in bytes. 0977 * @retval HAL status 0978 */ 0979 HAL_StatusTypeDef HAL_HMACEx_SHA256_Step1_2_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) 0980 { 0981 hhash->DigestCalculationDisable = SET; 0982 return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA256); 0983 } 0984 0985 /** 0986 * @brief SHA256 HMAC step 2 in multi-buffer DMA mode. 0987 * @note Step 2 consists in writing the message text in the Peripheral. 0988 * @note The API carries on the HMAC step 2, applied to the buffer entered as input 0989 * parameter. DCAL bit is not automatically set after the message buffer feeding, 0990 * allowing other messages DMA transfers to occur. 0991 * @note Same key is used for the inner and the outer hash functions; pointer to key and 0992 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize. 0993 * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the 0994 * HASH digest computation is corrupted. 0995 * @param hhash HASH handle. 0996 * @param pInBuffer pointer to the input buffer (message buffer). 0997 * @param Size length of the input buffer in bytes. 0998 * @retval HAL status 0999 */ 1000 HAL_StatusTypeDef HAL_HMACEx_SHA256_Step2_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) 1001 { 1002 if (hhash->DigestCalculationDisable != SET) 1003 { 1004 return HAL_ERROR; 1005 } 1006 return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA256); 1007 } 1008 1009 /** 1010 * @brief SHA256 HMAC step 2 wrap-up and step 3 completion in multi-buffer DMA mode. 1011 * @note Step 2 consists in writing the message text in the Peripheral, 1012 * step 3 consists in writing the outer hash function key. 1013 * @note The API wraps up the HMAC step 2 in processing the buffer entered as input 1014 * parameter (the input buffer must be the last one of the multi-buffer thread) 1015 * then carries out HMAC step 3. 1016 * @note Same key is used for the inner and the outer hash functions; pointer to key and 1017 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize. 1018 * @note Once the DMA transfers are finished (indicated by hhash->State set back 1019 * to HAL_HASH_STATE_READY), HAL_HASHEx_SHA256_Finish() API must be called to retrieve 1020 * the computed digest. 1021 * @param hhash HASH handle. 1022 * @param pInBuffer pointer to the input buffer (message buffer). 1023 * @param Size length of the input buffer in bytes. 1024 * @retval HAL status 1025 */ 1026 HAL_StatusTypeDef HAL_HMACEx_SHA256_Step2_3_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) 1027 { 1028 hhash->DigestCalculationDisable = RESET; 1029 return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA256); 1030 } 1031 1032 /** 1033 * @} 1034 */ 1035 1036 1037 /** 1038 * @} 1039 */ 1040 #endif /* HAL_HASH_MODULE_ENABLED */ 1041 1042 /** 1043 * @} 1044 */ 1045 #endif /* HASH*/ 1046 /** 1047 * @} 1048 */ 1049
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |