1 /** 2 ****************************************************************************** 3 * @file stm32h7rsxx_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 STM32H7RSxx_HAL_HASH_H 21 #define STM32H7RSxx_HAL_HASH_H 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /* Includes ------------------------------------------------------------------*/ 28 #include "stm32h7rsxx_hal_def.h" 29 30 /** @addtogroup STM32H7RSxx_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 #define HASH_ALGOSELECTION_SHA384 (HASH_CR_ALGO_2 | HASH_CR_ALGO_3) /*!< HASH function is SHA384 */ 220 #define HASH_ALGOSELECTION_SHA512_224 (HASH_CR_ALGO_0 | HASH_CR_ALGO_2 | HASH_CR_ALGO_3) 221 /*!< HASH function is SHA512_224 */ 222 #define HASH_ALGOSELECTION_SHA512_256 (HASH_CR_ALGO_1 | HASH_CR_ALGO_2 | HASH_CR_ALGO_3) 223 /*!< HASH function is SHA512_256 */ 224 #define HASH_ALGOSELECTION_SHA512 HASH_CR_ALGO /*!< HASH function is SHA512 */ 225 /** 226 * @} 227 */ 228 229 /** @defgroup HASH_Mode HASH Mode 230 * @{ 231 */ 232 #define HASH_ALGOMODE_HASH 0x00000000U /*!< HASH mode */ 233 #define HASH_ALGOMODE_HMAC HASH_CR_MODE /*!< HMAC mode */ 234 /** 235 * @} 236 */ 237 238 /** @defgroup HASH_Data_Type HASH Data Type 239 * @{ 240 */ 241 #define HASH_NO_SWAP 0x00000000U /*!< 32-bit data. No swapping */ 242 #define HASH_HALFWORD_SWAP HASH_CR_DATATYPE_0 /*!< 16-bit data. Each half word is swapped */ 243 #define HASH_BYTE_SWAP HASH_CR_DATATYPE_1 /*!< 8-bit data. All bytes are swapped */ 244 #define HASH_BIT_SWAP HASH_CR_DATATYPE /*!< 1-bit data. In the word all bits are swapped */ 245 /** 246 * @} 247 */ 248 249 /** @defgroup HASH_HMAC_KEY key length only for HMAC mode 250 * @{ 251 */ 252 #define HASH_SHORTKEY 0x00000000U /*!< HMAC Key size is <= block size (64 or 128 bytes) */ 253 #define HASH_LONGKEY HASH_CR_LKEY /*!< HMAC Key size is > block size (64 or 128 bytes) */ 254 /** 255 * @} 256 */ 257 258 /** @defgroup HASH_flags_definition HASH flags definitions 259 * @{ 260 */ 261 #define HASH_FLAG_DINIS HASH_SR_DINIS /*!< 16 locations are free in the DIN : new block can be entered 262 in the Peripheral */ 263 #define HASH_FLAG_DCIS HASH_SR_DCIS /*!< Digest calculation complete */ 264 #define HASH_FLAG_DMAS HASH_SR_DMAS /*!< DMA interface is enabled (DMAE=1) or a transfer is ongoing */ 265 #define HASH_FLAG_BUSY HASH_SR_BUSY /*!< The hash core is Busy, processing a block of data */ 266 #define HASH_FLAG_DINNE HASH_CR_DINNE /*!< DIN not empty : input buffer contains at least one word of data*/ 267 /** 268 * @} 269 */ 270 271 /** @defgroup HASH_interrupts_definition HASH interrupts definitions 272 * @{ 273 */ 274 #define HASH_IT_DINI HASH_IMR_DINIE /*!< A new block can be entered into the input buffer (DIN) */ 275 #define HASH_IT_DCI HASH_IMR_DCIE /*!< Digest calculation complete */ 276 277 /** 278 * @} 279 */ 280 281 /** 282 * @} 283 */ 284 285 /* Exported macros -----------------------------------------------------------*/ 286 /** @defgroup HASH_Exported_Macros HASH Exported Macros 287 * @{ 288 */ 289 290 /** @brief Check whether or not the specified HASH flag is set. 291 * @param __HANDLE__ specifies the HASH handle. 292 * @param __FLAG__ specifies the flag to check. 293 * This parameter can be one of the following values: 294 * @arg @ref HASH_FLAG_DINIS A new block can be entered into the input buffer. 295 * @arg @ref HASH_FLAG_DCIS Digest calculation complete. 296 * @arg @ref HASH_FLAG_DMAS DMA interface is enabled (DMAE=1) or a transfer is ongoing. 297 * @arg @ref HASH_FLAG_BUSY The hash core is Busy : processing a block of data. 298 * @arg @ref HASH_FLAG_DINNE DIN not empty : the input buffer contains at least one word of data. 299 * @retval The new state of __FLAG__ (TRUE or FALSE). 300 */ 301 #define __HAL_HASH_GET_FLAG(__HANDLE__, __FLAG__) (((__FLAG__) > 8U) ? \ 302 (((__HANDLE__)->Instance->CR & (__FLAG__)) == (__FLAG__)) :\ 303 (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__)) ) 304 305 /** @brief Clear the specified HASH flag. 306 * @param __HANDLE__ specifies the HASH handle. 307 * @param __FLAG__ specifies the flag to clear. 308 * This parameter can be one of the following values: 309 * @arg @ref HASH_FLAG_DINIS A new block can be entered into the input buffer. 310 * @arg @ref HASH_FLAG_DCIS Digest calculation complete 311 * @retval None 312 */ 313 #define __HAL_HASH_CLEAR_FLAG(__HANDLE__, __FLAG__) CLEAR_BIT((__HANDLE__)->Instance->SR, (__FLAG__)) 314 315 /** @brief Check whether the specified HASH interrupt source is enabled or not. 316 * @param __HANDLE__ specifies the HASH handle. 317 * @param __INTERRUPT__ HASH interrupt source to check 318 * This parameter can be one of the following values : 319 * @arg @ref HASH_IT_DINI A new block can be entered into the input buffer (DIN) 320 * @arg @ref HASH_IT_DCI Digest calculation complete 321 * @retval State of interruption (TRUE or FALSE). 322 */ 323 #define __HAL_HASH_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->IMR\ 324 & (__INTERRUPT__)) == (__INTERRUPT__)) 325 326 /** @brief Enable the specified HASH interrupt. 327 * @param __HANDLE__ specifies the HASH handle. 328 * @param __INTERRUPT__ specifies the HASH interrupt source to enable. 329 * This parameter can be one of the following values: 330 * @arg @ref HASH_IT_DINI A new block can be entered into the input buffer (DIN) 331 * @arg @ref HASH_IT_DCI Digest calculation complete 332 * @retval None 333 */ 334 #define __HAL_HASH_ENABLE_IT(__HANDLE__, __INTERRUPT__) SET_BIT((__HANDLE__)->Instance->IMR, (__INTERRUPT__)) 335 336 /** @brief Disable the specified HASH interrupt. 337 * @param __HANDLE__ specifies the HASH handle. 338 * @param __INTERRUPT__ specifies the HASH interrupt source to disable. 339 * This parameter can be one of the following values: 340 * @arg @ref HASH_IT_DINI A new block can be entered into the input buffer (DIN) 341 * @arg @ref HASH_IT_DCI Digest calculation complete 342 * @retval None 343 */ 344 #define __HAL_HASH_DISABLE_IT(__HANDLE__, __INTERRUPT__) CLEAR_BIT((__HANDLE__)->Instance->IMR, (__INTERRUPT__)) 345 346 /** @brief Reset HASH handle state. 347 * @param __HANDLE__ HASH handle. 348 * @retval None 349 */ 350 #if (USE_HAL_HASH_REGISTER_CALLBACKS == 1) 351 #define __HAL_HASH_RESET_HANDLE_STATE(__HANDLE__) do{\ 352 (__HANDLE__)->State = HAL_HASH_STATE_RESET;\ 353 (__HANDLE__)->MspInitCallback = NULL; \ 354 (__HANDLE__)->MspDeInitCallback = NULL; \ 355 }while(0) 356 #else 357 #define __HAL_HASH_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_HASH_STATE_RESET) 358 #endif /* USE_HAL_HASH_REGISTER_CALLBACKS */ 359 360 /** 361 * @brief Enable the multi-buffer DMA transfer mode. 362 * @note This bit is set when hashing large files when multiple DMA transfers are needed. 363 * @retval None 364 */ 365 #define __HAL_HASH_SET_MDMAT() SET_BIT(HASH->CR, HASH_CR_MDMAT) 366 367 /** 368 * @brief Disable the multi-buffer DMA transfer mode. 369 * @retval None 370 */ 371 #define __HAL_HASH_RESET_MDMAT() CLEAR_BIT(HASH->CR, HASH_CR_MDMAT) 372 373 /** 374 * @brief HAL HASH driver version. 375 * @retval None 376 */ 377 #define HAL_HASH_VERSION 200 /*!< HAL HASH driver version 2.0.0*/ 378 379 /** 380 * @} 381 */ 382 383 /* Exported functions --------------------------------------------------------*/ 384 385 /** @addtogroup HASH_Exported_Functions HASH Exported Functions 386 * @{ 387 */ 388 389 /** @addtogroup HASH_Exported_Functions_Group1 Initialization and de-initialization functions 390 * @{ 391 */ 392 HAL_StatusTypeDef HAL_HASH_Init(HASH_HandleTypeDef *hhash); 393 HAL_StatusTypeDef HAL_HASH_DeInit(HASH_HandleTypeDef *hhash); 394 void HAL_HASH_MspInit(HASH_HandleTypeDef *hhash); 395 void HAL_HASH_MspDeInit(HASH_HandleTypeDef *hhash); 396 HAL_StatusTypeDef HAL_HASH_GetConfig(HASH_HandleTypeDef *hhash, HASH_ConfigTypeDef *pConf); 397 HAL_StatusTypeDef HAL_HASH_SetConfig(HASH_HandleTypeDef *hhash, HASH_ConfigTypeDef *pConf); 398 399 /* Callbacks Register/UnRegister functions ***********************************/ 400 #if (USE_HAL_HASH_REGISTER_CALLBACKS == 1) 401 HAL_StatusTypeDef HAL_HASH_RegisterCallback(HASH_HandleTypeDef *hhash, HAL_HASH_CallbackIDTypeDef CallbackID, 402 pHASH_CallbackTypeDef pCallback); 403 HAL_StatusTypeDef HAL_HASH_UnRegisterCallback(HASH_HandleTypeDef *hhash, HAL_HASH_CallbackIDTypeDef CallbackID); 404 #endif /* USE_HAL_HASH_REGISTER_CALLBACKS */ 405 406 HAL_StatusTypeDef HAL_HASH_ProcessSuspend(HASH_HandleTypeDef *hhash); 407 void HAL_HASH_Resume(HASH_HandleTypeDef *hhash, uint8_t *pMemBuffer); 408 void HAL_HASH_Suspend(HASH_HandleTypeDef *hhash, uint8_t *pMemBuffer); 409 /** 410 * @} 411 */ 412 413 /** @addtogroup HASH_Exported_Functions_Group2 HASH processing functions 414 * @{ 415 */ 416 417 HAL_StatusTypeDef HAL_HASH_Start(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size, 418 uint8_t *const pOutBuffer, 419 uint32_t Timeout); 420 HAL_StatusTypeDef HAL_HASH_Start_IT(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size, 421 uint8_t *const pOutBuffer); 422 HAL_StatusTypeDef HAL_HASH_Start_DMA(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size, 423 uint8_t *const pOutBuffer); 424 425 HAL_StatusTypeDef HAL_HASH_Accumulate(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size, 426 uint32_t Timeout); 427 HAL_StatusTypeDef HAL_HASH_AccumulateLast(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size, 428 uint8_t *const pOutBuffer, 429 uint32_t Timeout); 430 HAL_StatusTypeDef HAL_HASH_AccumulateLast_IT(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size, 431 uint8_t *const pOutBuffer); 432 HAL_StatusTypeDef HAL_HASH_Accumulate_IT(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size); 433 434 /** 435 * @} 436 */ 437 438 /** @addtogroup HASH_Exported_Functions_Group3 HMAC processing functions 439 * @{ 440 */ 441 HAL_StatusTypeDef HAL_HASH_HMAC_Start(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size, 442 uint8_t *const pOutBuffer, 443 uint32_t Timeout); 444 HAL_StatusTypeDef HAL_HASH_HMAC_Start_DMA(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size, 445 uint8_t *const pOutBuffer); 446 HAL_StatusTypeDef HAL_HASH_HMAC_Start_IT(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size, 447 uint8_t *const pOutBuffer); 448 449 HAL_StatusTypeDef HAL_HASH_HMAC_Accumulate(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size, 450 uint32_t Timeout); 451 HAL_StatusTypeDef HAL_HASH_HMAC_AccumulateLast(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size, 452 uint8_t *const pOutBuffer, uint32_t Timeout); 453 HAL_StatusTypeDef HAL_HASH_HMAC_Accumulate_IT(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size); 454 HAL_StatusTypeDef HAL_HASH_HMAC_AccumulateLast_IT(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, 455 uint32_t Size, uint8_t *const pOutBuffer); 456 457 /** 458 * @} 459 */ 460 461 /** @addtogroup HASH_Exported_Functions_Group4 HASH IRQ handler management 462 * @{ 463 */ 464 void HAL_HASH_IRQHandler(HASH_HandleTypeDef *hhash); 465 void HAL_HASH_InCpltCallback(HASH_HandleTypeDef *hhash); 466 void HAL_HASH_DgstCpltCallback(HASH_HandleTypeDef *hhash); 467 void HAL_HASH_ErrorCallback(HASH_HandleTypeDef *hhash); 468 HAL_HASH_StateTypeDef HAL_HASH_GetState(const HASH_HandleTypeDef *hhash); 469 uint32_t HAL_HASH_GetError(const HASH_HandleTypeDef *hhash); 470 471 /** 472 * @} 473 */ 474 475 /** 476 * @} 477 */ 478 479 /* Private macros --------------------------------------------------------*/ 480 /** @defgroup HASH_Private_Macros HASH Private Macros 481 * @{ 482 */ 483 484 /** 485 * @brief Return digest length in bytes. 486 * @retval Digest length 487 */ 488 #define HASH_DIGEST_LENGTH(__HANDLE__) (((READ_BIT((__HANDLE__)->Instance->CR, HASH_CR_ALGO) \ 489 == HASH_ALGOSELECTION_SHA1) ? 20U : \ 490 ((READ_BIT((__HANDLE__)->Instance->CR, HASH_CR_ALGO) \ 491 == HASH_ALGOSELECTION_SHA224) ? 28U : \ 492 ((READ_BIT((__HANDLE__)->Instance->CR, HASH_CR_ALGO) \ 493 == HASH_ALGOSELECTION_SHA256) ? 32U : \ 494 ((READ_BIT((__HANDLE__)->Instance->CR, HASH_CR_ALGO) \ 495 == HASH_ALGOSELECTION_SHA384) ? 48U : \ 496 ((READ_BIT((__HANDLE__)->Instance->CR, HASH_CR_ALGO) \ 497 == HASH_ALGOSELECTION_SHA512_224) ? 28U : \ 498 ((READ_BIT((__HANDLE__)->Instance->CR, HASH_CR_ALGO) \ 499 == HASH_ALGOSELECTION_SHA512_256) ? 32U : \ 500 ((READ_BIT((__HANDLE__)->Instance->CR, HASH_CR_ALGO) \ 501 == HASH_ALGOSELECTION_SHA512) ? 64U : 20U ) ) )))))) 502 503 /** 504 * @brief Ensure that HASH input data type is valid. 505 * @param __DATATYPE__ HASH input data type. 506 * @retval SET (__DATATYPE__ is valid) or RESET (__DATATYPE__ is invalid) 507 */ 508 #define IS_HASH_DATATYPE(__DATATYPE__) (((__DATATYPE__) == HASH_NO_SWAP)|| \ 509 ((__DATATYPE__) == HASH_HALFWORD_SWAP)|| \ 510 ((__DATATYPE__) == HASH_BYTE_SWAP) || \ 511 ((__DATATYPE__) == HASH_BIT_SWAP)) 512 513 /** 514 * @brief Ensure that HASH input algorithm is valid. 515 * @param __ALGORITHM__ HASH algorithm. 516 * @retval SET (__ALGORITHM__ is valid) or RESET (__ALGORITHM__ is invalid) 517 */ 518 #define IS_HASH_ALGORITHM(__ALGORITHM__) (((__ALGORITHM__) == HASH_ALGOSELECTION_SHA1)|| \ 519 ((__ALGORITHM__) == HASH_ALGOSELECTION_SHA224)|| \ 520 ((__ALGORITHM__) == HASH_ALGOSELECTION_SHA256)|| \ 521 ((__ALGORITHM__) == HASH_ALGOSELECTION_SHA384)|| \ 522 ((__ALGORITHM__) == HASH_ALGOSELECTION_SHA512_224)|| \ 523 ((__ALGORITHM__) == HASH_ALGOSELECTION_SHA512_256)|| \ 524 ((__ALGORITHM__) == HASH_ALGOSELECTION_SHA512)) 525 526 /** 527 * @} 528 */ 529 530 /* Private constants ---------------------------------------------------------*/ 531 /** @defgroup HASH_Private_Constants HASH Private Constants 532 * @{ 533 */ 534 535 /** 536 * @} 537 */ 538 /* Private defines -----------------------------------------------------------*/ 539 /** @defgroup HASH_Private_Defines HASH Private Defines 540 * @{ 541 */ 542 543 /** 544 * @} 545 */ 546 547 /* Private variables ---------------------------------------------------------*/ 548 /** @defgroup HASH_Private_Variables HASH Private Variables 549 * @{ 550 */ 551 552 /** 553 * @} 554 */ 555 /* Private functions -----------------------------------------------------------*/ 556 557 /** @addtogroup HASH_Private_Functions HASH Private Functions 558 * @{ 559 */ 560 561 /** 562 * @} 563 */ 564 565 /** 566 * @} 567 */ 568 #endif /* HASH*/ 569 /** 570 * @} 571 */ 572 573 574 #ifdef __cplusplus 575 } 576 #endif 577 578 579 #endif /* STM32H7RSxx_HAL_HASH_H */ 580