1 /** 2 ****************************************************************************** 3 * @file stm32l4xx_hal_hash.h 4 * @author MCD Application Team 5 * @brief Header file of HASH HAL module. 6 ****************************************************************************** 7 * @attention 8 * 9 * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2> 10 * 11 * Redistribution and use in source and binary forms, with or without modification, 12 * are permitted provided that the following conditions are met: 13 * 1. Redistributions of source code must retain the above copyright notice, 14 * this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright notice, 16 * this list of conditions and the following disclaimer in the documentation 17 * and/or other materials provided with the distribution. 18 * 3. Neither the name of STMicroelectronics nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 * 33 ****************************************************************************** 34 */ 35 36 /* Define to prevent recursive inclusion -------------------------------------*/ 37 #ifndef STM32L4xx_HAL_HASH_H 38 #define STM32L4xx_HAL_HASH_H 39 40 #ifdef __cplusplus 41 extern "C" { 42 #endif 43 44 /* Includes ------------------------------------------------------------------*/ 45 #include "stm32l4xx_hal_def.h" 46 47 /** @addtogroup STM32L4xx_HAL_Driver 48 * @{ 49 */ 50 #if defined (HASH) 51 /** @addtogroup HASH 52 * @{ 53 */ 54 55 /* Exported types ------------------------------------------------------------*/ 56 /** @defgroup HASH_Exported_Types HASH Exported Types 57 * @{ 58 */ 59 60 /** 61 * @brief HASH Configuration Structure definition 62 */ 63 typedef struct 64 { 65 uint32_t DataType; /*!< 32-bit data, 16-bit data, 8-bit data or 1-bit data. 66 This parameter can be a value of @ref HASH_Data_Type. */ 67 68 uint32_t KeySize; /*!< The key size is used only in HMAC operation. */ 69 70 uint8_t* pKey; /*!< The key is used only in HMAC operation. */ 71 72 } HASH_InitTypeDef; 73 74 /** 75 * @brief HAL State structures definition 76 */ 77 typedef enum 78 { 79 HAL_HASH_STATE_RESET = 0x00U, /*!< Peripheral is not initialized */ 80 HAL_HASH_STATE_READY = 0x01U, /*!< Peripheral Initialized and ready for use */ 81 HAL_HASH_STATE_BUSY = 0x02U, /*!< Processing (hashing) is ongoing */ 82 HAL_HASH_STATE_TIMEOUT = 0x06U, /*!< Timeout state */ 83 HAL_HASH_STATE_ERROR = 0x07U, /*!< Error state */ 84 HAL_HASH_STATE_SUSPENDED = 0x08U /*!< Suspended state */ 85 }HAL_HASH_StateTypeDef; 86 87 /** 88 * @brief HAL phase structures definition 89 */ 90 typedef enum 91 { 92 HAL_HASH_PHASE_READY = 0x01U, /*!< HASH peripheral is ready to start */ 93 HAL_HASH_PHASE_PROCESS = 0x02U, /*!< HASH peripheral is in HASH processing phase */ 94 HAL_HASH_PHASE_HMAC_STEP_1 = 0x03U, /*!< HASH peripheral is in HMAC step 1 processing phase 95 (step 1 consists in entering the inner hash function key) */ 96 HAL_HASH_PHASE_HMAC_STEP_2 = 0x04U, /*!< HASH peripheral is in HMAC step 2 processing phase 97 (step 2 consists in entering the message text) */ 98 HAL_HASH_PHASE_HMAC_STEP_3 = 0x05U /*!< HASH peripheral is in HMAC step 3 processing phase 99 (step 3 consists in entering the outer hash function key) */ 100 }HAL_HASH_PhaseTypeDef; 101 102 /** 103 * @brief HAL HASH mode suspend definitions 104 */ 105 typedef enum 106 { 107 HAL_HASH_SUSPEND_NONE = 0x00U, /*!< HASH peripheral suspension not requested */ 108 HAL_HASH_SUSPEND = 0x01U /*!< HASH peripheral suspension is requested */ 109 }HAL_HASH_SuspendTypeDef; 110 111 #if (USE_HAL_HASH_REGISTER_CALLBACKS == 1U) 112 /** 113 * @brief HAL HASH common Callback ID enumeration definition 114 */ 115 typedef enum 116 { 117 HAL_HASH_MSPINIT_CB_ID = 0x00U, /*!< HASH MspInit callback ID */ 118 HAL_HASH_MSPDEINIT_CB_ID = 0x01U, /*!< HASH MspDeInit callback ID */ 119 HAL_HASH_INPUTCPLT_CB_ID = 0x02U, /*!< HASH input completion callback ID */ 120 HAL_HASH_DGSTCPLT_CB_ID = 0x03U, /*!< HASH digest computation completion callback ID */ 121 HAL_HASH_ERROR_CB_ID = 0x04U, /*!< HASH error callback ID */ 122 }HAL_HASH_CallbackIDTypeDef; 123 #endif /* USE_HAL_HASH_REGISTER_CALLBACKS */ 124 125 126 /** 127 * @brief HASH Handle Structure definition 128 */ 129 typedef struct __HASH_HandleTypeDef 130 { 131 HASH_InitTypeDef Init; /*!< HASH required parameters */ 132 133 uint8_t *pHashInBuffPtr; /*!< Pointer to input buffer */ 134 135 uint8_t *pHashOutBuffPtr; /*!< Pointer to output buffer (digest) */ 136 137 uint8_t *pHashKeyBuffPtr; /*!< Pointer to key buffer (HMAC only) */ 138 139 uint8_t *pHashMsgBuffPtr; /*!< Pointer to message buffer (HMAC only) */ 140 141 uint32_t HashBuffSize; /*!< Size of buffer to be processed */ 142 143 __IO uint32_t HashInCount; /*!< Counter of inputted data */ 144 145 __IO uint32_t HashITCounter; /*!< Counter of issued interrupts */ 146 147 __IO uint32_t HashKeyCount; /*!< Counter for Key inputted data (HMAC only) */ 148 149 HAL_StatusTypeDef Status; /*!< HASH peripheral status */ 150 151 HAL_HASH_PhaseTypeDef Phase; /*!< HASH peripheral phase */ 152 153 DMA_HandleTypeDef *hdmain; /*!< HASH In DMA Handle parameters */ 154 155 HAL_LockTypeDef Lock; /*!< Locking object */ 156 157 __IO HAL_HASH_StateTypeDef State; /*!< HASH peripheral state */ 158 159 HAL_HASH_SuspendTypeDef SuspendRequest; /*!< HASH peripheral suspension request flag */ 160 161 FlagStatus DigestCalculationDisable; /*!< Digest calculation phase skip (MDMAT bit control) for multi-buffers DMA-based HMAC computation */ 162 163 __IO uint32_t NbWordsAlreadyPushed; /*!< Numbers of words already pushed in FIFO before inputting new block */ 164 165 __IO uint32_t ErrorCode; /*!< HASH Error code */ 166 167 #if (USE_HAL_HASH_REGISTER_CALLBACKS == 1) 168 void (* InCpltCallback)( struct __HASH_HandleTypeDef * hhash); /*!< HASH input completion callback */ 169 170 void (* DgstCpltCallback)( struct __HASH_HandleTypeDef * hhash); /*!< HASH digest computation completion callback */ 171 172 void (* ErrorCallback)( struct __HASH_HandleTypeDef * hhash); /*!< HASH error callback */ 173 174 void (* MspInitCallback)( struct __HASH_HandleTypeDef * hhash); /*!< HASH Msp Init callback */ 175 176 void (* MspDeInitCallback)( struct __HASH_HandleTypeDef * hhash); /*!< HASH Msp DeInit callback */ 177 178 #endif /* (USE_HAL_HASH_REGISTER_CALLBACKS) */ 179 } HASH_HandleTypeDef; 180 181 #if (USE_HAL_HASH_REGISTER_CALLBACKS == 1U) 182 /** 183 * @brief HAL HASH Callback pointer definition 184 */ 185 typedef void (*pHASH_CallbackTypeDef)(HASH_HandleTypeDef * hhash); /*!< pointer to a HASH common callback functions */ 186 #endif /* USE_HAL_HASH_REGISTER_CALLBACKS */ 187 188 /** 189 * @} 190 */ 191 192 /* Exported constants --------------------------------------------------------*/ 193 194 /** @defgroup HASH_Exported_Constants HASH Exported Constants 195 * @{ 196 */ 197 198 /** @defgroup HASH_Algo_Selection HASH algorithm selection 199 * @{ 200 */ 201 #define HASH_ALGOSELECTION_SHA1 0x00000000U /*!< HASH function is SHA1 */ 202 #define HASH_ALGOSELECTION_MD5 HASH_CR_ALGO_0 /*!< HASH function is MD5 */ 203 #define HASH_ALGOSELECTION_SHA224 HASH_CR_ALGO_1 /*!< HASH function is SHA224 */ 204 #define HASH_ALGOSELECTION_SHA256 HASH_CR_ALGO /*!< HASH function is SHA256 */ 205 /** 206 * @} 207 */ 208 209 /** @defgroup HASH_Algorithm_Mode HASH algorithm mode 210 * @{ 211 */ 212 #define HASH_ALGOMODE_HASH 0x00000000U /*!< Algorithm is HASH */ 213 #define HASH_ALGOMODE_HMAC HASH_CR_MODE /*!< Algorithm is HMAC */ 214 /** 215 * @} 216 */ 217 218 /** @defgroup HASH_Data_Type HASH input data type 219 * @{ 220 */ 221 #define HASH_DATATYPE_32B 0x00000000U /*!< 32-bit data. No swapping */ 222 #define HASH_DATATYPE_16B HASH_CR_DATATYPE_0 /*!< 16-bit data. Each half word is swapped */ 223 #define HASH_DATATYPE_8B HASH_CR_DATATYPE_1 /*!< 8-bit data. All bytes are swapped */ 224 #define HASH_DATATYPE_1B HASH_CR_DATATYPE /*!< 1-bit data. In the word all bits are swapped */ 225 /** 226 * @} 227 */ 228 229 /** @defgroup HASH_HMAC_Long_key_only_for_HMAC_mode HMAC key length type 230 * @{ 231 */ 232 #define HASH_HMAC_KEYTYPE_SHORTKEY 0x00000000U /*!< HMAC Key size is <= 64 bytes */ 233 #define HASH_HMAC_KEYTYPE_LONGKEY HASH_CR_LKEY /*!< HMAC Key size is > 64 bytes */ 234 /** 235 * @} 236 */ 237 238 /** @defgroup HASH_flags_definition HASH flags definitions 239 * @{ 240 */ 241 #define HASH_FLAG_DINIS HASH_SR_DINIS /*!< 16 locations are free in the DIN : a new block can be entered in the IP */ 242 #define HASH_FLAG_DCIS HASH_SR_DCIS /*!< Digest calculation complete */ 243 #define HASH_FLAG_DMAS HASH_SR_DMAS /*!< DMA interface is enabled (DMAE=1) or a transfer is ongoing */ 244 #define HASH_FLAG_BUSY HASH_SR_BUSY /*!< The hash core is Busy, processing a block of data */ 245 #define HASH_FLAG_DINNE HASH_CR_DINNE /*!< DIN not empty : the input buffer contains at least one word of data */ 246 247 /** 248 * @} 249 */ 250 251 /** @defgroup HASH_interrupts_definition HASH interrupts definitions 252 * @{ 253 */ 254 #define HASH_IT_DINI HASH_IMR_DINIE /*!< A new block can be entered into the input buffer (DIN) */ 255 #define HASH_IT_DCI HASH_IMR_DCIE /*!< Digest calculation complete */ 256 257 /** 258 * @} 259 */ 260 /** @defgroup HASH_alias HASH API alias 261 * @{ 262 */ 263 #define HAL_HASHEx_IRQHandler HAL_HASH_IRQHandler /*!< HAL_HASHEx_IRQHandler() is re-directed to HAL_HASH_IRQHandler() for compatibility with legacy code */ 264 /** 265 * @} 266 */ 267 268 /** @defgroup HASH_Error_Definition HASH Error Definition 269 * @{ 270 */ 271 #define HAL_HASH_ERROR_NONE 0x00000000U /*!< No error */ 272 #define HAL_HASH_ERROR_IT 0x00000001U /*!< IT-based process error */ 273 #define HAL_HASH_ERROR_DMA 0x00000002U /*!< DMA-based process error */ 274 #if (USE_HAL_HASH_REGISTER_CALLBACKS == 1U) 275 #define HAL_HASH_ERROR_INVALID_CALLBACK 0x00000004U /*!< Invalid Callback error */ 276 #endif /* USE_HAL_HASH_REGISTER_CALLBACKS */ 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 __FLAG__: specifies the flag to check. 292 * This parameter can be one of the following values: 293 * @arg @ref HASH_FLAG_DINIS A new block can be entered into the input buffer. 294 * @arg @ref HASH_FLAG_DCIS Digest calculation complete. 295 * @arg @ref HASH_FLAG_DMAS DMA interface is enabled (DMAE=1) or a transfer is ongoing. 296 * @arg @ref HASH_FLAG_BUSY The hash core is Busy : processing a block of data. 297 * @arg @ref HASH_FLAG_DINNE DIN not empty : the input buffer contains at least one word of data. 298 * @retval The new state of __FLAG__ (TRUE or FALSE). 299 */ 300 #define __HAL_HASH_GET_FLAG(__FLAG__) (((__FLAG__) > 8U) ? \ 301 ((HASH->CR & (__FLAG__)) == (__FLAG__)) :\ 302 ((HASH->SR & (__FLAG__)) == (__FLAG__)) ) 303 304 305 /** @brief Clear the specified HASH flag. 306 * @param __FLAG__: specifies the flag to clear. 307 * This parameter can be one of the following values: 308 * @arg @ref HASH_FLAG_DINIS A new block can be entered into the input buffer. 309 * @arg @ref HASH_FLAG_DCIS Digest calculation complete 310 * @retval None 311 */ 312 #define __HAL_HASH_CLEAR_FLAG(__FLAG__) CLEAR_BIT(HASH->SR, (__FLAG__)) 313 314 315 /** @brief Enable the specified HASH interrupt. 316 * @param __INTERRUPT__: specifies the HASH interrupt source to enable. 317 * This parameter can be one of the following values: 318 * @arg @ref HASH_IT_DINI A new block can be entered into the input buffer (DIN) 319 * @arg @ref HASH_IT_DCI Digest calculation complete 320 * @retval None 321 */ 322 #define __HAL_HASH_ENABLE_IT(__INTERRUPT__) SET_BIT(HASH->IMR, (__INTERRUPT__)) 323 324 /** @brief Disable the specified HASH interrupt. 325 * @param __INTERRUPT__: specifies the HASH interrupt source to disable. 326 * This parameter can be one of the following values: 327 * @arg @ref HASH_IT_DINI A new block can be entered into the input buffer (DIN) 328 * @arg @ref HASH_IT_DCI Digest calculation complete 329 * @retval None 330 */ 331 #define __HAL_HASH_DISABLE_IT(__INTERRUPT__) CLEAR_BIT(HASH->IMR, (__INTERRUPT__)) 332 333 /** @brief Reset HASH handle state. 334 * @param __HANDLE__: HASH handle. 335 * @retval None 336 */ 337 338 #if (USE_HAL_HASH_REGISTER_CALLBACKS == 1) 339 #define __HAL_HASH_RESET_HANDLE_STATE(__HANDLE__) do{\ 340 (__HANDLE__)->State = HAL_HASH_STATE_RESET;\ 341 (__HANDLE__)->MspInitCallback = NULL; \ 342 (__HANDLE__)->MspDeInitCallback = NULL; \ 343 }while(0) 344 #else 345 #define __HAL_HASH_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_HASH_STATE_RESET) 346 #endif /* USE_HAL_HASH_REGISTER_CALLBACKS */ 347 348 349 /** @brief Reset HASH handle status. 350 * @param __HANDLE__: HASH handle. 351 * @retval None 352 */ 353 #define __HAL_HASH_RESET_HANDLE_STATUS(__HANDLE__) ((__HANDLE__)->Status = HAL_OK) 354 355 /** 356 * @brief Enable the multi-buffer DMA transfer mode. 357 * @note This bit is set when hashing large files when multiple DMA transfers are needed. 358 * @retval None 359 */ 360 #define __HAL_HASH_SET_MDMAT() SET_BIT(HASH->CR, HASH_CR_MDMAT) 361 362 /** 363 * @brief Disable the multi-buffer DMA transfer mode. 364 * @retval None 365 */ 366 #define __HAL_HASH_RESET_MDMAT() CLEAR_BIT(HASH->CR, HASH_CR_MDMAT) 367 368 369 /** 370 * @brief Start the digest computation. 371 * @retval None 372 */ 373 #define __HAL_HASH_START_DIGEST() SET_BIT(HASH->STR, HASH_STR_DCAL) 374 375 /** 376 * @brief Set the number of valid bits in the last word written in data register DIN. 377 * @param __SIZE__: size in bytes of last data written in Data register. 378 * @retval None 379 */ 380 #define __HAL_HASH_SET_NBVALIDBITS(__SIZE__) MODIFY_REG(HASH->STR, HASH_STR_NBLW, 8U * ((__SIZE__) % 4U)) 381 382 /** 383 * @brief Reset the HASH core. 384 * @retval None 385 */ 386 #define __HAL_HASH_INIT() SET_BIT(HASH->CR, HASH_CR_INIT) 387 388 /** 389 * @} 390 */ 391 392 393 /* Private macros --------------------------------------------------------*/ 394 /** @defgroup HASH_Private_Macros HASH Private Macros 395 * @{ 396 */ 397 /** 398 * @brief Return digest length in bytes. 399 * @retval Digest length 400 */ 401 #define HASH_DIGEST_LENGTH() ((READ_BIT(HASH->CR, HASH_CR_ALGO) == HASH_ALGOSELECTION_SHA1) ? 20U : \ 402 ((READ_BIT(HASH->CR, HASH_CR_ALGO) == HASH_ALGOSELECTION_SHA224) ? 28U : \ 403 ((READ_BIT(HASH->CR, HASH_CR_ALGO) == HASH_ALGOSELECTION_SHA256) ? 32U : 16U ) ) ) 404 /** 405 * @brief Return number of words already pushed in the FIFO. 406 * @retval Number of words already pushed in the FIFO 407 */ 408 #define HASH_NBW_PUSHED() ((READ_BIT(HASH->CR, HASH_CR_NBW)) >> 8U) 409 410 /** 411 * @brief Ensure that HASH input data type is valid. 412 * @param __DATATYPE__: HASH input data type. 413 * @retval SET (__DATATYPE__ is valid) or RESET (__DATATYPE__ is invalid) 414 */ 415 #define IS_HASH_DATATYPE(__DATATYPE__) (((__DATATYPE__) == HASH_DATATYPE_32B)|| \ 416 ((__DATATYPE__) == HASH_DATATYPE_16B)|| \ 417 ((__DATATYPE__) == HASH_DATATYPE_8B) || \ 418 ((__DATATYPE__) == HASH_DATATYPE_1B)) 419 420 421 422 /** 423 * @brief Ensure that input data buffer size is valid for multi-buffer HASH 424 * processing in polling mode. 425 * @note This check is valid only for multi-buffer HASH processing in polling mode. 426 * @param __SIZE__: input data buffer size. 427 * @retval SET (__SIZE__ is valid) or RESET (__SIZE__ is invalid) 428 */ 429 #define IS_HASH_POLLING_MULTIBUFFER_SIZE(__SIZE__) (((__SIZE__) % 4U) == 0U) 430 /** 431 * @brief Ensure that input data buffer size is valid for multi-buffer HASH 432 * processing in DMA mode. 433 * @note This check is valid only for multi-buffer HASH processing in DMA mode. 434 * @param __SIZE__: input data buffer size. 435 * @retval SET (__SIZE__ is valid) or RESET (__SIZE__ is invalid) 436 */ 437 #define IS_HASH_DMA_MULTIBUFFER_SIZE(__SIZE__) ((READ_BIT(HASH->CR, HASH_CR_MDMAT) == 0U) || (((__SIZE__) % 4U) == 0U)) 438 439 /** 440 * @brief Ensure that input data buffer size is valid for multi-buffer HMAC 441 * processing in DMA mode. 442 * @note This check is valid only for multi-buffer HMAC processing in DMA mode. 443 * @param __HANDLE__: HASH handle. 444 * @param __SIZE__: input data buffer size. 445 * @retval SET (__SIZE__ is valid) or RESET (__SIZE__ is invalid) 446 */ 447 #define IS_HMAC_DMA_MULTIBUFFER_SIZE(__HANDLE__,__SIZE__) ((((__HANDLE__)->DigestCalculationDisable) == RESET) || (((__SIZE__) % 4U) == 0U)) 448 /** 449 * @brief Ensure that handle phase is set to HASH processing. 450 * @param __HANDLE__: HASH handle. 451 * @retval SET (handle phase is set to HASH processing) or RESET (handle phase is not set to HASH processing) 452 */ 453 #define IS_HASH_PROCESSING(__HANDLE__) ((__HANDLE__)->Phase == HAL_HASH_PHASE_PROCESS) 454 455 /** 456 * @brief Ensure that handle phase is set to HMAC processing. 457 * @param __HANDLE__: HASH handle. 458 * @retval SET (handle phase is set to HMAC processing) or RESET (handle phase is not set to HMAC processing) 459 */ 460 #define IS_HMAC_PROCESSING(__HANDLE__) (((__HANDLE__)->Phase == HAL_HASH_PHASE_HMAC_STEP_1) || \ 461 ((__HANDLE__)->Phase == HAL_HASH_PHASE_HMAC_STEP_2) || \ 462 ((__HANDLE__)->Phase == HAL_HASH_PHASE_HMAC_STEP_3)) 463 464 /** 465 * @} 466 */ 467 468 /* Include HASH HAL Extended module */ 469 #include "stm32l4xx_hal_hash_ex.h" 470 /* Exported functions --------------------------------------------------------*/ 471 472 /** @addtogroup HASH_Exported_Functions HASH Exported Functions 473 * @{ 474 */ 475 476 /** @addtogroup HASH_Exported_Functions_Group1 Initialization and de-initialization functions 477 * @{ 478 */ 479 480 /* Initialization/de-initialization methods **********************************/ 481 HAL_StatusTypeDef HAL_HASH_Init(HASH_HandleTypeDef *hhash); 482 HAL_StatusTypeDef HAL_HASH_DeInit(HASH_HandleTypeDef *hhash); 483 void HAL_HASH_MspInit(HASH_HandleTypeDef *hhash); 484 void HAL_HASH_MspDeInit(HASH_HandleTypeDef *hhash); 485 void HAL_HASH_InCpltCallback(HASH_HandleTypeDef *hhash); 486 void HAL_HASH_DgstCpltCallback(HASH_HandleTypeDef *hhash); 487 void HAL_HASH_ErrorCallback(HASH_HandleTypeDef *hhash); 488 /* Callbacks Register/UnRegister functions ***********************************/ 489 #if (USE_HAL_HASH_REGISTER_CALLBACKS == 1) 490 HAL_StatusTypeDef HAL_HASH_RegisterCallback(HASH_HandleTypeDef *hhash, HAL_HASH_CallbackIDTypeDef CallbackID, pHASH_CallbackTypeDef pCallback); 491 HAL_StatusTypeDef HAL_HASH_UnRegisterCallback(HASH_HandleTypeDef *hhash, HAL_HASH_CallbackIDTypeDef CallbackID); 492 #endif /* USE_HAL_HASH_REGISTER_CALLBACKS */ 493 494 495 /** 496 * @} 497 */ 498 499 /** @addtogroup HASH_Exported_Functions_Group2 HASH processing functions in polling mode 500 * @{ 501 */ 502 503 504 /* HASH processing using polling *********************************************/ 505 HAL_StatusTypeDef HAL_HASH_SHA1_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer, uint32_t Timeout); 506 HAL_StatusTypeDef HAL_HASH_MD5_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer, uint32_t Timeout); 507 HAL_StatusTypeDef HAL_HASH_MD5_Accumulate(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size); 508 HAL_StatusTypeDef HAL_HASH_SHA1_Accumulate(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size); 509 510 /** 511 * @} 512 */ 513 514 /** @addtogroup HASH_Exported_Functions_Group3 HASH processing functions in interrupt mode 515 * @{ 516 */ 517 518 /* HASH processing using IT **************************************************/ 519 HAL_StatusTypeDef HAL_HASH_SHA1_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer); 520 HAL_StatusTypeDef HAL_HASH_MD5_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer); 521 void HAL_HASH_IRQHandler(HASH_HandleTypeDef *hhash); 522 /** 523 * @} 524 */ 525 526 /** @addtogroup HASH_Exported_Functions_Group4 HASH processing functions in DMA mode 527 * @{ 528 */ 529 530 /* HASH processing using DMA *************************************************/ 531 HAL_StatusTypeDef HAL_HASH_SHA1_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size); 532 HAL_StatusTypeDef HAL_HASH_SHA1_Finish(HASH_HandleTypeDef *hhash, uint8_t* pOutBuffer, uint32_t Timeout); 533 HAL_StatusTypeDef HAL_HASH_MD5_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size); 534 HAL_StatusTypeDef HAL_HASH_MD5_Finish(HASH_HandleTypeDef *hhash, uint8_t* pOutBuffer, uint32_t Timeout); 535 536 /** 537 * @} 538 */ 539 540 /** @addtogroup HASH_Exported_Functions_Group5 HMAC processing functions in polling mode 541 * @{ 542 */ 543 544 /* HASH-MAC processing using polling *****************************************/ 545 HAL_StatusTypeDef HAL_HMAC_SHA1_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer, uint32_t Timeout); 546 HAL_StatusTypeDef HAL_HMAC_MD5_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer, uint32_t Timeout); 547 548 /** 549 * @} 550 */ 551 552 /** @addtogroup HASH_Exported_Functions_Group6 HMAC processing functions in interrupt mode 553 * @{ 554 */ 555 556 HAL_StatusTypeDef HAL_HMAC_MD5_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer); 557 HAL_StatusTypeDef HAL_HMAC_SHA1_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer); 558 559 /** 560 * @} 561 */ 562 563 /** @addtogroup HASH_Exported_Functions_Group7 HMAC processing functions in DMA mode 564 * @{ 565 */ 566 567 /* HASH-HMAC processing using DMA ********************************************/ 568 HAL_StatusTypeDef HAL_HMAC_SHA1_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size); 569 HAL_StatusTypeDef HAL_HMAC_MD5_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size); 570 571 /** 572 * @} 573 */ 574 575 /** @addtogroup HASH_Exported_Functions_Group8 Peripheral states functions 576 * @{ 577 */ 578 579 580 /* Peripheral State methods **************************************************/ 581 HAL_HASH_StateTypeDef HAL_HASH_GetState(HASH_HandleTypeDef *hhash); 582 HAL_StatusTypeDef HAL_HASH_GetStatus(HASH_HandleTypeDef *hhash); 583 void HAL_HASH_ContextSaving(HASH_HandleTypeDef *hhash, uint8_t* pMemBuffer); 584 void HAL_HASH_ContextRestoring(HASH_HandleTypeDef *hhash, uint8_t* pMemBuffer); 585 void HAL_HASH_SwFeed_ProcessSuspend(HASH_HandleTypeDef *hhash); 586 HAL_StatusTypeDef HAL_HASH_DMAFeed_ProcessSuspend(HASH_HandleTypeDef *hhash); 587 uint32_t HAL_HASH_GetError(HASH_HandleTypeDef *hhash); 588 589 /** 590 * @} 591 */ 592 593 /** 594 * @} 595 */ 596 597 /* Private functions -----------------------------------------------------------*/ 598 599 /** @addtogroup HASH_Private_Functions HASH Private Functions 600 * @{ 601 */ 602 603 /* Private functions */ 604 HAL_StatusTypeDef HASH_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer, uint32_t Timeout, uint32_t Algorithm); 605 HAL_StatusTypeDef HASH_Accumulate(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint32_t Algorithm); 606 HAL_StatusTypeDef HASH_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer, uint32_t Algorithm); 607 HAL_StatusTypeDef HASH_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint32_t Algorithm); 608 HAL_StatusTypeDef HASH_Finish(HASH_HandleTypeDef *hhash, uint8_t* pOutBuffer, uint32_t Timeout); 609 HAL_StatusTypeDef HMAC_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer, uint32_t Timeout, uint32_t Algorithm); 610 HAL_StatusTypeDef HMAC_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer, uint32_t Algorithm); 611 HAL_StatusTypeDef HMAC_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint32_t Algorithm); 612 613 /** 614 * @} 615 */ 616 617 /** 618 * @} 619 */ 620 #endif /* HASH*/ 621 /** 622 * @} 623 */ 624 625 626 #ifdef __cplusplus 627 } 628 #endif 629 630 631 #endif /* STM32L4xx_HAL_HASH_H */ 632 633 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 634