STM32F479xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32f4xx_hal_hash_ex.c 00004 * @author MCD Application Team 00005 * @brief Extended HASH HAL module driver. 00006 * This file provides firmware functions to manage the following 00007 * functionalities of the HASH peripheral for SHA-224 and SHA-256 00008 * algorithms: 00009 * + HASH or HMAC processing in polling mode 00010 * + HASH or HMAC processing in interrupt mode 00011 * + HASH or HMAC processing in DMA mode 00012 * Additionally, this file provides functions to manage HMAC 00013 * multi-buffer DMA-based processing for MD-5, SHA-1, SHA-224 00014 * and SHA-256. 00015 * 00016 * 00017 @verbatim 00018 =============================================================================== 00019 ##### HASH peripheral extended features ##### 00020 =============================================================================== 00021 [..] 00022 The SHA-224 and SHA-256 HASH and HMAC processing can be carried out exactly 00023 the same way as for SHA-1 or MD-5 algorithms. 00024 (#) Three modes are available. 00025 (##) Polling mode: processing APIs are blocking functions 00026 i.e. they process the data and wait till the digest computation is finished, 00027 e.g. HAL_HASHEx_xxx_Start() 00028 (##) Interrupt mode: processing APIs are not blocking functions 00029 i.e. they process the data under interrupt, 00030 e.g. HAL_HASHEx_xxx_Start_IT() 00031 (##) DMA mode: processing APIs are not blocking functions and the CPU is 00032 not used for data transfer i.e. the data transfer is ensured by DMA, 00033 e.g. HAL_HASHEx_xxx_Start_DMA(). Note that in DMA mode, a call to 00034 HAL_HASHEx_xxx_Finish() is then required to retrieve the digest. 00035 00036 (#)Multi-buffer processing is possible in polling, interrupt and DMA modes. 00037 (##) In polling mode, only multi-buffer HASH processing is possible. 00038 API HAL_HASHEx_xxx_Accumulate() must be called for each input buffer, except for the last one. 00039 User must resort to HAL_HASHEx_xxx_Accumulate_End() to enter the last one and retrieve as 00040 well the computed digest. 00041 00042 (##) In interrupt mode, API HAL_HASHEx_xxx_Accumulate_IT() must be called for each input buffer, 00043 except for the last one. 00044 User must resort to HAL_HASHEx_xxx_Accumulate_End_IT() to enter the last one and retrieve as 00045 well the computed digest. 00046 00047 (##) In DMA mode, multi-buffer HASH and HMAC processing are possible. 00048 00049 (+++) HASH processing: once initialization is done, MDMAT bit must be set through 00050 __HAL_HASH_SET_MDMAT() macro. 00051 From that point, each buffer can be fed to the Peripheral through HAL_HASHEx_xxx_Start_DMA() API. 00052 Before entering the last buffer, reset the MDMAT bit with __HAL_HASH_RESET_MDMAT() 00053 macro then wrap-up the HASH processing in feeding the last input buffer through the 00054 same API HAL_HASHEx_xxx_Start_DMA(). The digest can then be retrieved with a call to 00055 API HAL_HASHEx_xxx_Finish(). 00056 00057 (+++) HMAC processing (MD-5, SHA-1, SHA-224 and SHA-256 must all resort to 00058 extended functions): after initialization, the key and the first input buffer are entered 00059 in the Peripheral with the API HAL_HMACEx_xxx_Step1_2_DMA(). This carries out HMAC step 1 and 00060 starts step 2. 00061 The following buffers are next entered with the API HAL_HMACEx_xxx_Step2_DMA(). At this 00062 point, the HMAC processing is still carrying out step 2. 00063 Then, step 2 for the last input buffer and step 3 are carried out by a single call 00064 to HAL_HMACEx_xxx_Step2_3_DMA(). 00065 00066 The digest can finally be retrieved with a call to API HAL_HASH_xxx_Finish() for 00067 MD-5 and SHA-1, to HAL_HASHEx_xxx_Finish() for SHA-224 and SHA-256. 00068 00069 00070 @endverbatim 00071 ****************************************************************************** 00072 * @attention 00073 * 00074 * <h2><center>© Copyright (c) 2016 STMicroelectronics. 00075 * All rights reserved.</center></h2> 00076 * 00077 * This software component is licensed by ST under BSD 3-Clause license, 00078 * the "License"; You may not use this file except in compliance with the 00079 * License. You may obtain a copy of the License at: 00080 * opensource.org/licenses/BSD-3-Clause 00081 * 00082 ****************************************************************************** 00083 */ 00084 00085 /* Includes ------------------------------------------------------------------*/ 00086 #include "stm32f4xx_hal.h" 00087 00088 00089 00090 00091 /** @addtogroup STM32F4xx_HAL_Driver 00092 * @{ 00093 */ 00094 #if defined (HASH) 00095 00096 /** @defgroup HASHEx HASHEx 00097 * @brief HASH HAL extended module driver. 00098 * @{ 00099 */ 00100 #ifdef HAL_HASH_MODULE_ENABLED 00101 /* Private typedef -----------------------------------------------------------*/ 00102 /* Private define ------------------------------------------------------------*/ 00103 /* Private functions ---------------------------------------------------------*/ 00104 #if defined (HASH_CR_MDMAT) 00105 00106 /** @defgroup HASHEx_Exported_Functions HASH Extended Exported Functions 00107 * @{ 00108 */ 00109 00110 /** @defgroup HASHEx_Exported_Functions_Group1 HASH extended processing functions in polling mode 00111 * @brief HASH extended processing functions using polling mode. 00112 * 00113 @verbatim 00114 =============================================================================== 00115 ##### Polling mode HASH extended processing functions ##### 00116 =============================================================================== 00117 [..] This section provides functions allowing to calculate in polling mode 00118 the hash value using one of the following algorithms: 00119 (+) SHA224 00120 (++) HAL_HASHEx_SHA224_Start() 00121 (++) HAL_HASHEx_SHA224_Accmlt() 00122 (++) HAL_HASHEx_SHA224_Accmlt_End() 00123 (+) SHA256 00124 (++) HAL_HASHEx_SHA256_Start() 00125 (++) HAL_HASHEx_SHA256_Accmlt() 00126 (++) HAL_HASHEx_SHA256_Accmlt_End() 00127 00128 [..] For a single buffer to be hashed, user can resort to HAL_HASH_xxx_Start(). 00129 00130 [..] In case of multi-buffer HASH processing (a single digest is computed while 00131 several buffers are fed to the Peripheral), the user can resort to successive calls 00132 to HAL_HASHEx_xxx_Accumulate() and wrap-up the digest computation by a call 00133 to HAL_HASHEx_xxx_Accumulate_End(). 00134 00135 @endverbatim 00136 * @{ 00137 */ 00138 00139 00140 /** 00141 * @brief Initialize the HASH peripheral in SHA224 mode, next process pInBuffer then 00142 * read the computed digest. 00143 * @note Digest is available in pOutBuffer. 00144 * @param hhash HASH handle. 00145 * @param pInBuffer pointer to the input buffer (buffer to be hashed). 00146 * @param Size length of the input buffer in bytes. 00147 * @param pOutBuffer pointer to the computed digest. Digest size is 28 bytes. 00148 * @param Timeout Timeout value 00149 * @retval HAL status 00150 */ 00151 HAL_StatusTypeDef HAL_HASHEx_SHA224_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, 00152 uint8_t *pOutBuffer, uint32_t Timeout) 00153 { 00154 return HASH_Start(hhash, pInBuffer, Size, pOutBuffer, Timeout, HASH_ALGOSELECTION_SHA224); 00155 } 00156 00157 /** 00158 * @brief If not already done, initialize the HASH peripheral in SHA224 mode then 00159 * processes pInBuffer. 00160 * @note Consecutive calls to HAL_HASHEx_SHA224_Accmlt() can be used to feed 00161 * several input buffers back-to-back to the Peripheral that will yield a single 00162 * HASH signature once all buffers have been entered. Wrap-up of input 00163 * buffers feeding and retrieval of digest is done by a call to 00164 * HAL_HASHEx_SHA224_Accmlt_End(). 00165 * @note Field hhash->Phase of HASH handle is tested to check whether or not 00166 * the Peripheral has already been initialized. 00167 * @note Digest is not retrieved by this API, user must resort to HAL_HASHEx_SHA224_Accmlt_End() 00168 * to read it, feeding at the same time the last input buffer to the Peripheral. 00169 * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the 00170 * HASH digest computation is corrupted. Only HAL_HASHEx_SHA224_Accmlt_End() is able 00171 * to manage the ending buffer with a length in bytes not a multiple of 4. 00172 * @param hhash HASH handle. 00173 * @param pInBuffer pointer to the input buffer (buffer to be hashed). 00174 * @param Size length of the input buffer in bytes, must be a multiple of 4. 00175 * @retval HAL status 00176 */ 00177 HAL_StatusTypeDef HAL_HASHEx_SHA224_Accmlt(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) 00178 { 00179 return HASH_Accumulate(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA224); 00180 } 00181 00182 /** 00183 * @brief End computation of a single HASH signature after several calls to HAL_HASHEx_SHA224_Accmlt() API. 00184 * @note Digest is available in pOutBuffer. 00185 * @param hhash HASH handle. 00186 * @param pInBuffer pointer to the input buffer (buffer to be hashed). 00187 * @param Size length of the input buffer in bytes. 00188 * @param pOutBuffer pointer to the computed digest. Digest size is 28 bytes. 00189 * @param Timeout Timeout value 00190 * @retval HAL status 00191 */ 00192 HAL_StatusTypeDef HAL_HASHEx_SHA224_Accmlt_End(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, 00193 uint8_t *pOutBuffer, uint32_t Timeout) 00194 { 00195 return HASH_Start(hhash, pInBuffer, Size, pOutBuffer, Timeout, HASH_ALGOSELECTION_SHA224); 00196 } 00197 00198 /** 00199 * @brief Initialize the HASH peripheral in SHA256 mode, next process pInBuffer then 00200 * read the computed digest. 00201 * @note Digest is available in pOutBuffer. 00202 * @param hhash HASH handle. 00203 * @param pInBuffer pointer to the input buffer (buffer to be hashed). 00204 * @param Size length of the input buffer in bytes. 00205 * @param pOutBuffer pointer to the computed digest. Digest size is 32 bytes. 00206 * @param Timeout Timeout value 00207 * @retval HAL status 00208 */ 00209 HAL_StatusTypeDef HAL_HASHEx_SHA256_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, 00210 uint8_t *pOutBuffer, uint32_t Timeout) 00211 { 00212 return HASH_Start(hhash, pInBuffer, Size, pOutBuffer, Timeout, HASH_ALGOSELECTION_SHA256); 00213 } 00214 00215 /** 00216 * @brief If not already done, initialize the HASH peripheral in SHA256 mode then 00217 * processes pInBuffer. 00218 * @note Consecutive calls to HAL_HASHEx_SHA256_Accmlt() can be used to feed 00219 * several input buffers back-to-back to the Peripheral that will yield a single 00220 * HASH signature once all buffers have been entered. Wrap-up of input 00221 * buffers feeding and retrieval of digest is done by a call to 00222 * HAL_HASHEx_SHA256_Accmlt_End(). 00223 * @note Field hhash->Phase of HASH handle is tested to check whether or not 00224 * the Peripheral has already been initialized. 00225 * @note Digest is not retrieved by this API, user must resort to HAL_HASHEx_SHA256_Accmlt_End() 00226 * to read it, feeding at the same time the last input buffer to the Peripheral. 00227 * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the 00228 * HASH digest computation is corrupted. Only HAL_HASHEx_SHA256_Accmlt_End() is able 00229 * to manage the ending buffer with a length in bytes not a multiple of 4. 00230 * @param hhash HASH handle. 00231 * @param pInBuffer pointer to the input buffer (buffer to be hashed). 00232 * @param Size length of the input buffer in bytes, must be a multiple of 4. 00233 * @retval HAL status 00234 */ 00235 HAL_StatusTypeDef HAL_HASHEx_SHA256_Accmlt(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) 00236 { 00237 return HASH_Accumulate(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA256); 00238 } 00239 00240 /** 00241 * @brief End computation of a single HASH signature after several calls to HAL_HASHEx_SHA256_Accmlt() API. 00242 * @note Digest is available in pOutBuffer. 00243 * @param hhash HASH handle. 00244 * @param pInBuffer pointer to the input buffer (buffer to be hashed). 00245 * @param Size length of the input buffer in bytes. 00246 * @param pOutBuffer pointer to the computed digest. Digest size is 32 bytes. 00247 * @param Timeout Timeout value 00248 * @retval HAL status 00249 */ 00250 HAL_StatusTypeDef HAL_HASHEx_SHA256_Accmlt_End(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, 00251 uint8_t *pOutBuffer, uint32_t Timeout) 00252 { 00253 return HASH_Start(hhash, pInBuffer, Size, pOutBuffer, Timeout, HASH_ALGOSELECTION_SHA256); 00254 } 00255 00256 /** 00257 * @} 00258 */ 00259 00260 /** @defgroup HASHEx_Exported_Functions_Group2 HASH extended processing functions in interrupt mode 00261 * @brief HASH extended processing functions using interrupt mode. 00262 * 00263 @verbatim 00264 =============================================================================== 00265 ##### Interruption mode HASH extended processing functions ##### 00266 =============================================================================== 00267 [..] This section provides functions allowing to calculate in interrupt mode 00268 the hash value using one of the following algorithms: 00269 (+) SHA224 00270 (++) HAL_HASHEx_SHA224_Start_IT() 00271 (++) HAL_HASHEx_SHA224_Accmlt_IT() 00272 (++) HAL_HASHEx_SHA224_Accmlt_End_IT() 00273 (+) SHA256 00274 (++) HAL_HASHEx_SHA256_Start_IT() 00275 (++) HAL_HASHEx_SHA256_Accmlt_IT() 00276 (++) HAL_HASHEx_SHA256_Accmlt_End_IT() 00277 00278 @endverbatim 00279 * @{ 00280 */ 00281 00282 00283 /** 00284 * @brief Initialize the HASH peripheral in SHA224 mode, next process pInBuffer then 00285 * read the computed digest in interruption mode. 00286 * @note Digest is available in pOutBuffer. 00287 * @param hhash HASH handle. 00288 * @param pInBuffer pointer to the input buffer (buffer to be hashed). 00289 * @param Size length of the input buffer in bytes. 00290 * @param pOutBuffer pointer to the computed digest. Digest size is 28 bytes. 00291 * @retval HAL status 00292 */ 00293 HAL_StatusTypeDef HAL_HASHEx_SHA224_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, 00294 uint8_t *pOutBuffer) 00295 { 00296 return HASH_Start_IT(hhash, pInBuffer, Size, pOutBuffer, HASH_ALGOSELECTION_SHA224); 00297 } 00298 00299 /** 00300 * @brief If not already done, initialize the HASH peripheral in SHA224 mode then 00301 * processes pInBuffer in interruption mode. 00302 * @note Consecutive calls to HAL_HASHEx_SHA224_Accmlt_IT() can be used to feed 00303 * several input buffers back-to-back to the Peripheral that will yield a single 00304 * HASH signature once all buffers have been entered. Wrap-up of input 00305 * buffers feeding and retrieval of digest is done by a call to 00306 * HAL_HASHEx_SHA224_Accmlt_End_IT(). 00307 * @note Field hhash->Phase of HASH handle is tested to check whether or not 00308 * the Peripheral has already been initialized. 00309 * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the 00310 * HASH digest computation is corrupted. Only HAL_HASHEx_SHA224_Accmlt_End_IT() is able 00311 * to manage the ending buffer with a length in bytes not a multiple of 4. 00312 * @param hhash HASH handle. 00313 * @param pInBuffer pointer to the input buffer (buffer to be hashed). 00314 * @param Size length of the input buffer in bytes, must be a multiple of 4. 00315 * @retval HAL status 00316 */ 00317 HAL_StatusTypeDef HAL_HASHEx_SHA224_Accmlt_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) 00318 { 00319 return HASH_Accumulate_IT(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA224); 00320 } 00321 00322 /** 00323 * @brief End computation of a single HASH signature after several calls to HAL_HASHEx_SHA224_Accmlt_IT() API. 00324 * @note Digest is available in pOutBuffer. 00325 * @param hhash HASH handle. 00326 * @param pInBuffer pointer to the input buffer (buffer to be hashed). 00327 * @param Size length of the input buffer in bytes. 00328 * @param pOutBuffer pointer to the computed digest. Digest size is 28 bytes. 00329 * @retval HAL status 00330 */ 00331 HAL_StatusTypeDef HAL_HASHEx_SHA224_Accmlt_End_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, 00332 uint8_t *pOutBuffer) 00333 { 00334 return HASH_Start_IT(hhash, pInBuffer, Size, pOutBuffer, HASH_ALGOSELECTION_SHA224); 00335 } 00336 00337 /** 00338 * @brief Initialize the HASH peripheral in SHA256 mode, next process pInBuffer then 00339 * read the computed digest in interruption mode. 00340 * @note Digest is available in pOutBuffer. 00341 * @param hhash HASH handle. 00342 * @param pInBuffer pointer to the input buffer (buffer to be hashed). 00343 * @param Size length of the input buffer in bytes. 00344 * @param pOutBuffer pointer to the computed digest. Digest size is 32 bytes. 00345 * @retval HAL status 00346 */ 00347 HAL_StatusTypeDef HAL_HASHEx_SHA256_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, 00348 uint8_t *pOutBuffer) 00349 { 00350 return HASH_Start_IT(hhash, pInBuffer, Size, pOutBuffer, HASH_ALGOSELECTION_SHA256); 00351 } 00352 00353 /** 00354 * @brief If not already done, initialize the HASH peripheral in SHA256 mode then 00355 * processes pInBuffer in interruption mode. 00356 * @note Consecutive calls to HAL_HASHEx_SHA256_Accmlt_IT() can be used to feed 00357 * several input buffers back-to-back to the Peripheral that will yield a single 00358 * HASH signature once all buffers have been entered. Wrap-up of input 00359 * buffers feeding and retrieval of digest is done by a call to 00360 * HAL_HASHEx_SHA256_Accmlt_End_IT(). 00361 * @note Field hhash->Phase of HASH handle is tested to check whether or not 00362 * the Peripheral has already been initialized. 00363 * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the 00364 * HASH digest computation is corrupted. Only HAL_HASHEx_SHA256_Accmlt_End_IT() is able 00365 * to manage the ending buffer with a length in bytes not a multiple of 4. 00366 * @param hhash HASH handle. 00367 * @param pInBuffer pointer to the input buffer (buffer to be hashed). 00368 * @param Size length of the input buffer in bytes, must be a multiple of 4. 00369 * @retval HAL status 00370 */ 00371 HAL_StatusTypeDef HAL_HASHEx_SHA256_Accmlt_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) 00372 { 00373 return HASH_Accumulate_IT(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA256); 00374 } 00375 00376 /** 00377 * @brief End computation of a single HASH signature after several calls to HAL_HASHEx_SHA256_Accmlt_IT() API. 00378 * @note Digest is available in pOutBuffer. 00379 * @param hhash HASH handle. 00380 * @param pInBuffer pointer to the input buffer (buffer to be hashed). 00381 * @param Size length of the input buffer in bytes. 00382 * @param pOutBuffer pointer to the computed digest. Digest size is 32 bytes. 00383 * @retval HAL status 00384 */ 00385 HAL_StatusTypeDef HAL_HASHEx_SHA256_Accmlt_End_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, 00386 uint8_t *pOutBuffer) 00387 { 00388 return HASH_Start_IT(hhash, pInBuffer, Size, pOutBuffer, HASH_ALGOSELECTION_SHA256); 00389 } 00390 00391 /** 00392 * @} 00393 */ 00394 00395 /** @defgroup HASHEx_Exported_Functions_Group3 HASH extended processing functions in DMA mode 00396 * @brief HASH extended processing functions using DMA mode. 00397 * 00398 @verbatim 00399 =============================================================================== 00400 ##### DMA mode HASH extended processing functions ##### 00401 =============================================================================== 00402 [..] This section provides functions allowing to calculate in DMA mode 00403 the hash value using one of the following algorithms: 00404 (+) SHA224 00405 (++) HAL_HASHEx_SHA224_Start_DMA() 00406 (++) HAL_HASHEx_SHA224_Finish() 00407 (+) SHA256 00408 (++) HAL_HASHEx_SHA256_Start_DMA() 00409 (++) HAL_HASHEx_SHA256_Finish() 00410 00411 [..] When resorting to DMA mode to enter the data in the Peripheral, user must resort 00412 to HAL_HASHEx_xxx_Start_DMA() then read the resulting digest with 00413 HAL_HASHEx_xxx_Finish(). 00414 00415 [..] In case of multi-buffer HASH processing, MDMAT bit must first be set before 00416 the successive calls to HAL_HASHEx_xxx_Start_DMA(). Then, MDMAT bit needs to be 00417 reset before the last call to HAL_HASHEx_xxx_Start_DMA(). Digest is finally 00418 retrieved thanks to HAL_HASHEx_xxx_Finish(). 00419 00420 @endverbatim 00421 * @{ 00422 */ 00423 00424 00425 00426 00427 /** 00428 * @brief Initialize the HASH peripheral in SHA224 mode then initiate a DMA transfer 00429 * to feed the input buffer to the Peripheral. 00430 * @note Once the DMA transfer is finished, HAL_HASHEx_SHA224_Finish() API must 00431 * be called to retrieve the computed digest. 00432 * @param hhash HASH handle. 00433 * @param pInBuffer pointer to the input buffer (buffer to be hashed). 00434 * @param Size length of the input buffer in bytes. 00435 * @retval HAL status 00436 */ 00437 HAL_StatusTypeDef HAL_HASHEx_SHA224_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) 00438 { 00439 return HASH_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA224); 00440 } 00441 00442 /** 00443 * @brief Return the computed digest in SHA224 mode. 00444 * @note The API waits for DCIS to be set then reads the computed digest. 00445 * @note HAL_HASHEx_SHA224_Finish() can be used as well to retrieve the digest in 00446 * HMAC SHA224 mode. 00447 * @param hhash HASH handle. 00448 * @param pOutBuffer pointer to the computed digest. Digest size is 28 bytes. 00449 * @param Timeout Timeout value. 00450 * @retval HAL status 00451 */ 00452 HAL_StatusTypeDef HAL_HASHEx_SHA224_Finish(HASH_HandleTypeDef *hhash, uint8_t *pOutBuffer, uint32_t Timeout) 00453 { 00454 return HASH_Finish(hhash, pOutBuffer, Timeout); 00455 } 00456 00457 /** 00458 * @brief Initialize the HASH peripheral in SHA256 mode then initiate a DMA transfer 00459 * to feed the input buffer to the Peripheral. 00460 * @note Once the DMA transfer is finished, HAL_HASHEx_SHA256_Finish() API must 00461 * be called to retrieve the computed digest. 00462 * @param hhash HASH handle. 00463 * @param pInBuffer pointer to the input buffer (buffer to be hashed). 00464 * @param Size length of the input buffer in bytes. 00465 * @retval HAL status 00466 */ 00467 HAL_StatusTypeDef HAL_HASHEx_SHA256_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) 00468 { 00469 return HASH_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA256); 00470 } 00471 00472 /** 00473 * @brief Return the computed digest in SHA256 mode. 00474 * @note The API waits for DCIS to be set then reads the computed digest. 00475 * @note HAL_HASHEx_SHA256_Finish() can be used as well to retrieve the digest in 00476 * HMAC SHA256 mode. 00477 * @param hhash HASH handle. 00478 * @param pOutBuffer pointer to the computed digest. Digest size is 32 bytes. 00479 * @param Timeout Timeout value. 00480 * @retval HAL status 00481 */ 00482 HAL_StatusTypeDef HAL_HASHEx_SHA256_Finish(HASH_HandleTypeDef *hhash, uint8_t *pOutBuffer, uint32_t Timeout) 00483 { 00484 return HASH_Finish(hhash, pOutBuffer, Timeout); 00485 } 00486 00487 /** 00488 * @} 00489 */ 00490 00491 /** @defgroup HASHEx_Exported_Functions_Group4 HMAC extended processing functions in polling mode 00492 * @brief HMAC extended processing functions using polling mode. 00493 * 00494 @verbatim 00495 =============================================================================== 00496 ##### Polling mode HMAC extended processing functions ##### 00497 =============================================================================== 00498 [..] This section provides functions allowing to calculate in polling mode 00499 the HMAC value using one of the following algorithms: 00500 (+) SHA224 00501 (++) HAL_HMACEx_SHA224_Start() 00502 (+) SHA256 00503 (++) HAL_HMACEx_SHA256_Start() 00504 00505 @endverbatim 00506 * @{ 00507 */ 00508 00509 00510 00511 /** 00512 * @brief Initialize the HASH peripheral in HMAC SHA224 mode, next process pInBuffer then 00513 * read the computed digest. 00514 * @note Digest is available in pOutBuffer. 00515 * @note Same key is used for the inner and the outer hash functions; pointer to key and 00516 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize. 00517 * @param hhash HASH handle. 00518 * @param pInBuffer pointer to the input buffer (buffer to be hashed). 00519 * @param Size length of the input buffer in bytes. 00520 * @param pOutBuffer pointer to the computed digest. Digest size is 28 bytes. 00521 * @param Timeout Timeout value. 00522 * @retval HAL status 00523 */ 00524 HAL_StatusTypeDef HAL_HMACEx_SHA224_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, 00525 uint8_t *pOutBuffer, uint32_t Timeout) 00526 { 00527 return HMAC_Start(hhash, pInBuffer, Size, pOutBuffer, Timeout, HASH_ALGOSELECTION_SHA224); 00528 } 00529 00530 /** 00531 * @brief Initialize the HASH peripheral in HMAC SHA256 mode, next process pInBuffer then 00532 * read the computed digest. 00533 * @note Digest is available in pOutBuffer. 00534 * @note Same key is used for the inner and the outer hash functions; pointer to key and 00535 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize. 00536 * @param hhash HASH handle. 00537 * @param pInBuffer pointer to the input buffer (buffer to be hashed). 00538 * @param Size length of the input buffer in bytes. 00539 * @param pOutBuffer pointer to the computed digest. Digest size is 32 bytes. 00540 * @param Timeout Timeout value. 00541 * @retval HAL status 00542 */ 00543 HAL_StatusTypeDef HAL_HMACEx_SHA256_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, 00544 uint8_t *pOutBuffer, uint32_t Timeout) 00545 { 00546 return HMAC_Start(hhash, pInBuffer, Size, pOutBuffer, Timeout, HASH_ALGOSELECTION_SHA256); 00547 } 00548 00549 /** 00550 * @} 00551 */ 00552 00553 00554 /** @defgroup HASHEx_Exported_Functions_Group5 HMAC extended processing functions in interrupt mode 00555 * @brief HMAC extended processing functions using interruption mode. 00556 * 00557 @verbatim 00558 =============================================================================== 00559 ##### Interrupt mode HMAC extended processing functions ##### 00560 =============================================================================== 00561 [..] This section provides functions allowing to calculate in interrupt mode 00562 the HMAC value using one of the following algorithms: 00563 (+) SHA224 00564 (++) HAL_HMACEx_SHA224_Start_IT() 00565 (+) SHA256 00566 (++) HAL_HMACEx_SHA256_Start_IT() 00567 00568 @endverbatim 00569 * @{ 00570 */ 00571 00572 00573 00574 /** 00575 * @brief Initialize the HASH peripheral in HMAC SHA224 mode, next process pInBuffer then 00576 * read the computed digest in interrupt mode. 00577 * @note Digest is available in pOutBuffer. 00578 * @note Same key is used for the inner and the outer hash functions; pointer to key and 00579 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize. 00580 * @param hhash HASH handle. 00581 * @param pInBuffer pointer to the input buffer (buffer to be hashed). 00582 * @param Size length of the input buffer in bytes. 00583 * @param pOutBuffer pointer to the computed digest. Digest size is 28 bytes. 00584 * @retval HAL status 00585 */ 00586 HAL_StatusTypeDef HAL_HMACEx_SHA224_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, 00587 uint8_t *pOutBuffer) 00588 { 00589 return HMAC_Start_IT(hhash, pInBuffer, Size, pOutBuffer, HASH_ALGOSELECTION_SHA224); 00590 } 00591 00592 /** 00593 * @brief Initialize the HASH peripheral in HMAC SHA256 mode, next process pInBuffer then 00594 * read the computed digest in interrupt mode. 00595 * @note Digest is available in pOutBuffer. 00596 * @note Same key is used for the inner and the outer hash functions; pointer to key and 00597 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize. 00598 * @param hhash HASH handle. 00599 * @param pInBuffer pointer to the input buffer (buffer to be hashed). 00600 * @param Size length of the input buffer in bytes. 00601 * @param pOutBuffer pointer to the computed digest. Digest size is 32 bytes. 00602 * @retval HAL status 00603 */ 00604 HAL_StatusTypeDef HAL_HMACEx_SHA256_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, 00605 uint8_t *pOutBuffer) 00606 { 00607 return HMAC_Start_IT(hhash, pInBuffer, Size, pOutBuffer, HASH_ALGOSELECTION_SHA256); 00608 } 00609 00610 00611 00612 00613 /** 00614 * @} 00615 */ 00616 00617 00618 /** @defgroup HASHEx_Exported_Functions_Group6 HMAC extended processing functions in DMA mode 00619 * @brief HMAC extended processing functions using DMA mode. 00620 * 00621 @verbatim 00622 =============================================================================== 00623 ##### DMA mode HMAC extended processing functions ##### 00624 =============================================================================== 00625 [..] This section provides functions allowing to calculate in DMA mode 00626 the HMAC value using one of the following algorithms: 00627 (+) SHA224 00628 (++) HAL_HMACEx_SHA224_Start_DMA() 00629 (+) SHA256 00630 (++) HAL_HMACEx_SHA256_Start_DMA() 00631 00632 [..] When resorting to DMA mode to enter the data in the Peripheral for HMAC processing, 00633 user must resort to HAL_HMACEx_xxx_Start_DMA() then read the resulting digest 00634 with HAL_HASHEx_xxx_Finish(). 00635 00636 00637 @endverbatim 00638 * @{ 00639 */ 00640 00641 00642 00643 /** 00644 * @brief Initialize the HASH peripheral in HMAC SHA224 mode then initiate the required 00645 * DMA transfers to feed the key and the input buffer to the Peripheral. 00646 * @note Once the DMA transfers are finished (indicated by hhash->State set back 00647 * to HAL_HASH_STATE_READY), HAL_HASHEx_SHA224_Finish() API must be called to retrieve 00648 * the computed digest. 00649 * @note Same key is used for the inner and the outer hash functions; pointer to key and 00650 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize. 00651 * @note If MDMAT bit is set before calling this function (multi-buffer 00652 * HASH processing case), the input buffer size (in bytes) must be 00653 * a multiple of 4 otherwise, the HASH digest computation is corrupted. 00654 * For the processing of the last buffer of the thread, MDMAT bit must 00655 * be reset and the buffer length (in bytes) doesn't have to be a 00656 * multiple of 4. 00657 * @param hhash HASH handle. 00658 * @param pInBuffer pointer to the input buffer (buffer to be hashed). 00659 * @param Size length of the input buffer in bytes. 00660 * @retval HAL status 00661 */ 00662 HAL_StatusTypeDef HAL_HMACEx_SHA224_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) 00663 { 00664 return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA224); 00665 } 00666 00667 /** 00668 * @brief Initialize the HASH peripheral in HMAC SHA224 mode then initiate the required 00669 * DMA transfers to feed the key and the input buffer to the Peripheral. 00670 * @note Once the DMA transfers are finished (indicated by hhash->State set back 00671 * to HAL_HASH_STATE_READY), HAL_HASHEx_SHA256_Finish() API must be called to retrieve 00672 * the computed digest. 00673 * @note Same key is used for the inner and the outer hash functions; pointer to key and 00674 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize. 00675 * @note If MDMAT bit is set before calling this function (multi-buffer 00676 * HASH processing case), the input buffer size (in bytes) must be 00677 * a multiple of 4 otherwise, the HASH digest computation is corrupted. 00678 * For the processing of the last buffer of the thread, MDMAT bit must 00679 * be reset and the buffer length (in bytes) doesn't have to be a 00680 * multiple of 4. 00681 * @param hhash HASH handle. 00682 * @param pInBuffer pointer to the input buffer (buffer to be hashed). 00683 * @param Size length of the input buffer in bytes. 00684 * @retval HAL status 00685 */ 00686 HAL_StatusTypeDef HAL_HMACEx_SHA256_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) 00687 { 00688 return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA256); 00689 } 00690 00691 00692 /** 00693 * @} 00694 */ 00695 00696 /** @defgroup HASHEx_Exported_Functions_Group7 Multi-buffer HMAC extended processing functions in DMA mode 00697 * @brief HMAC extended processing functions in multi-buffer DMA mode. 00698 * 00699 @verbatim 00700 =============================================================================== 00701 ##### Multi-buffer DMA mode HMAC extended processing functions ##### 00702 =============================================================================== 00703 [..] This section provides functions to manage HMAC multi-buffer 00704 DMA-based processing for MD5, SHA1, SHA224 and SHA256 algorithms. 00705 (+) MD5 00706 (++) HAL_HMACEx_MD5_Step1_2_DMA() 00707 (++) HAL_HMACEx_MD5_Step2_DMA() 00708 (++) HAL_HMACEx_MD5_Step2_3_DMA() 00709 (+) SHA1 00710 (++) HAL_HMACEx_SHA1_Step1_2_DMA() 00711 (++) HAL_HMACEx_SHA1_Step2_DMA() 00712 (++) HAL_HMACEx_SHA1_Step2_3_DMA() 00713 00714 (+) SHA256 00715 (++) HAL_HMACEx_SHA224_Step1_2_DMA() 00716 (++) HAL_HMACEx_SHA224_Step2_DMA() 00717 (++) HAL_HMACEx_SHA224_Step2_3_DMA() 00718 (+) SHA256 00719 (++) HAL_HMACEx_SHA256_Step1_2_DMA() 00720 (++) HAL_HMACEx_SHA256_Step2_DMA() 00721 (++) HAL_HMACEx_SHA256_Step2_3_DMA() 00722 00723 [..] User must first start-up the multi-buffer DMA-based HMAC computation in 00724 calling HAL_HMACEx_xxx_Step1_2_DMA(). This carries out HMAC step 1 and 00725 intiates step 2 with the first input buffer. 00726 00727 [..] The following buffers are next fed to the Peripheral with a call to the API 00728 HAL_HMACEx_xxx_Step2_DMA(). There may be several consecutive calls 00729 to this API. 00730 00731 [..] Multi-buffer DMA-based HMAC computation is wrapped up by a call to 00732 HAL_HMACEx_xxx_Step2_3_DMA(). This finishes step 2 in feeding the last input 00733 buffer to the Peripheral then carries out step 3. 00734 00735 [..] Digest is retrieved by a call to HAL_HASH_xxx_Finish() for MD-5 or 00736 SHA-1, to HAL_HASHEx_xxx_Finish() for SHA-224 or SHA-256. 00737 00738 [..] If only two buffers need to be consecutively processed, a call to 00739 HAL_HMACEx_xxx_Step1_2_DMA() followed by a call to HAL_HMACEx_xxx_Step2_3_DMA() 00740 is sufficient. 00741 00742 @endverbatim 00743 * @{ 00744 */ 00745 00746 /** 00747 * @brief MD5 HMAC step 1 completion and step 2 start in multi-buffer DMA mode. 00748 * @note Step 1 consists in writing the inner hash function key in the Peripheral, 00749 * step 2 consists in writing the message text. 00750 * @note The API carries out the HMAC step 1 then starts step 2 with 00751 * the first buffer entered to the Peripheral. DCAL bit is not automatically set after 00752 * the message buffer feeding, allowing other messages DMA transfers to occur. 00753 * @note Same key is used for the inner and the outer hash functions; pointer to key and 00754 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize. 00755 * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the 00756 * HASH digest computation is corrupted. 00757 * @param hhash HASH handle. 00758 * @param pInBuffer pointer to the input buffer (message buffer). 00759 * @param Size length of the input buffer in bytes. 00760 * @retval HAL status 00761 */ 00762 HAL_StatusTypeDef HAL_HMACEx_MD5_Step1_2_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) 00763 { 00764 hhash->DigestCalculationDisable = SET; 00765 return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_MD5); 00766 } 00767 00768 /** 00769 * @brief MD5 HMAC step 2 in multi-buffer DMA mode. 00770 * @note Step 2 consists in writing the message text in the Peripheral. 00771 * @note The API carries on the HMAC step 2, applied to the buffer entered as input 00772 * parameter. DCAL bit is not automatically set after the message buffer feeding, 00773 * allowing other messages DMA transfers to occur. 00774 * @note Same key is used for the inner and the outer hash functions; pointer to key and 00775 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize. 00776 * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the 00777 * HASH digest computation is corrupted. 00778 * @param hhash HASH handle. 00779 * @param pInBuffer pointer to the input buffer (message buffer). 00780 * @param Size length of the input buffer in bytes. 00781 * @retval HAL status 00782 */ 00783 HAL_StatusTypeDef HAL_HMACEx_MD5_Step2_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) 00784 { 00785 if (hhash->DigestCalculationDisable != SET) 00786 { 00787 return HAL_ERROR; 00788 } 00789 return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_MD5); 00790 } 00791 00792 /** 00793 * @brief MD5 HMAC step 2 wrap-up and step 3 completion in multi-buffer DMA mode. 00794 * @note Step 2 consists in writing the message text in the Peripheral, 00795 * step 3 consists in writing the outer hash function key. 00796 * @note The API wraps up the HMAC step 2 in processing the buffer entered as input 00797 * parameter (the input buffer must be the last one of the multi-buffer thread) 00798 * then carries out HMAC step 3. 00799 * @note Same key is used for the inner and the outer hash functions; pointer to key and 00800 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize. 00801 * @note Once the DMA transfers are finished (indicated by hhash->State set back 00802 * to HAL_HASH_STATE_READY), HAL_HASHEx_SHA256_Finish() API must be called to retrieve 00803 * the computed digest. 00804 * @param hhash HASH handle. 00805 * @param pInBuffer pointer to the input buffer (message buffer). 00806 * @param Size length of the input buffer in bytes. 00807 * @retval HAL status 00808 */ 00809 HAL_StatusTypeDef HAL_HMACEx_MD5_Step2_3_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) 00810 { 00811 hhash->DigestCalculationDisable = RESET; 00812 return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_MD5); 00813 } 00814 00815 00816 /** 00817 * @brief SHA1 HMAC step 1 completion and step 2 start in multi-buffer DMA mode. 00818 * @note Step 1 consists in writing the inner hash function key in the Peripheral, 00819 * step 2 consists in writing the message text. 00820 * @note The API carries out the HMAC step 1 then starts step 2 with 00821 * the first buffer entered to the Peripheral. DCAL bit is not automatically set after 00822 * the message buffer feeding, allowing other messages DMA transfers to occur. 00823 * @note Same key is used for the inner and the outer hash functions; pointer to key and 00824 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize. 00825 * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the 00826 * HASH digest computation is corrupted. 00827 * @param hhash HASH handle. 00828 * @param pInBuffer pointer to the input buffer (message buffer). 00829 * @param Size length of the input buffer in bytes. 00830 * @retval HAL status 00831 */ 00832 HAL_StatusTypeDef HAL_HMACEx_SHA1_Step1_2_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) 00833 { 00834 hhash->DigestCalculationDisable = SET; 00835 return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA1); 00836 } 00837 00838 /** 00839 * @brief SHA1 HMAC step 2 in multi-buffer DMA mode. 00840 * @note Step 2 consists in writing the message text in the Peripheral. 00841 * @note The API carries on the HMAC step 2, applied to the buffer entered as input 00842 * parameter. DCAL bit is not automatically set after the message buffer feeding, 00843 * allowing other messages DMA transfers to occur. 00844 * @note Same key is used for the inner and the outer hash functions; pointer to key and 00845 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize. 00846 * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the 00847 * HASH digest computation is corrupted. 00848 * @param hhash HASH handle. 00849 * @param pInBuffer pointer to the input buffer (message buffer). 00850 * @param Size length of the input buffer in bytes. 00851 * @retval HAL status 00852 */ 00853 HAL_StatusTypeDef HAL_HMACEx_SHA1_Step2_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) 00854 { 00855 if (hhash->DigestCalculationDisable != SET) 00856 { 00857 return HAL_ERROR; 00858 } 00859 return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA1); 00860 } 00861 00862 /** 00863 * @brief SHA1 HMAC step 2 wrap-up and step 3 completion in multi-buffer DMA mode. 00864 * @note Step 2 consists in writing the message text in the Peripheral, 00865 * step 3 consists in writing the outer hash function key. 00866 * @note The API wraps up the HMAC step 2 in processing the buffer entered as input 00867 * parameter (the input buffer must be the last one of the multi-buffer thread) 00868 * then carries out HMAC step 3. 00869 * @note Same key is used for the inner and the outer hash functions; pointer to key and 00870 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize. 00871 * @note Once the DMA transfers are finished (indicated by hhash->State set back 00872 * to HAL_HASH_STATE_READY), HAL_HASHEx_SHA256_Finish() API must be called to retrieve 00873 * the computed digest. 00874 * @param hhash HASH handle. 00875 * @param pInBuffer pointer to the input buffer (message buffer). 00876 * @param Size length of the input buffer in bytes. 00877 * @retval HAL status 00878 */ 00879 HAL_StatusTypeDef HAL_HMACEx_SHA1_Step2_3_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) 00880 { 00881 hhash->DigestCalculationDisable = RESET; 00882 return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA1); 00883 } 00884 00885 /** 00886 * @brief SHA224 HMAC step 1 completion and step 2 start in multi-buffer DMA mode. 00887 * @note Step 1 consists in writing the inner hash function key in the Peripheral, 00888 * step 2 consists in writing the message text. 00889 * @note The API carries out the HMAC step 1 then starts step 2 with 00890 * the first buffer entered to the Peripheral. DCAL bit is not automatically set after 00891 * the message buffer feeding, allowing other messages DMA transfers to occur. 00892 * @note Same key is used for the inner and the outer hash functions; pointer to key and 00893 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize. 00894 * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the 00895 * HASH digest computation is corrupted. 00896 * @param hhash HASH handle. 00897 * @param pInBuffer pointer to the input buffer (message buffer). 00898 * @param Size length of the input buffer in bytes. 00899 * @retval HAL status 00900 */ 00901 HAL_StatusTypeDef HAL_HMACEx_SHA224_Step1_2_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) 00902 { 00903 hhash->DigestCalculationDisable = SET; 00904 return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA224); 00905 } 00906 00907 /** 00908 * @brief SHA224 HMAC step 2 in multi-buffer DMA mode. 00909 * @note Step 2 consists in writing the message text in the Peripheral. 00910 * @note The API carries on the HMAC step 2, applied to the buffer entered as input 00911 * parameter. DCAL bit is not automatically set after the message buffer feeding, 00912 * allowing other messages DMA transfers to occur. 00913 * @note Same key is used for the inner and the outer hash functions; pointer to key and 00914 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize. 00915 * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the 00916 * HASH digest computation is corrupted. 00917 * @param hhash HASH handle. 00918 * @param pInBuffer pointer to the input buffer (message buffer). 00919 * @param Size length of the input buffer in bytes. 00920 * @retval HAL status 00921 */ 00922 HAL_StatusTypeDef HAL_HMACEx_SHA224_Step2_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) 00923 { 00924 if (hhash->DigestCalculationDisable != SET) 00925 { 00926 return HAL_ERROR; 00927 } 00928 return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA224); 00929 } 00930 00931 /** 00932 * @brief SHA224 HMAC step 2 wrap-up and step 3 completion in multi-buffer DMA mode. 00933 * @note Step 2 consists in writing the message text in the Peripheral, 00934 * step 3 consists in writing the outer hash function key. 00935 * @note The API wraps up the HMAC step 2 in processing the buffer entered as input 00936 * parameter (the input buffer must be the last one of the multi-buffer thread) 00937 * then carries out HMAC step 3. 00938 * @note Same key is used for the inner and the outer hash functions; pointer to key and 00939 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize. 00940 * @note Once the DMA transfers are finished (indicated by hhash->State set back 00941 * to HAL_HASH_STATE_READY), HAL_HASHEx_SHA256_Finish() API must be called to retrieve 00942 * the computed digest. 00943 * @param hhash HASH handle. 00944 * @param pInBuffer pointer to the input buffer (message buffer). 00945 * @param Size length of the input buffer in bytes. 00946 * @retval HAL status 00947 */ 00948 HAL_StatusTypeDef HAL_HMACEx_SHA224_Step2_3_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) 00949 { 00950 hhash->DigestCalculationDisable = RESET; 00951 return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA224); 00952 } 00953 00954 /** 00955 * @brief SHA256 HMAC step 1 completion and step 2 start in multi-buffer DMA mode. 00956 * @note Step 1 consists in writing the inner hash function key in the Peripheral, 00957 * step 2 consists in writing the message text. 00958 * @note The API carries out the HMAC step 1 then starts step 2 with 00959 * the first buffer entered to the Peripheral. DCAL bit is not automatically set after 00960 * the message buffer feeding, allowing other messages DMA transfers to occur. 00961 * @note Same key is used for the inner and the outer hash functions; pointer to key and 00962 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize. 00963 * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the 00964 * HASH digest computation is corrupted. 00965 * @param hhash HASH handle. 00966 * @param pInBuffer pointer to the input buffer (message buffer). 00967 * @param Size length of the input buffer in bytes. 00968 * @retval HAL status 00969 */ 00970 HAL_StatusTypeDef HAL_HMACEx_SHA256_Step1_2_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) 00971 { 00972 hhash->DigestCalculationDisable = SET; 00973 return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA256); 00974 } 00975 00976 /** 00977 * @brief SHA256 HMAC step 2 in multi-buffer DMA mode. 00978 * @note Step 2 consists in writing the message text in the Peripheral. 00979 * @note The API carries on the HMAC step 2, applied to the buffer entered as input 00980 * parameter. DCAL bit is not automatically set after the message buffer feeding, 00981 * allowing other messages DMA transfers to occur. 00982 * @note Same key is used for the inner and the outer hash functions; pointer to key and 00983 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize. 00984 * @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the 00985 * HASH digest computation is corrupted. 00986 * @param hhash HASH handle. 00987 * @param pInBuffer pointer to the input buffer (message buffer). 00988 * @param Size length of the input buffer in bytes. 00989 * @retval HAL status 00990 */ 00991 HAL_StatusTypeDef HAL_HMACEx_SHA256_Step2_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) 00992 { 00993 if (hhash->DigestCalculationDisable != SET) 00994 { 00995 return HAL_ERROR; 00996 } 00997 return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA256); 00998 } 00999 01000 /** 01001 * @brief SHA256 HMAC step 2 wrap-up and step 3 completion in multi-buffer DMA mode. 01002 * @note Step 2 consists in writing the message text in the Peripheral, 01003 * step 3 consists in writing the outer hash function key. 01004 * @note The API wraps up the HMAC step 2 in processing the buffer entered as input 01005 * parameter (the input buffer must be the last one of the multi-buffer thread) 01006 * then carries out HMAC step 3. 01007 * @note Same key is used for the inner and the outer hash functions; pointer to key and 01008 * key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize. 01009 * @note Once the DMA transfers are finished (indicated by hhash->State set back 01010 * to HAL_HASH_STATE_READY), HAL_HASHEx_SHA256_Finish() API must be called to retrieve 01011 * the computed digest. 01012 * @param hhash HASH handle. 01013 * @param pInBuffer pointer to the input buffer (message buffer). 01014 * @param Size length of the input buffer in bytes. 01015 * @retval HAL status 01016 */ 01017 HAL_StatusTypeDef HAL_HMACEx_SHA256_Step2_3_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) 01018 { 01019 hhash->DigestCalculationDisable = RESET; 01020 return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA256); 01021 } 01022 01023 /** 01024 * @} 01025 */ 01026 01027 #endif /* MDMA defined*/ 01028 /** 01029 * @} 01030 */ 01031 #endif /* HAL_HASH_MODULE_ENABLED */ 01032 01033 /** 01034 * @} 01035 */ 01036 #endif /* HASH*/ 01037 /** 01038 * @} 01039 */ 01040 01041 01042 01043 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/