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) 2023 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__ (SET or RESET). 302 */ 303 #define __HAL_HASH_GET_FLAG(__HANDLE__, __FLAG__) (((__FLAG__) > 8U) ? \ 304 ((((__HANDLE__)->Instance->CR & (__FLAG__)) == \ 305 (__FLAG__)) ? SET : RESET) : \ 306 ((((__HANDLE__)->Instance->SR & (__FLAG__)) == \ 307 (__FLAG__)) ? SET : RESET) ) 308 309 /** @brief Clear the specified HASH flag. 310 * @param __HANDLE__ specifies the HASH handle. 311 * @param __FLAG__ specifies the flag to clear. 312 * This parameter can be one of the following values: 313 * @arg @ref HASH_FLAG_DINIS A new block can be entered into the input buffer. 314 * @arg @ref HASH_FLAG_DCIS Digest calculation complete 315 * @retval None 316 */ 317 #define __HAL_HASH_CLEAR_FLAG(__HANDLE__, __FLAG__) CLEAR_BIT((__HANDLE__)->Instance->SR, (__FLAG__)) 318 319 /** @brief Check whether the specified HASH interrupt source is enabled or not. 320 * @param __HANDLE__ specifies the HASH handle. 321 * @param __INTERRUPT__ HASH interrupt source to check 322 * This parameter can be one of the following values : 323 * @arg @ref HASH_IT_DINI A new block can be entered into the input buffer (DIN) 324 * @arg @ref HASH_IT_DCI Digest calculation complete 325 * @retval State of interruption (TRUE or FALSE). 326 */ 327 #define __HAL_HASH_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->IMR\ 328 & (__INTERRUPT__)) == (__INTERRUPT__)) 329 330 /** @brief Enable the specified HASH interrupt. 331 * @param __HANDLE__ specifies the HASH handle. 332 * @param __INTERRUPT__ specifies the HASH interrupt source to enable. 333 * This parameter can be one of the following values: 334 * @arg @ref HASH_IT_DINI A new block can be entered into the input buffer (DIN) 335 * @arg @ref HASH_IT_DCI Digest calculation complete 336 * @retval None 337 */ 338 #define __HAL_HASH_ENABLE_IT(__HANDLE__, __INTERRUPT__) SET_BIT((__HANDLE__)->Instance->IMR, (__INTERRUPT__)) 339 340 /** @brief Disable the specified HASH interrupt. 341 * @param __HANDLE__ specifies the HASH handle. 342 * @param __INTERRUPT__ specifies the HASH interrupt source to disable. 343 * This parameter can be one of the following values: 344 * @arg @ref HASH_IT_DINI A new block can be entered into the input buffer (DIN) 345 * @arg @ref HASH_IT_DCI Digest calculation complete 346 * @retval None 347 */ 348 #define __HAL_HASH_DISABLE_IT(__HANDLE__, __INTERRUPT__) CLEAR_BIT((__HANDLE__)->Instance->IMR, (__INTERRUPT__)) 349 350 /** @brief Reset HASH handle state. 351 * @param __HANDLE__ HASH handle. 352 * @retval None 353 */ 354 #if (USE_HAL_HASH_REGISTER_CALLBACKS == 1) 355 #define __HAL_HASH_RESET_HANDLE_STATE(__HANDLE__) do{\ 356 (__HANDLE__)->State = HAL_HASH_STATE_RESET;\ 357 (__HANDLE__)->MspInitCallback = NULL; \ 358 (__HANDLE__)->MspDeInitCallback = NULL; \ 359 }while(0) 360 #else 361 #define __HAL_HASH_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_HASH_STATE_RESET) 362 #endif /* USE_HAL_HASH_REGISTER_CALLBACKS */ 363 364 /** 365 * @brief Enable the multi-buffer DMA transfer mode. 366 * @note This bit is set when hashing large files when multiple DMA transfers are needed. 367 * @retval None 368 */ 369 #define __HAL_HASH_SET_MDMAT() SET_BIT(HASH->CR, HASH_CR_MDMAT) 370 371 /** 372 * @brief Disable the multi-buffer DMA transfer mode. 373 * @retval None 374 */ 375 #define __HAL_HASH_RESET_MDMAT() CLEAR_BIT(HASH->CR, HASH_CR_MDMAT) 376 377 /** 378 * @brief HAL HASH driver version. 379 * @retval None 380 */ 381 #define HAL_HASH_VERSION 200 /*!< HAL HASH driver version 2.0.0*/ 382 383 /** 384 * @} 385 */ 386 387 /* Exported functions --------------------------------------------------------*/ 388 389 /** @addtogroup HASH_Exported_Functions HASH Exported Functions 390 * @{ 391 */ 392 393 /** @addtogroup HASH_Exported_Functions_Group1 Initialization and de-initialization functions 394 * @{ 395 */ 396 HAL_StatusTypeDef HAL_HASH_Init(HASH_HandleTypeDef *hhash); 397 HAL_StatusTypeDef HAL_HASH_DeInit(HASH_HandleTypeDef *hhash); 398 void HAL_HASH_MspInit(HASH_HandleTypeDef *hhash); 399 void HAL_HASH_MspDeInit(HASH_HandleTypeDef *hhash); 400 HAL_StatusTypeDef HAL_HASH_GetConfig(HASH_HandleTypeDef *hhash, HASH_ConfigTypeDef *pConf); 401 HAL_StatusTypeDef HAL_HASH_SetConfig(HASH_HandleTypeDef *hhash, HASH_ConfigTypeDef *pConf); 402 403 /* Callbacks Register/UnRegister functions ***********************************/ 404 #if (USE_HAL_HASH_REGISTER_CALLBACKS == 1) 405 HAL_StatusTypeDef HAL_HASH_RegisterCallback(HASH_HandleTypeDef *hhash, HAL_HASH_CallbackIDTypeDef CallbackID, 406 pHASH_CallbackTypeDef pCallback); 407 HAL_StatusTypeDef HAL_HASH_UnRegisterCallback(HASH_HandleTypeDef *hhash, HAL_HASH_CallbackIDTypeDef CallbackID); 408 #endif /* USE_HAL_HASH_REGISTER_CALLBACKS */ 409 410 HAL_StatusTypeDef HAL_HASH_ProcessSuspend(HASH_HandleTypeDef *hhash); 411 void HAL_HASH_Resume(HASH_HandleTypeDef *hhash, uint8_t *pMemBuffer); 412 void HAL_HASH_Suspend(HASH_HandleTypeDef *hhash, uint8_t *pMemBuffer); 413 /** 414 * @} 415 */ 416 417 /** @addtogroup HASH_Exported_Functions_Group2 HASH processing functions 418 * @{ 419 */ 420 421 HAL_StatusTypeDef HAL_HASH_Start(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size, 422 uint8_t *const pOutBuffer, 423 uint32_t Timeout); 424 HAL_StatusTypeDef HAL_HASH_Start_IT(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size, 425 uint8_t *const pOutBuffer); 426 HAL_StatusTypeDef HAL_HASH_Start_DMA(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size, 427 uint8_t *const pOutBuffer); 428 429 HAL_StatusTypeDef HAL_HASH_Accumulate(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size, 430 uint32_t Timeout); 431 HAL_StatusTypeDef HAL_HASH_AccumulateLast(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size, 432 uint8_t *const pOutBuffer, 433 uint32_t Timeout); 434 HAL_StatusTypeDef HAL_HASH_AccumulateLast_IT(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size, 435 uint8_t *const pOutBuffer); 436 HAL_StatusTypeDef HAL_HASH_Accumulate_IT(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size); 437 438 /** 439 * @} 440 */ 441 442 /** @addtogroup HASH_Exported_Functions_Group3 HMAC processing functions 443 * @{ 444 */ 445 HAL_StatusTypeDef HAL_HASH_HMAC_Start(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size, 446 uint8_t *const pOutBuffer, 447 uint32_t Timeout); 448 HAL_StatusTypeDef HAL_HASH_HMAC_Start_DMA(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size, 449 uint8_t *const pOutBuffer); 450 HAL_StatusTypeDef HAL_HASH_HMAC_Start_IT(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size, 451 uint8_t *const pOutBuffer); 452 453 HAL_StatusTypeDef HAL_HASH_HMAC_Accumulate(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size, 454 uint32_t Timeout); 455 HAL_StatusTypeDef HAL_HASH_HMAC_AccumulateLast(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size, 456 uint8_t *const pOutBuffer, uint32_t Timeout); 457 HAL_StatusTypeDef HAL_HASH_HMAC_Accumulate_IT(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size); 458 HAL_StatusTypeDef HAL_HASH_HMAC_AccumulateLast_IT(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, 459 uint32_t Size, uint8_t *const pOutBuffer); 460 461 /** 462 * @} 463 */ 464 465 /** @addtogroup HASH_Exported_Functions_Group4 HASH IRQ handler management 466 * @{ 467 */ 468 void HAL_HASH_IRQHandler(HASH_HandleTypeDef *hhash); 469 void HAL_HASH_InCpltCallback(HASH_HandleTypeDef *hhash); 470 void HAL_HASH_DgstCpltCallback(HASH_HandleTypeDef *hhash); 471 void HAL_HASH_ErrorCallback(HASH_HandleTypeDef *hhash); 472 HAL_HASH_StateTypeDef HAL_HASH_GetState(const HASH_HandleTypeDef *hhash); 473 uint32_t HAL_HASH_GetError(const HASH_HandleTypeDef *hhash); 474 475 /** 476 * @} 477 */ 478 479 /** 480 * @} 481 */ 482 483 /* Private macros --------------------------------------------------------*/ 484 /** @defgroup HASH_Private_Macros HASH Private Macros 485 * @{ 486 */ 487 488 /** 489 * @brief Return digest length in bytes. 490 * @retval Digest length 491 */ 492 #if defined(HASH_ALGOSELECTION_SHA512) 493 #define HASH_DIGEST_LENGTH(__HANDLE__) (((READ_BIT((__HANDLE__)->Instance->CR, HASH_CR_ALGO) \ 494 == HASH_ALGOSELECTION_SHA1) ? 20U : \ 495 ((READ_BIT((__HANDLE__)->Instance->CR, HASH_CR_ALGO) \ 496 == HASH_ALGOSELECTION_SHA224) ? 28U : \ 497 ((READ_BIT((__HANDLE__)->Instance->CR, HASH_CR_ALGO) \ 498 == HASH_ALGOSELECTION_SHA256) ? 32U : \ 499 ((READ_BIT((__HANDLE__)->Instance->CR, HASH_CR_ALGO) \ 500 == HASH_ALGOSELECTION_SHA384) ? 48U : \ 501 ((READ_BIT((__HANDLE__)->Instance->CR, HASH_CR_ALGO) \ 502 == HASH_ALGOSELECTION_SHA512_224) ? 28U : \ 503 ((READ_BIT((__HANDLE__)->Instance->CR, HASH_CR_ALGO) \ 504 == HASH_ALGOSELECTION_SHA512_256) ? 32U : \ 505 ((READ_BIT((__HANDLE__)->Instance->CR, HASH_CR_ALGO) \ 506 == HASH_ALGOSELECTION_SHA512) ? 64U : 20U ) ) )))))) 507 #else 508 #define HASH_DIGEST_LENGTH(__HANDLE__) (((READ_BIT((__HANDLE__)->Instance->CR, HASH_CR_ALGO) \ 509 == HASH_ALGOSELECTION_SHA1) ? 20U : \ 510 ((READ_BIT((__HANDLE__)->Instance->CR, HASH_CR_ALGO) \ 511 == HASH_ALGOSELECTION_SHA224) ? 28U : \ 512 ((READ_BIT((__HANDLE__)->Instance->CR, HASH_CR_ALGO) \ 513 == HASH_ALGOSELECTION_SHA256) ? 32U :20U)))) 514 #endif /* HASH_ALGOSELECTION_SHA512 */ 515 516 /** 517 * @brief Ensure that HASH input data type is valid. 518 * @param __DATATYPE__ HASH input data type. 519 * @retval SET (__DATATYPE__ is valid) or RESET (__DATATYPE__ is invalid) 520 */ 521 #define IS_HASH_DATATYPE(__DATATYPE__) (((__DATATYPE__) == HASH_NO_SWAP)|| \ 522 ((__DATATYPE__) == HASH_HALFWORD_SWAP)|| \ 523 ((__DATATYPE__) == HASH_BYTE_SWAP) || \ 524 ((__DATATYPE__) == HASH_BIT_SWAP)) 525 526 /** 527 * @brief Ensure that HASH input algorithm is valid. 528 * @param __ALGORITHM__ HASH algorithm. 529 * @retval SET (__ALGORITHM__ is valid) or RESET (__ALGORITHM__ is invalid) 530 */ 531 #if defined(HASH_ALGOSELECTION_SHA512) 532 #define IS_HASH_ALGORITHM(__ALGORITHM__) (((__ALGORITHM__) == HASH_ALGOSELECTION_SHA1)|| \ 533 ((__ALGORITHM__) == HASH_ALGOSELECTION_SHA224)|| \ 534 ((__ALGORITHM__) == HASH_ALGOSELECTION_SHA256)|| \ 535 ((__ALGORITHM__) == HASH_ALGOSELECTION_SHA384)|| \ 536 ((__ALGORITHM__) == HASH_ALGOSELECTION_SHA512_224)|| \ 537 ((__ALGORITHM__) == HASH_ALGOSELECTION_SHA512_256)|| \ 538 ((__ALGORITHM__) == HASH_ALGOSELECTION_SHA512)) 539 #else 540 #define IS_HASH_ALGORITHM(__ALGORITHM__) (((__ALGORITHM__) == HASH_ALGOSELECTION_SHA1)|| \ 541 ((__ALGORITHM__) == HASH_ALGOSELECTION_SHA224)|| \ 542 ((__ALGORITHM__) == HASH_ALGOSELECTION_SHA256)) 543 #endif /* HASH_ALGOSELECTION_SHA512 */ 544 545 /** 546 * @} 547 */ 548 549 /* Private constants ---------------------------------------------------------*/ 550 /** @defgroup HASH_Private_Constants HASH Private Constants 551 * @{ 552 */ 553 554 /** 555 * @} 556 */ 557 /* Private defines -----------------------------------------------------------*/ 558 /** @defgroup HASH_Private_Defines HASH Private Defines 559 * @{ 560 */ 561 562 /** 563 * @} 564 */ 565 566 /* Private variables ---------------------------------------------------------*/ 567 /** @defgroup HASH_Private_Variables HASH Private Variables 568 * @{ 569 */ 570 571 /** 572 * @} 573 */ 574 /* Private functions -----------------------------------------------------------*/ 575 576 /** @addtogroup HASH_Private_Functions HASH Private Functions 577 * @{ 578 */ 579 580 /** 581 * @} 582 */ 583 584 /** 585 * @} 586 */ 587 #endif /* HASH*/ 588 /** 589 * @} 590 */ 591 592 593 #ifdef __cplusplus 594 } 595 #endif 596 597 598 #endif /* STM32H5xx_HAL_HASH_H */ 599