1 /** 2 ****************************************************************************** 3 * @file stm32h5xx_hal_hash.h 4 * @author MCD Application Team 5 * @brief Header file of HASH HAL module. 6 ****************************************************************************** 7 * @attention 8 * 9 * Copyright (c) 2022 STMicroelectronics. 10 * All rights reserved. 11 * 12 * This software is licensed under terms that can be found in the LICENSE file 13 * in the root directory of this software component. 14 * If no LICENSE file comes with this software, it is provided AS-IS. 15 * 16 ****************************************************************************** 17 */ 18 19 /* Define to prevent recursive inclusion -------------------------------------*/ 20 #ifndef STM32H5xx_HAL_HASH_H 21 #define STM32H5xx_HAL_HASH_H 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /* Includes ------------------------------------------------------------------*/ 28 #include "stm32h5xx_hal_def.h" 29 30 /** @addtogroup STM32H5xx_HAL_Driver 31 * @{ 32 */ 33 #if defined (HASH) 34 /** @defgroup HASH HASH 35 * @brief HASH HAL module driver. 36 * @{ 37 */ 38 39 /* Exported types ------------------------------------------------------------*/ 40 /** @defgroup HASH_Exported_Types HASH Exported Types 41 * @{ 42 */ 43 44 /** 45 * @brief HASH Configuration Structure definition 46 */ 47 typedef struct 48 { 49 uint32_t DataType; /*!< no swap (32-bit data), half word swap (16-bit data), byte swap (8-bit data) or bit swap 50 (1-bit data). This parameter can be a value of @ref HASH_Data_Type. */ 51 52 uint32_t KeySize; /*!< The key size is used only in HMAC operation. */ 53 54 uint8_t *pKey; /*!< The key is used only in HMAC operation. */ 55 56 uint32_t Algorithm; /*!< HASH algorithm MD5, SHA1 or SHA2. 57 This parameter can be a value of @ref HASH_Algorithm_Selection */ 58 59 60 } HASH_ConfigTypeDef; 61 62 /** 63 * @brief HAL State structure definition 64 */ 65 typedef enum 66 { 67 HAL_HASH_STATE_RESET = 0x00U, /*!< Peripheral is not initialized */ 68 HAL_HASH_STATE_READY = 0x01U, /*!< Peripheral Initialized and ready for use */ 69 HAL_HASH_STATE_BUSY = 0x02U, /*!< Processing (hashing) is ongoing */ 70 HAL_HASH_STATE_SUSPENDED = 0x03U /*!< Suspended state */ 71 } HAL_HASH_StateTypeDef; 72 73 /** 74 * @brief HAL phase structure definition 75 */ 76 typedef enum 77 { 78 HAL_HASH_PHASE_READY = 0x01U, /*!< HASH peripheral is ready to start */ 79 HAL_HASH_PHASE_PROCESS = 0x02U, /*!< HASH peripheral is in HASH processing phase */ 80 HAL_HASH_PHASE_HMAC_STEP_1 = 0x03U, /*!< HASH peripheral is in HMAC step 1 processing phase 81 (step 1 consists in entering the inner hash function key)*/ 82 HAL_HASH_PHASE_HMAC_STEP_2 = 0x04U, /*!< HASH peripheral is in HMAC step 2 processing phase 83 (step 2 consists in entering the message text) */ 84 HAL_HASH_PHASE_HMAC_STEP_3 = 0x05U /*!< HASH peripheral is in HMAC step 3 processing phase 85 (step 3 consists in entering the outer hash function key)*/ 86 87 } HAL_HASH_PhaseTypeDef; 88 89 #if (USE_HAL_HASH_SUSPEND_RESUME == 1U) 90 /** 91 * @brief HAL HASH mode suspend definitions 92 */ 93 typedef enum 94 { 95 HAL_HASH_SUSPEND_NONE = 0x00U, /*!< HASH peripheral suspension not requested */ 96 HAL_HASH_SUSPEND = 0x01U /*!< HASH peripheral suspension is requested */ 97 } HAL_HASH_SuspendTypeDef; 98 #endif /* USE_HAL_HASH_SUSPEND_RESUME */ 99 100 101 /** 102 * @brief HASH Handle Structure definition 103 */ 104 #if (USE_HAL_HASH_REGISTER_CALLBACKS == 1) 105 typedef struct __HASH_HandleTypeDef 106 #else 107 typedef struct 108 #endif /* (USE_HAL_HASH_REGISTER_CALLBACKS) */ 109 { 110 HASH_TypeDef *Instance; /*!< HASH Register base address */ 111 112 HASH_ConfigTypeDef Init; /*!< HASH required parameters */ 113 114 uint8_t const *pHashInBuffPtr; /*!< Pointer to input buffer */ 115 116 uint8_t *pHashOutBuffPtr; /*!< Pointer to output buffer (digest) */ 117 118 __IO uint32_t HashInCount; /*!< Counter of inputted data */ 119 120 uint32_t Size; /*!< Size of buffer to be processed in bytes */ 121 122 uint8_t *pHashKeyBuffPtr; /*!< Pointer to key buffer (HMAC only) */ 123 124 HAL_HASH_PhaseTypeDef Phase; /*!< HASH peripheral phase */ 125 126 DMA_HandleTypeDef *hdmain; /*!< HASH In DMA Handle parameters */ 127 128 HAL_LockTypeDef Lock; /*!< Locking object */ 129 130 __IO uint32_t ErrorCode; /*!< HASH Error code */ 131 132 __IO HAL_HASH_StateTypeDef State; /*!< HASH peripheral state */ 133 134 __IO uint32_t Accumulation; /*!< HASH multi buffers accumulation flag */ 135 136 #if (USE_HAL_HASH_REGISTER_CALLBACKS == 1) 137 void (* InCpltCallback)(struct __HASH_HandleTypeDef *hhash); /*!< HASH input completion callback */ 138 139 void (* DgstCpltCallback)(struct __HASH_HandleTypeDef *hhash); /*!< HASH digest computation complete callback */ 140 141 void (* ErrorCallback)(struct __HASH_HandleTypeDef *hhash); /*!< HASH error callback */ 142 143 void (* MspInitCallback)(struct __HASH_HandleTypeDef *hhash); /*!< HASH Msp Init callback */ 144 145 void (* MspDeInitCallback)(struct __HASH_HandleTypeDef *hhash); /*!< HASH Msp DeInit callback */ 146 147 #endif /* (USE_HAL_HASH_REGISTER_CALLBACKS) */ 148 #if (USE_HAL_HASH_SUSPEND_RESUME == 1U) 149 __IO HAL_HASH_SuspendTypeDef SuspendRequest; /*!< HASH peripheral suspension request flag */ 150 151 HASH_ConfigTypeDef Init_saved; /*!< Saved HASH required parameters */ 152 153 uint8_t const *pHashInBuffPtr_saved; /*!< Saved pointer to input buffer */ 154 155 uint8_t *pHashOutBuffPtr_saved; /*!< Saved pointer to output buffer (digest) */ 156 157 __IO uint32_t HashInCount_saved; /*!< Saved counter of inputted data */ 158 159 uint32_t Size_saved; /*!< Saved size of buffer to be processed */ 160 161 uint8_t *pHashKeyBuffPtr_saved; /*!< Saved pointer to key buffer (HMAC only) */ 162 163 HAL_HASH_PhaseTypeDef Phase_saved; /*!< Saved HASH peripheral phase */ 164 #endif /* USE_HAL_HASH_SUSPEND_RESUME */ 165 166 } HASH_HandleTypeDef; 167 168 #if (USE_HAL_HASH_REGISTER_CALLBACKS == 1U) 169 /** 170 * @brief HAL HASH common Callback ID enumeration definition 171 */ 172 typedef enum 173 { 174 HAL_HASH_MSPINIT_CB_ID = 0x00U, /*!< HASH MspInit callback ID */ 175 HAL_HASH_MSPDEINIT_CB_ID = 0x01U, /*!< HASH MspDeInit callback ID */ 176 HAL_HASH_INPUTCPLT_CB_ID = 0x02U, /*!< HASH input completion callback ID */ 177 HAL_HASH_DGSTCPLT_CB_ID = 0x03U, /*!< HASH digest computation completion callback ID */ 178 HAL_HASH_ERROR_CB_ID = 0x04U, /*!< HASH error callback ID */ 179 } HAL_HASH_CallbackIDTypeDef; 180 181 /** 182 * @brief HAL HASH Callback pointer definition 183 */ 184 typedef void (*pHASH_CallbackTypeDef)(HASH_HandleTypeDef *hhash); /*!< pointer to a HASH common callback functions */ 185 186 #endif /* USE_HAL_HASH_REGISTER_CALLBACKS */ 187 188 189 /** 190 * @} 191 */ 192 193 /* Exported constants --------------------------------------------------------*/ 194 195 /** @defgroup HASH_Exported_Constants HASH Exported Constants 196 * @{ 197 */ 198 199 /** @defgroup HASH_Error_Definition HASH Error Definition 200 * @{ 201 */ 202 #define HAL_HASH_ERROR_NONE 0x00000000U /*!< No error */ 203 #define HAL_HASH_ERROR_BUSY 0x00000001U /*!< Busy flag error */ 204 #define HAL_HASH_ERROR_DMA 0x00000002U /*!< DMA-based process error */ 205 #define HAL_HASH_ERROR_TIMEOUT 0x00000004U /*!< Timeout error */ 206 #if (USE_HAL_HASH_REGISTER_CALLBACKS == 1U) 207 #define HAL_HASH_ERROR_INVALID_CALLBACK 0x00000010U /*!< Invalid Callback error */ 208 #endif /* USE_HAL_HASH_REGISTER_CALLBACKS */ 209 /** 210 * @} 211 */ 212 213 /** @defgroup HASH_Algorithm_Selection HASH algorithm selection 214 * @{ 215 */ 216 #define HASH_ALGOSELECTION_SHA1 0x00000000U /*!< HASH function is SHA1 */ 217 #define HASH_ALGOSELECTION_SHA224 HASH_CR_ALGO_1 /*!< HASH function is SHA224 */ 218 #define HASH_ALGOSELECTION_SHA256 (HASH_CR_ALGO_0 | HASH_CR_ALGO_1) /*!< HASH function is SHA256 */ 219 #if defined (HASH_CR_ALGO_2) 220 #define HASH_ALGOSELECTION_SHA384 (HASH_CR_ALGO_2 | HASH_CR_ALGO_3) /*!< HASH function is SHA384 */ 221 #define HASH_ALGOSELECTION_SHA512_224 (HASH_CR_ALGO_0 | HASH_CR_ALGO_2 | HASH_CR_ALGO_3) 222 /*!< HASH function is SHA512_224 */ 223 #define HASH_ALGOSELECTION_SHA512_256 (HASH_CR_ALGO_1 | HASH_CR_ALGO_2 | HASH_CR_ALGO_3) 224 /*!< HASH function is SHA512_256 */ 225 #define HASH_ALGOSELECTION_SHA512 HASH_CR_ALGO /*!< HASH function is SHA512 */ 226 #endif /* defined (HASH_CR_ALGO_2) */ 227 /** 228 * @} 229 */ 230 231 /** @defgroup HASH_Mode HASH Mode 232 * @{ 233 */ 234 #define HASH_ALGOMODE_HASH 0x00000000U /*!< HASH mode */ 235 #define HASH_ALGOMODE_HMAC HASH_CR_MODE /*!< HMAC mode */ 236 /** 237 * @} 238 */ 239 240 /** @defgroup HASH_Data_Type HASH Data Type 241 * @{ 242 */ 243 #define HASH_NO_SWAP 0x00000000U /*!< 32-bit data. No swapping */ 244 #define HASH_HALFWORD_SWAP HASH_CR_DATATYPE_0 /*!< 16-bit data. Each half word is swapped */ 245 #define HASH_BYTE_SWAP HASH_CR_DATATYPE_1 /*!< 8-bit data. All bytes are swapped */ 246 #define HASH_BIT_SWAP HASH_CR_DATATYPE /*!< 1-bit data. In the word all bits are swapped */ 247 /** 248 * @} 249 */ 250 251 /** @defgroup HASH_HMAC_KEY key length only for HMAC mode 252 * @{ 253 */ 254 #define HASH_SHORTKEY 0x00000000U /*!< HMAC Key size is <= block size (64 or 128 bytes) */ 255 #define HASH_LONGKEY HASH_CR_LKEY /*!< HMAC Key size is > block size (64 or 128 bytes) */ 256 /** 257 * @} 258 */ 259 260 /** @defgroup HASH_flags_definition HASH flags definitions 261 * @{ 262 */ 263 #define HASH_FLAG_DINIS HASH_SR_DINIS /*!< 16 locations are free in the DIN : new block can be entered 264 in the Peripheral */ 265 #define HASH_FLAG_DCIS HASH_SR_DCIS /*!< Digest calculation complete */ 266 #define HASH_FLAG_DMAS HASH_SR_DMAS /*!< DMA interface is enabled (DMAE=1) or a transfer is ongoing */ 267 #define HASH_FLAG_BUSY HASH_SR_BUSY /*!< The hash core is Busy, processing a block of data */ 268 #define HASH_FLAG_DINNE HASH_CR_DINNE /*!< DIN not empty : input buffer contains at least one word of data*/ 269 /** 270 * @} 271 */ 272 273 /** @defgroup HASH_interrupts_definition HASH interrupts definitions 274 * @{ 275 */ 276 #define HASH_IT_DINI HASH_IMR_DINIE /*!< A new block can be entered into the input buffer (DIN) */ 277 #define HASH_IT_DCI HASH_IMR_DCIE /*!< Digest calculation complete */ 278 279 /** 280 * @} 281 */ 282 283 /** 284 * @} 285 */ 286 287 /* Exported macros -----------------------------------------------------------*/ 288 /** @defgroup HASH_Exported_Macros HASH Exported Macros 289 * @{ 290 */ 291 292 /** @brief Check whether or not the specified HASH flag is set. 293 * @param __HANDLE__ specifies the HASH handle. 294 * @param __FLAG__ specifies the flag to check. 295 * This parameter can be one of the following values: 296 * @arg @ref HASH_FLAG_DINIS A new block can be entered into the input buffer. 297 * @arg @ref HASH_FLAG_DCIS Digest calculation complete. 298 * @arg @ref HASH_FLAG_DMAS DMA interface is enabled (DMAE=1) or a transfer is ongoing. 299 * @arg @ref HASH_FLAG_BUSY The hash core is Busy : processing a block of data. 300 * @arg @ref HASH_FLAG_DINNE DIN not empty : the input buffer contains at least one word of data. 301 * @retval The new state of __FLAG__ (TRUE or FALSE). 302 */ 303 #define __HAL_HASH_GET_FLAG(__HANDLE__, __FLAG__) (((__FLAG__) > 8U) ? \ 304 (((__HANDLE__)->Instance->CR & (__FLAG__)) == (__FLAG__)) :\ 305 (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__)) ) 306 307 /** @brief Clear the specified HASH flag. 308 * @param __HANDLE__ specifies the HASH handle. 309 * @param __FLAG__ specifies the flag to clear. 310 * This parameter can be one of the following values: 311 * @arg @ref HASH_FLAG_DINIS A new block can be entered into the input buffer. 312 * @arg @ref HASH_FLAG_DCIS Digest calculation complete 313 * @retval None 314 */ 315 #define __HAL_HASH_CLEAR_FLAG(__HANDLE__, __FLAG__) CLEAR_BIT((__HANDLE__)->Instance->SR, (__FLAG__)) 316 317 /** @brief Check whether the specified HASH interrupt source is enabled or not. 318 * @param __HANDLE__ specifies the HASH handle. 319 * @param __INTERRUPT__ HASH interrupt source to check 320 * This parameter can be one of the following values : 321 * @arg @ref HASH_IT_DINI A new block can be entered into the input buffer (DIN) 322 * @arg @ref HASH_IT_DCI Digest calculation complete 323 * @retval State of interruption (TRUE or FALSE). 324 */ 325 #define __HAL_HASH_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->IMR\ 326 & (__INTERRUPT__)) == (__INTERRUPT__)) 327 328 /** @brief Enable the specified HASH interrupt. 329 * @param __HANDLE__ specifies the HASH handle. 330 * @param __INTERRUPT__ specifies the HASH interrupt source to enable. 331 * This parameter can be one of the following values: 332 * @arg @ref HASH_IT_DINI A new block can be entered into the input buffer (DIN) 333 * @arg @ref HASH_IT_DCI Digest calculation complete 334 * @retval None 335 */ 336 #define __HAL_HASH_ENABLE_IT(__HANDLE__, __INTERRUPT__) SET_BIT((__HANDLE__)->Instance->IMR, (__INTERRUPT__)) 337 338 /** @brief Disable the specified HASH interrupt. 339 * @param __HANDLE__ specifies the HASH handle. 340 * @param __INTERRUPT__ specifies the HASH interrupt source to disable. 341 * This parameter can be one of the following values: 342 * @arg @ref HASH_IT_DINI A new block can be entered into the input buffer (DIN) 343 * @arg @ref HASH_IT_DCI Digest calculation complete 344 * @retval None 345 */ 346 #define __HAL_HASH_DISABLE_IT(__HANDLE__, __INTERRUPT__) CLEAR_BIT((__HANDLE__)->Instance->IMR, (__INTERRUPT__)) 347 348 /** @brief Reset HASH handle state. 349 * @param __HANDLE__ HASH handle. 350 * @retval None 351 */ 352 #if (USE_HAL_HASH_REGISTER_CALLBACKS == 1) 353 #define __HAL_HASH_RESET_HANDLE_STATE(__HANDLE__) do{\ 354 (__HANDLE__)->State = HAL_HASH_STATE_RESET;\ 355 (__HANDLE__)->MspInitCallback = NULL; \ 356 (__HANDLE__)->MspDeInitCallback = NULL; \ 357 }while(0) 358 #else 359 #define __HAL_HASH_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_HASH_STATE_RESET) 360 #endif /* USE_HAL_HASH_REGISTER_CALLBACKS */ 361 362 /** 363 * @brief Enable the multi-buffer DMA transfer mode. 364 * @note This bit is set when hashing large files when multiple DMA transfers are needed. 365 * @retval None 366 */ 367 #define __HAL_HASH_SET_MDMAT() SET_BIT(HASH->CR, HASH_CR_MDMAT) 368 369 /** 370 * @brief Disable the multi-buffer DMA transfer mode. 371 * @retval None 372 */ 373 #define __HAL_HASH_RESET_MDMAT() CLEAR_BIT(HASH->CR, HASH_CR_MDMAT) 374 375 /** 376 * @brief HAL HASH driver version. 377 * @retval None 378 */ 379 #define HAL_HASH_VERSION 200 /*!< HAL HASH driver version 2.0.0*/ 380 381 /** 382 * @} 383 */ 384 385 /* Exported functions --------------------------------------------------------*/ 386 387 /** @addtogroup HASH_Exported_Functions HASH Exported Functions 388 * @{ 389 */ 390 391 /** @addtogroup HASH_Exported_Functions_Group1 Initialization and de-initialization functions 392 * @{ 393 */ 394 HAL_StatusTypeDef HAL_HASH_Init(HASH_HandleTypeDef *hhash); 395 HAL_StatusTypeDef HAL_HASH_DeInit(HASH_HandleTypeDef *hhash); 396 void HAL_HASH_MspInit(HASH_HandleTypeDef *hhash); 397 void HAL_HASH_MspDeInit(HASH_HandleTypeDef *hhash); 398 HAL_StatusTypeDef HAL_HASH_GetConfig(HASH_HandleTypeDef *hhash, HASH_ConfigTypeDef *pConf); 399 HAL_StatusTypeDef HAL_HASH_SetConfig(HASH_HandleTypeDef *hhash, HASH_ConfigTypeDef *pConf); 400 401 /* Callbacks Register/UnRegister functions ***********************************/ 402 #if (USE_HAL_HASH_REGISTER_CALLBACKS == 1) 403 HAL_StatusTypeDef HAL_HASH_RegisterCallback(HASH_HandleTypeDef *hhash, HAL_HASH_CallbackIDTypeDef CallbackID, 404 pHASH_CallbackTypeDef pCallback); 405 HAL_StatusTypeDef HAL_HASH_UnRegisterCallback(HASH_HandleTypeDef *hhash, HAL_HASH_CallbackIDTypeDef CallbackID); 406 #endif /* USE_HAL_HASH_REGISTER_CALLBACKS */ 407 408 HAL_StatusTypeDef HAL_HASH_ProcessSuspend(HASH_HandleTypeDef *hhash); 409 void HAL_HASH_Resume(HASH_HandleTypeDef *hhash, uint8_t *pMemBuffer); 410 void HAL_HASH_Suspend(HASH_HandleTypeDef *hhash, uint8_t *pMemBuffer); 411 /** 412 * @} 413 */ 414 415 /** @addtogroup HASH_Exported_Functions_Group2 HASH processing functions 416 * @{ 417 */ 418 419 HAL_StatusTypeDef HAL_HASH_Start(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size, 420 uint8_t *const pOutBuffer, 421 uint32_t Timeout); 422 HAL_StatusTypeDef HAL_HASH_Start_IT(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size, 423 uint8_t *const pOutBuffer); 424 HAL_StatusTypeDef HAL_HASH_Start_DMA(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size, 425 uint8_t *const pOutBuffer); 426 427 HAL_StatusTypeDef HAL_HASH_Accumulate(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size, 428 uint32_t Timeout); 429 HAL_StatusTypeDef HAL_HASH_AccumulateLast(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size, 430 uint8_t *const pOutBuffer, 431 uint32_t Timeout); 432 HAL_StatusTypeDef HAL_HASH_AccumulateLast_IT(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size, 433 uint8_t *const pOutBuffer); 434 HAL_StatusTypeDef HAL_HASH_Accumulate_IT(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size); 435 436 /** 437 * @} 438 */ 439 440 /** @addtogroup HASH_Exported_Functions_Group3 HMAC processing functions in interrupt mode 441 * @{ 442 */ 443 HAL_StatusTypeDef HAL_HASH_HMAC_Start(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size, 444 uint8_t *const pOutBuffer, 445 uint32_t Timeout); 446 HAL_StatusTypeDef HAL_HASH_HMAC_Start_DMA(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size, 447 uint8_t *const pOutBuffer); 448 HAL_StatusTypeDef HAL_HASH_HMAC_Start_IT(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size, 449 uint8_t *const pOutBuffer); 450 451 HAL_StatusTypeDef HAL_HASH_HMAC_Accumulate(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size, 452 uint32_t Timeout); 453 HAL_StatusTypeDef HAL_HASH_HMAC_AccumulateLast(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size, 454 uint8_t *const pOutBuffer, uint32_t Timeout); 455 HAL_StatusTypeDef HAL_HASH_HMAC_Accumulate_IT(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size); 456 HAL_StatusTypeDef HAL_HASH_HMAC_AccumulateLast_IT(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, 457 uint32_t Size, uint8_t *const pOutBuffer); 458 459 /** 460 * @} 461 */ 462 463 /** @addtogroup HASH_Exported_Functions_Group4 HASH IRQ handler management 464 * @{ 465 */ 466 void HAL_HASH_IRQHandler(HASH_HandleTypeDef *hhash); 467 void HAL_HASH_InCpltCallback(HASH_HandleTypeDef *hhash); 468 void HAL_HASH_DgstCpltCallback(HASH_HandleTypeDef *hhash); 469 void HAL_HASH_ErrorCallback(HASH_HandleTypeDef *hhash); 470 HAL_HASH_StateTypeDef HAL_HASH_GetState(HASH_HandleTypeDef *hhash); 471 uint32_t HAL_HASH_GetError(HASH_HandleTypeDef *hhash); 472 473 /** 474 * @} 475 */ 476 477 /** 478 * @} 479 */ 480 481 /* Private macros --------------------------------------------------------*/ 482 /** @defgroup HASH_Private_Macros HASH Private Macros 483 * @{ 484 */ 485 486 /** 487 * @brief Return digest length in bytes. 488 * @retval Digest length 489 */ 490 #if defined(HASH_ALGOSELECTION_SHA512) 491 #define HASH_DIGEST_LENGTH(__HANDLE__) (((READ_BIT((__HANDLE__)->Instance->CR, HASH_CR_ALGO) \ 492 == HASH_ALGOSELECTION_SHA1) ? 20U : \ 493 ((READ_BIT((__HANDLE__)->Instance->CR, HASH_CR_ALGO) \ 494 == HASH_ALGOSELECTION_SHA224) ? 28U : \ 495 ((READ_BIT((__HANDLE__)->Instance->CR, HASH_CR_ALGO) \ 496 == HASH_ALGOSELECTION_SHA256) ? 32U : \ 497 ((READ_BIT((__HANDLE__)->Instance->CR, HASH_CR_ALGO) \ 498 == HASH_ALGOSELECTION_SHA384) ? 48U : \ 499 ((READ_BIT((__HANDLE__)->Instance->CR, HASH_CR_ALGO) \ 500 == HASH_ALGOSELECTION_SHA512_224) ? 28U : \ 501 ((READ_BIT((__HANDLE__)->Instance->CR, HASH_CR_ALGO) \ 502 == HASH_ALGOSELECTION_SHA512_256) ? 32U : \ 503 ((READ_BIT((__HANDLE__)->Instance->CR, HASH_CR_ALGO) \ 504 == HASH_ALGOSELECTION_SHA512) ? 64U : 20U ) ) )))))) 505 #else 506 #define HASH_DIGEST_LENGTH(__HANDLE__) (((READ_BIT((__HANDLE__)->Instance->CR, HASH_CR_ALGO) \ 507 == HASH_ALGOSELECTION_SHA1) ? 20U : \ 508 ((READ_BIT((__HANDLE__)->Instance->CR, HASH_CR_ALGO) \ 509 == HASH_ALGOSELECTION_SHA224) ? 28U : \ 510 ((READ_BIT((__HANDLE__)->Instance->CR, HASH_CR_ALGO) \ 511 == HASH_ALGOSELECTION_SHA256) ? 32U :20U)))) 512 #endif /* HASH_ALGOSELECTION_SHA512 */ 513 514 /** 515 * @brief Ensure that HASH input data type is valid. 516 * @param __DATATYPE__ HASH input data type. 517 * @retval SET (__DATATYPE__ is valid) or RESET (__DATATYPE__ is invalid) 518 */ 519 #define IS_HASH_DATATYPE(__DATATYPE__) (((__DATATYPE__) == HASH_NO_SWAP)|| \ 520 ((__DATATYPE__) == HASH_HALFWORD_SWAP)|| \ 521 ((__DATATYPE__) == HASH_BYTE_SWAP) || \ 522 ((__DATATYPE__) == HASH_BIT_SWAP)) 523 524 /** 525 * @brief Ensure that HASH input algorithm is valid. 526 * @param __ALGORITHM__ HASH algorithm. 527 * @retval SET (__ALGORITHM__ is valid) or RESET (__ALGORITHM__ is invalid) 528 */ 529 #if defined(HASH_ALGOSELECTION_SHA512) 530 #define IS_HASH_ALGORITHM(__ALGORITHM__) (((__ALGORITHM__) == HASH_ALGOSELECTION_SHA1)|| \ 531 ((__ALGORITHM__) == HASH_ALGOSELECTION_SHA224)|| \ 532 ((__ALGORITHM__) == HASH_ALGOSELECTION_SHA256)|| \ 533 ((__ALGORITHM__) == HASH_ALGOSELECTION_SHA384)|| \ 534 ((__ALGORITHM__) == HASH_ALGOSELECTION_SHA512_224)|| \ 535 ((__ALGORITHM__) == HASH_ALGOSELECTION_SHA512_256)|| \ 536 ((__ALGORITHM__) == HASH_ALGOSELECTION_SHA512)) 537 #else 538 #define IS_HASH_ALGORITHM(__ALGORITHM__) (((__ALGORITHM__) == HASH_ALGOSELECTION_SHA1)|| \ 539 ((__ALGORITHM__) == HASH_ALGOSELECTION_SHA224)|| \ 540 ((__ALGORITHM__) == HASH_ALGOSELECTION_SHA256)) 541 #endif /* HASH_ALGOSELECTION_SHA512 */ 542 543 /** 544 * @} 545 */ 546 547 /* Private constants ---------------------------------------------------------*/ 548 /** @defgroup HASH_Private_Constants HASH Private Constants 549 * @{ 550 */ 551 552 /** 553 * @} 554 */ 555 /* Private defines -----------------------------------------------------------*/ 556 /** @defgroup HASH_Private_Defines HASH Private Defines 557 * @{ 558 */ 559 560 /** 561 * @} 562 */ 563 564 /* Private variables ---------------------------------------------------------*/ 565 /** @defgroup HASH_Private_Variables HASH Private Variables 566 * @{ 567 */ 568 569 /** 570 * @} 571 */ 572 /* Private functions -----------------------------------------------------------*/ 573 574 /** @addtogroup HASH_Private_Functions HASH Private Functions 575 * @{ 576 */ 577 578 /** 579 * @} 580 */ 581 582 /** 583 * @} 584 */ 585 #endif /* HASH*/ 586 /** 587 * @} 588 */ 589 590 591 #ifdef __cplusplus 592 } 593 #endif 594 595 596 #endif /* STM32H5xx_HAL_HASH_H */ 597