1 /** 2 ****************************************************************************** 3 * @file stm32h5xx_hal_cryp.h 4 * @author MCD Application Team 5 * @brief Header file of CRYP HAL module. 6 ****************************************************************************** 7 * @attention 8 * 9 * Copyright (c) 2023 STMicroelectronics. 10 * All rights reserved. 11 * 12 * This software component is licensed by ST under BSD 3-Clause license, 13 * the "License"; You may not use this file except in compliance with the 14 * License. You may obtain a copy of the License at: 15 * opensource.org/licenses/BSD-3-Clause 16 * 17 ****************************************************************************** 18 */ 19 20 /* Define to prevent recursive inclusion -------------------------------------*/ 21 #ifndef STM32H5xx_HAL_CRYP_H 22 #define STM32H5xx_HAL_CRYP_H 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 /* Includes ------------------------------------------------------------------*/ 29 #include "stm32h5xx_hal_def.h" 30 31 /** @addtogroup STM32H5xx_HAL_Driver 32 * @{ 33 */ 34 35 #if defined(AES) 36 37 /** @defgroup CRYP CRYP 38 * @brief CRYP HAL module driver. 39 * @{ 40 */ 41 42 /* Exported types ------------------------------------------------------------*/ 43 44 /** @defgroup CRYP_Exported_Types CRYP Exported Types 45 * @{ 46 */ 47 48 /** 49 * @brief CRYP Init Structure definition 50 */ 51 52 typedef struct 53 { 54 uint32_t DataType; /*!< 32-bit data, 16-bit data, 8-bit data or 1-bit string. 55 This parameter can be a value of @ref CRYP_Data_Type */ 56 uint32_t KeySize; /*!< Used only in AES mode : 128, 192 or 256 bit key length in CRYP1. 57 128 or 256 bit key length in TinyAES This parameter can be a value 58 of @ref CRYP_Key_Size */ 59 uint32_t *pKey; /*!< The key used for encryption/decryption */ 60 uint32_t *pInitVect; /*!< The initialization vector used also as initialization 61 counter in CTR mode */ 62 uint32_t Algorithm; /*!< DES/ TDES Algorithm ECB/CBC 63 AES Algorithm ECB/CBC/CTR/GCM or CCM 64 This parameter can be a value of @ref CRYP_Algorithm_Mode */ 65 uint32_t *Header; /*!< used only in AES GCM and CCM Algorithm for authentication, 66 GCM : also known as Additional Authentication Data 67 CCM : named B1 composed of the associated data length and Associated Data. */ 68 uint32_t HeaderSize; /*!< The size of header buffer */ 69 uint32_t *B0; /*!< B0 is first authentication block used only in AES CCM mode */ 70 uint32_t DataWidthUnit; /*!< Payload Data Width Unit, this parameter can be value of @ref CRYP_Data_Width_Unit */ 71 uint32_t HeaderWidthUnit; /*!< Header Width Unit, this parameter can be value of @ref CRYP_Header_Width_Unit */ 72 uint32_t KeyIVConfigSkip; /*!< CRYP peripheral Key and IV configuration skip, to config Key and Initialization 73 Vector only once and to skip configuration for consecutive processings. 74 This parameter can be a value of @ref CRYP_Configuration_Skip */ 75 uint32_t KeyMode; /*!< Key mode selection, this parameter can be value of @ref CRYP_Key_Mode */ 76 uint32_t KeySelect; /*!< Only for SAES : Key selection, this parameter can be value of @ref CRYP_Key_Select */ 77 uint32_t KeyProtection; /*!< Only for SAES : Key protection, this parameter can be value of @ref CRYP_Key_Protection */ 78 79 } CRYP_ConfigTypeDef; 80 81 82 /** 83 * @brief CRYP State Structure definition 84 */ 85 86 typedef enum 87 { 88 HAL_CRYP_STATE_RESET = 0x00U, /*!< CRYP not yet initialized or disabled */ 89 HAL_CRYP_STATE_READY = 0x01U, /*!< CRYP initialized and ready for use */ 90 HAL_CRYP_STATE_BUSY = 0x02U, /*!< CRYP BUSY, internal processing is ongoing */ 91 #if (USE_HAL_CRYP_SUSPEND_RESUME == 1U) 92 HAL_CRYP_STATE_SUSPENDED = 0x03U, /*!< CRYP suspended */ 93 #endif /* USE_HAL_CRYP_SUSPEND_RESUME */ 94 } HAL_CRYP_STATETypeDef; 95 96 #if (USE_HAL_CRYP_SUSPEND_RESUME == 1U) 97 /** 98 * @brief HAL CRYP mode suspend definitions 99 */ 100 typedef enum 101 { 102 HAL_CRYP_SUSPEND_NONE = 0x00U, /*!< CRYP processing suspension not requested */ 103 HAL_CRYP_SUSPEND = 0x01U /*!< CRYP processing suspension requested */ 104 } HAL_SuspendTypeDef; 105 #endif /* USE_HAL_CRYP_SUSPEND_RESUME */ 106 107 /** 108 * @brief CRYP handle Structure definition 109 */ 110 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1) 111 typedef struct __CRYP_HandleTypeDef 112 #else 113 typedef struct 114 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */ 115 { 116 AES_TypeDef *Instance; /*!< AES Register base address */ 117 118 CRYP_ConfigTypeDef Init; /*!< CRYP required parameters */ 119 uint32_t *pCrypInBuffPtr; /*!< Pointer to CRYP processing (encryption, decryption,...) buffer */ 120 121 uint32_t *pCrypOutBuffPtr; /*!< Pointer to CRYP processing (encryption, decryption,...) buffer */ 122 123 __IO uint16_t CrypHeaderCount; /*!< Counter of header data in words */ 124 125 __IO uint16_t CrypInCount; /*!< Counter of input data in words */ 126 127 __IO uint16_t CrypOutCount; /*!< Counter of output data in words */ 128 129 uint16_t Size; /*!< length of input data in word or in byte, according to DataWidthUnit */ 130 131 uint32_t Phase; /*!< CRYP peripheral phase */ 132 133 DMA_HandleTypeDef *hdmain; /*!< CRYP In DMA handle parameters */ 134 135 DMA_HandleTypeDef *hdmaout; /*!< CRYP Out DMA handle parameters */ 136 137 HAL_LockTypeDef Lock; /*!< CRYP locking object */ 138 139 __IO HAL_CRYP_STATETypeDef State; /*!< CRYP peripheral state */ 140 141 __IO uint32_t ErrorCode; /*!< CRYP peripheral error code */ 142 143 uint32_t KeyIVConfig; /*!< CRYP peripheral Key and IV configuration flag, used when 144 configuration can be skipped */ 145 146 uint32_t SizesSum; /*!< Sum of successive payloads lengths (in bytes), stored 147 for a single signature computation after several 148 messages processing */ 149 150 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1U) 151 void (*InCpltCallback)(struct __CRYP_HandleTypeDef *hcryp); /*!< CRYP Input FIFO transfer completed callback */ 152 void (*OutCpltCallback)(struct __CRYP_HandleTypeDef *hcryp); /*!< CRYP Output FIFO transfer completed callback */ 153 void (*ErrorCallback)(struct __CRYP_HandleTypeDef *hcryp); /*!< CRYP Error callback */ 154 155 void (* MspInitCallback)(struct __CRYP_HandleTypeDef *hcryp); /*!< CRYP Msp Init callback */ 156 void (* MspDeInitCallback)(struct __CRYP_HandleTypeDef *hcryp); /*!< CRYP Msp DeInit callback */ 157 158 #endif /* (USE_HAL_CRYP_REGISTER_CALLBACKS) */ 159 160 #if (USE_HAL_CRYP_SUSPEND_RESUME == 1U) 161 162 __IO HAL_SuspendTypeDef SuspendRequest; /*!< CRYP peripheral suspension request flag */ 163 164 CRYP_ConfigTypeDef Init_saved; /*!< copy of CRYP required parameters when processing is suspended */ 165 166 uint32_t *pCrypInBuffPtr_saved; /*!< copy of CRYP input pointer when processing is suspended */ 167 168 uint32_t *pCrypOutBuffPtr_saved; /*!< copy of CRYP output pointer when processing is suspended */ 169 170 uint32_t CrypInCount_saved; /*!< copy of CRYP input data counter when processing is suspended */ 171 172 uint32_t CrypOutCount_saved; /*!< copy of CRYP output data counter when processing is suspended */ 173 174 uint32_t Phase_saved; /*!< copy of CRYP authentication phase when processing is suspended */ 175 176 __IO HAL_CRYP_STATETypeDef State_saved; /*!< copy of CRYP peripheral state when processing is suspended */ 177 178 uint32_t IV_saved[4]; /*!< copy of Initialisation Vector registers */ 179 180 uint32_t SUSPxR_saved[8]; /*!< copy of suspension registers */ 181 182 uint32_t CR_saved; /*!< copy of CRYP control register when processing is suspended*/ 183 184 uint32_t Key_saved[8]; /*!< copy of key registers */ 185 186 uint16_t Size_saved; /*!< copy of input buffer size */ 187 188 uint16_t CrypHeaderCount_saved; /*!< copy of CRYP header data counter when processing is suspended */ 189 190 uint32_t SizesSum_saved; /*!< copy of SizesSum when processing is suspended */ 191 192 uint32_t ResumingFlag; /*!< resumption flag to bypass steps already carried out */ 193 #endif /* USE_HAL_CRYP_SUSPEND_RESUME */ 194 195 } CRYP_HandleTypeDef; 196 197 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1U) 198 199 /** 200 * @brief HAL CRYP Callback ID enumeration definition 201 */ 202 typedef enum 203 { 204 HAL_CRYP_MSPINIT_CB_ID = 0x00U, /*!< CRYP MspInit callback ID */ 205 HAL_CRYP_MSPDEINIT_CB_ID = 0x01U, /*!< CRYP MspDeInit callback ID */ 206 HAL_CRYP_INPUT_COMPLETE_CB_ID = 0x02U, /*!< CRYP Input FIFO transfer completed callback ID */ 207 HAL_CRYP_OUTPUT_COMPLETE_CB_ID = 0x03U, /*!< CRYP Output FIFO transfer completed callback ID */ 208 HAL_CRYP_ERROR_CB_ID = 0x04U, /*!< CRYP Error callback ID */ 209 } HAL_CRYP_CallbackIDTypeDef; 210 211 /** 212 * @brief HAL CRYP Callback pointer definition 213 */ 214 typedef void (*pCRYP_CallbackTypeDef)(CRYP_HandleTypeDef *hcryp); /*!< pointer to a common CRYP callback function */ 215 216 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */ 217 218 /** 219 * @} 220 */ 221 222 /* Exported constants --------------------------------------------------------*/ 223 /** @defgroup CRYP_Exported_Constants CRYP Exported Constants 224 * @{ 225 */ 226 227 /** @defgroup CRYP_Error_Definition CRYP Error Definition 228 * @{ 229 */ 230 #define HAL_CRYP_ERROR_NONE 0x00000000U /*!< No error */ 231 #define HAL_CRYP_ERROR_WRITE 0x00000001U /*!< Write error */ 232 #define HAL_CRYP_ERROR_READ 0x00000002U /*!< Read error */ 233 #define HAL_CRYP_ERROR_DMA 0x00000004U /*!< DMA error */ 234 #define HAL_CRYP_ERROR_BUSY 0x00000008U /*!< Busy flag error */ 235 #define HAL_CRYP_ERROR_TIMEOUT 0x00000010U /*!< Timeout error */ 236 #define HAL_CRYP_ERROR_NOT_SUPPORTED 0x00000020U /*!< Not supported mode */ 237 #define HAL_CRYP_ERROR_AUTH_TAG_SEQUENCE 0x00000040U /*!< Sequence are not respected only for GCM or CCM */ 238 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1U) 239 #define HAL_CRYP_ERROR_INVALID_CALLBACK ((uint32_t)0x00000080U) /*!< Invalid Callback error */ 240 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */ 241 #define HAL_CRYP_ERROR_KEY 0x00000100U /*!< Key error */ 242 #define HAL_CRYP_ERROR_RNG 0x00000200U /*!< Rng error */ 243 /** 244 * @} 245 */ 246 247 /** @defgroup CRYP_Data_Width_Unit CRYP Data Width Unit 248 * @{ 249 */ 250 251 #define CRYP_DATAWIDTHUNIT_WORD 0x00000000U /*!< By default, size unit is word */ 252 #define CRYP_DATAWIDTHUNIT_BYTE 0x00000001U /*!< By default, size unit is byte */ 253 254 /** 255 * @} 256 */ 257 258 /** @defgroup CRYP_Header_Width_Unit CRYP Header Width Unit 259 * @{ 260 */ 261 262 #define CRYP_HEADERWIDTHUNIT_WORD 0x00000000U /*!< By default, header size unit is word */ 263 #define CRYP_HEADERWIDTHUNIT_BYTE 0x00000001U /*!< By default, header size unit is byte */ 264 265 /** 266 * @} 267 */ 268 269 /** @defgroup CRYP_Algorithm_Mode CRYP Algorithm Mode 270 * @{ 271 */ 272 273 #define CRYP_AES_ECB 0x00000000U /*!< Electronic codebook chaining algorithm */ 274 #define CRYP_AES_CBC AES_CR_CHMOD_0 /*!< Cipher block chaining algorithm */ 275 #define CRYP_AES_CTR AES_CR_CHMOD_1 /*!< Counter mode chaining algorithm */ 276 #define CRYP_AES_GCM_GMAC (AES_CR_CHMOD_0 | AES_CR_CHMOD_1) /*!< Galois counter mode - Galois message authentication code */ 277 #define CRYP_AES_CCM AES_CR_CHMOD_2 /*!< Counter with Cipher Mode */ 278 279 /** 280 * @} 281 */ 282 283 /** @defgroup CRYP_Key_Size CRYP Key Size 284 * @{ 285 */ 286 287 #define CRYP_KEYSIZE_128B 0x00000000U /*!< 128-bit long key */ 288 #define CRYP_KEYSIZE_256B AES_CR_KEYSIZE /*!< 256-bit long key */ 289 290 /** 291 * @} 292 */ 293 294 /** @defgroup CRYP_Key_Mode CRYP Key Mode 295 * @{ 296 */ 297 298 #define CRYP_KEYMODE_NORMAL 0x00000000U /*!< Normal key usage, Key registers are freely usable */ 299 #define CRYP_KEYMODE_SHARED AES_CR_KMOD_1 /*!< Shared key */ 300 #define CRYP_KEYMODE_WRAPPED AES_CR_KMOD_0 /*!< Only for SAES, Wrapped key: to encrypt or decrypt AES keys */ 301 302 /** 303 * @} 304 */ 305 306 /** @defgroup CRYP_Key_Select CRYP Key Select 307 * @{ 308 */ 309 310 #define CRYP_KEYSEL_NORMAL 0x00000000U /*!< Normal key, key registers SAES_KEYx or CRYP_KEYx */ 311 #define CRYP_KEYSEL_HW AES_CR_KEYSEL_0 /*!< Only for SAES, Hardware key : derived hardware unique key (DHUK 256-bit) */ 312 #define CRYP_KEYSEL_SW AES_CR_KEYSEL_1 /*!< Only for SAES, Software key : boot hardware key BHK (256-bit) */ 313 #define CRYP_KEYSEL_HSW AES_CR_KEYSEL_2 /*!< Only for SAES, DHUK XOR BHK Hardware unique key XOR software key */ 314 315 /** 316 * @} 317 */ 318 319 /** @defgroup CRYP_Key_ShareID CRYP Key Share ID 320 * @{ 321 */ 322 323 #define CRYP_KSHAREID_AES 0x00000000U /*!< Share SAES Key with AES peripheral */ 324 325 /** 326 * @} 327 */ 328 329 /** @defgroup CRYP_Key_Protection CRYP Key Protection 330 * @{ 331 */ 332 333 #define CRYP_KEYPROT_ENABLE AES_CR_KEYPROT /*!< Only for SAES, Key protection between 2 applications with different security contexts */ 334 #define CRYP_KEYPROT_DISABLE 0x00000000U /*!< Only for SAES, Key not protected between 2 applications with different security contexts */ 335 /** 336 * @} 337 */ 338 339 340 /** @defgroup CRYP_Data_Type CRYP Data Type 341 * @{ 342 */ 343 344 #define CRYP_NO_SWAP 0x00000000U /*!< 32-bit data type (no swapping) */ 345 #define CRYP_HALFWORD_SWAP AES_CR_DATATYPE_0 /*!< 16-bit data type (half-word swapping) */ 346 #define CRYP_BYTE_SWAP AES_CR_DATATYPE_1 /*!< 8-bit data type (byte swapping) */ 347 #define CRYP_BIT_SWAP AES_CR_DATATYPE /*!< 1-bit data type (bit swapping) */ 348 349 /** 350 * @} 351 */ 352 353 /** @defgroup CRYP_Interrupt CRYP Interrupt 354 * @{ 355 */ 356 #define CRYP_IT_CCFIE AES_IER_CCFIE /*!< Computation Complete interrupt enable */ 357 #define CRYP_IT_RWEIE AES_IER_RWEIE /*!< Read or write Error interrupt enable */ 358 #define CRYP_IT_KEIE AES_IER_KEIE /*!< Key error interrupt enable */ 359 #define CRYP_IT_RNGEIE AES_IER_RNGEIE /*!< Rng error interrupt enable */ 360 361 /** 362 * @} 363 */ 364 365 /** @defgroup CRYP_Flags CRYP Flags 366 * @{ 367 */ 368 369 #define CRYP_FLAG_BUSY AES_SR_BUSY /*!< GCM process suspension forbidden 370 also set when transferring a shared key from SAES peripheral */ 371 #define CRYP_FLAG_WRERR (AES_SR_WRERR | 0x80000000U) /*!< Write Error flag */ 372 #define CRYP_FLAG_RDERR (AES_SR_RDERR | 0x80000000U) /*!< Read error flag */ 373 #define CRYP_FLAG_CCF AES_ISR_CCF /*!< Computation completed flag as AES_ISR_CCF */ 374 #define CRYP_FLAG_KEYVALID AES_SR_KEYVALID /*!< Key Valid flag */ 375 #define CRYP_FLAG_KEIF AES_ISR_KEIF /*Key error interrupt flag */ 376 #define CRYP_FLAG_RWEIF AES_ISR_RWEIF /*Read or write error Interrupt flag */ 377 #define CRYP_FLAG_RNGEIF AES_ISR_RNGEIF /*RNG error interrupt flag */ 378 379 380 /** 381 * @} 382 */ 383 384 /** @defgroup CRYP_CLEAR_Flags CRYP CLEAR Flags 385 * @{ 386 */ 387 388 #define CRYP_CLEAR_CCF AES_ICR_CCF /* Computation Complete Flag Clear */ 389 #define CRYP_CLEAR_RWEIF AES_ICR_RWEIF /* Clear Error Flag : RWEIF in AES_ISR and 390 both RDERR and WRERR flags in AES_SR */ 391 #define CRYP_CLEAR_KEIF AES_ICR_KEIF /* Clear Key Error Flag: KEIF in AES_ISR */ 392 #define CRYP_CLEAR_RNGEIF AES_ICR_RNGEIF /* Clear rng Error Flag: RNGEIF in AES_ISR */ 393 394 395 /** 396 * @} 397 */ 398 399 /** @defgroup CRYP_Configuration_Skip CRYP Key and IV Configuration Skip Mode 400 * @{ 401 */ 402 403 #define CRYP_KEYIVCONFIG_ALWAYS 0x00000000U /*!< Peripheral Key and IV configuration to do systematically */ 404 #define CRYP_KEYIVCONFIG_ONCE 0x00000001U /*!< Peripheral Key and IV configuration to do only once */ 405 #define CRYP_KEYNOCONFIG 0x00000002U /*!< Peripheral Key configuration to not do */ 406 407 /** 408 * @} 409 */ 410 411 412 /** 413 * @} 414 */ 415 416 /* Exported macros -----------------------------------------------------------*/ 417 /** @defgroup CRYP_Exported_Macros CRYP Exported Macros 418 * @{ 419 */ 420 421 /** @brief Reset CRYP handle state 422 * @param __HANDLE__ specifies the CRYP handle. 423 * @retval None 424 */ 425 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1U) 426 #define __HAL_CRYP_RESET_HANDLE_STATE(__HANDLE__) do{\ 427 (__HANDLE__)->State = HAL_CRYP_STATE_RESET;\ 428 (__HANDLE__)->MspInitCallback = NULL;\ 429 (__HANDLE__)->MspDeInitCallback = NULL;\ 430 }while(0U) 431 #else 432 #define __HAL_CRYP_RESET_HANDLE_STATE(__HANDLE__) ( (__HANDLE__)->State = HAL_CRYP_STATE_RESET) 433 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */ 434 435 /** 436 * @brief Enable/Disable the CRYP peripheral. 437 * @param __HANDLE__ specifies the CRYP handle. 438 * @retval None 439 */ 440 441 #define __HAL_CRYP_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= AES_CR_EN) 442 #define __HAL_CRYP_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~AES_CR_EN) 443 444 445 /** @brief Check whether the specified CRYP status flag is set or not. 446 * @param __HANDLE__ specifies the CRYP handle. 447 * @param __FLAG__ specifies the flag to check. 448 * This parameter can be one of the following values for TinyAES: 449 * @arg @ref CRYP_FLAG_KEYVALID Key valid flag 450 * @arg @ref CRYP_FLAG_BUSY GCM process suspension forbidden or 451 * transferring a shared key from SAES IP. 452 * @arg @ref CRYP_FLAG_WRERR Write Error flag 453 * @arg @ref CRYP_FLAG_RDERR Read Error flag 454 * @arg @ref CRYP_FLAG_CCF Computation Complete flag 455 * @arg @ref CRYP_FLAG_KEIF Key error flag 456 * @arg @ref CRYP_FLAG_RWEIF Read/write Error flag 457 458 * @retval The state of __FLAG__ (TRUE or FALSE). 459 */ 460 461 #define __HAL_CRYP_GET_FLAG(__HANDLE__, __FLAG__) (\ 462 ((__FLAG__) == CRYP_FLAG_KEYVALID )?(((__HANDLE__)->Instance->SR \ 463 & (CRYP_FLAG_KEYVALID)) == (CRYP_FLAG_KEYVALID)) : \ 464 ((__FLAG__) == CRYP_FLAG_BUSY )?(((__HANDLE__)->Instance->SR \ 465 & (CRYP_FLAG_BUSY)) == (CRYP_FLAG_BUSY)) : \ 466 ((__FLAG__) == CRYP_FLAG_WRERR )?(((__HANDLE__)->Instance->SR \ 467 & (CRYP_FLAG_WRERR & 0x7FFFFFFFU)) == \ 468 (CRYP_FLAG_WRERR & 0x7FFFFFFFU)) : \ 469 ((__FLAG__) == CRYP_FLAG_RDERR )?(((__HANDLE__)->Instance->SR \ 470 & (CRYP_FLAG_RDERR & 0x7FFFFFFFU)) == \ 471 (CRYP_FLAG_RDERR & 0x7FFFFFFFU)) : \ 472 ((__FLAG__) == CRYP_FLAG_KEIF )?(((__HANDLE__)->Instance->ISR \ 473 & (CRYP_FLAG_KEIF)) == (CRYP_FLAG_KEIF)) : \ 474 ((__FLAG__) == CRYP_FLAG_RWEIF )?(((__HANDLE__)->Instance->ISR \ 475 & (CRYP_FLAG_RWEIF)) == (CRYP_FLAG_RWEIF)) : \ 476 (((__HANDLE__)->Instance->ISR & (CRYP_FLAG_CCF)) == (CRYP_FLAG_CCF))) 477 478 /** @brief Clear the CRYP pending status flag. 479 * @param __HANDLE__ specifies the CRYP handle. 480 * @param __FLAG__ specifies the flag to clear. 481 * This parameter can be one of the following values: 482 * @arg @ref CRYP_CLEAR_RWEIF Read (RDERR), Write (WRERR) or Read/write (RWEIF) Error Flag Clear 483 * @arg @ref CRYP_CLEAR_CCF Computation Complete Flag (CCF) Clear 484 * @arg @ref CRYP_CLEAR_KEIF Key error interrupt flag clear 485 * @retval None 486 */ 487 488 #define __HAL_CRYP_CLEAR_FLAG(__HANDLE__, __FLAG__) SET_BIT((__HANDLE__)->Instance->ICR, (__FLAG__)) 489 490 491 /** @brief Check whether the specified CRYP interrupt source is enabled or not. 492 * @param __HANDLE__ specifies the CRYP handle. 493 * @param __INTERRUPT__ CRYP interrupt source to check 494 * This parameter can be one of the following values for TinyAES: 495 * @arg @ref CRYP_IT_RWEIE Error interrupt (used for RDERR and WRERR) 496 * @arg @ref CRYP_IT_CCFIE Computation Complete interrupt 497 * @arg @ref CRYP_IT_KEIE Key error interrupt 498 * @retval State of interruption (TRUE or FALSE). 499 */ 500 501 #define __HAL_CRYP_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->IER\ 502 & (__INTERRUPT__)) == (__INTERRUPT__)) 503 504 /** 505 * @brief Enable the CRYP interrupt. 506 * @param __HANDLE__ specifies the CRYP handle. 507 * @param __INTERRUPT__ CRYP Interrupt. 508 * This parameter can be one of the following values for TinyAES: 509 * @arg @ref CRYP_IT_RWEIE Error interrupt (used for RDERR and WRERR) 510 * @arg @ref CRYP_IT_CCFIE Computation Complete interrupt 511 * @arg @ref CRYP_IT_KEIE Key error interrupt 512 * @retval None 513 */ 514 515 #define __HAL_CRYP_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->IER) |= (__INTERRUPT__)) 516 517 /** 518 * @brief Disable the CRYP interrupt. 519 * @param __HANDLE__ specifies the CRYP handle. 520 * @param __INTERRUPT__ CRYP Interrupt. 521 * This parameter can be one of the following values for TinyAES: 522 * @arg @ref CRYP_IT_RWEIE Error interrupt (used for RDERR and WRERR) 523 * @arg @ref CRYP_IT_CCFIE Computation Complete interrupt 524 * @arg @ref CRYP_IT_KEIE Key error interrupt 525 * @retval None 526 */ 527 528 #define __HAL_CRYP_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->IER) &= ~(__INTERRUPT__)) 529 530 /** 531 * @} 532 */ 533 534 /* Include CRYP HAL Extended module */ 535 #include "stm32h5xx_hal_cryp_ex.h" 536 537 /* Exported functions --------------------------------------------------------*/ 538 /** @defgroup CRYP_Exported_Functions CRYP Exported Functions 539 * @{ 540 */ 541 542 /** @addtogroup CRYP_Exported_Functions_Group1 543 * @{ 544 */ 545 HAL_StatusTypeDef HAL_CRYP_Init(CRYP_HandleTypeDef *hcryp); 546 HAL_StatusTypeDef HAL_CRYP_DeInit(CRYP_HandleTypeDef *hcryp); 547 void HAL_CRYP_MspInit(CRYP_HandleTypeDef *hcryp); 548 void HAL_CRYP_MspDeInit(CRYP_HandleTypeDef *hcryp); 549 HAL_StatusTypeDef HAL_CRYP_SetConfig(CRYP_HandleTypeDef *hcryp, CRYP_ConfigTypeDef *pConf); 550 HAL_StatusTypeDef HAL_CRYP_GetConfig(CRYP_HandleTypeDef *hcryp, CRYP_ConfigTypeDef *pConf); 551 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1U) 552 HAL_StatusTypeDef HAL_CRYP_RegisterCallback(CRYP_HandleTypeDef *hcryp, HAL_CRYP_CallbackIDTypeDef CallbackID, 553 pCRYP_CallbackTypeDef pCallback); 554 HAL_StatusTypeDef HAL_CRYP_UnRegisterCallback(CRYP_HandleTypeDef *hcryp, HAL_CRYP_CallbackIDTypeDef CallbackID); 555 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */ 556 #if (USE_HAL_CRYP_SUSPEND_RESUME == 1U) 557 void HAL_CRYP_ProcessSuspend(CRYP_HandleTypeDef *hcryp); 558 HAL_StatusTypeDef HAL_CRYP_Suspend(CRYP_HandleTypeDef *hcryp); 559 HAL_StatusTypeDef HAL_CRYP_Resume(CRYP_HandleTypeDef *hcryp); 560 #endif /* defined (USE_HAL_CRYP_SUSPEND_RESUME) */ 561 /** 562 * @} 563 */ 564 565 /** @addtogroup CRYP_Exported_Functions_Group2 566 * @{ 567 */ 568 569 /* encryption/decryption ***********************************/ 570 HAL_StatusTypeDef HAL_CRYP_Encrypt(CRYP_HandleTypeDef *hcryp, uint32_t *pInput, uint16_t Size, uint32_t *pOutput, 571 uint32_t Timeout); 572 HAL_StatusTypeDef HAL_CRYP_Decrypt(CRYP_HandleTypeDef *hcryp, uint32_t *pInput, uint16_t Size, uint32_t *pOutput, 573 uint32_t Timeout); 574 HAL_StatusTypeDef HAL_CRYP_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint32_t *pInput, uint16_t Size, uint32_t *pOutput); 575 HAL_StatusTypeDef HAL_CRYP_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint32_t *pInput, uint16_t Size, uint32_t *pOutput); 576 HAL_StatusTypeDef HAL_CRYP_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint32_t *pInput, uint16_t Size, uint32_t *pOutput); 577 HAL_StatusTypeDef HAL_CRYP_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint32_t *pInput, uint16_t Size, uint32_t *pOutput); 578 579 /** 580 * @} 581 */ 582 583 584 /** @addtogroup CRYP_Exported_Functions_Group3 585 * @{ 586 */ 587 /* Interrupt Handler functions **********************************************/ 588 void HAL_CRYP_IRQHandler(CRYP_HandleTypeDef *hcryp); 589 HAL_CRYP_STATETypeDef HAL_CRYP_GetState(CRYP_HandleTypeDef *hcryp); 590 void HAL_CRYP_InCpltCallback(CRYP_HandleTypeDef *hcryp); 591 void HAL_CRYP_OutCpltCallback(CRYP_HandleTypeDef *hcryp); 592 void HAL_CRYP_ErrorCallback(CRYP_HandleTypeDef *hcryp); 593 uint32_t HAL_CRYP_GetError(CRYP_HandleTypeDef *hcryp); 594 595 /** 596 * @} 597 */ 598 599 /** 600 * @} 601 */ 602 603 /* Private macros --------------------------------------------------------*/ 604 /** @defgroup CRYP_Private_Macros CRYP Private Macros 605 * @{ 606 */ 607 608 #define IS_CRYP_INSTANCE(INSTANCE)(((INSTANCE) == AES) || \ 609 ((INSTANCE) == SAES)) 610 611 #define IS_CRYP_ALGORITHM(ALGORITHM) (((ALGORITHM) == CRYP_AES_ECB) || \ 612 ((ALGORITHM) == CRYP_AES_CBC) || \ 613 ((ALGORITHM) == CRYP_AES_CTR) || \ 614 ((ALGORITHM) == CRYP_AES_GCM_GMAC)|| \ 615 ((ALGORITHM) == CRYP_AES_CCM)) 616 617 618 #define IS_CRYP_KEYSIZE(KEYSIZE)(((KEYSIZE) == CRYP_KEYSIZE_128B) || \ 619 ((KEYSIZE) == CRYP_KEYSIZE_256B)) 620 621 #define IS_CRYP_DATATYPE(DATATYPE)(((DATATYPE) == CRYP_NO_SWAP) || \ 622 ((DATATYPE) == CRYP_HALFWORD_SWAP) || \ 623 ((DATATYPE) == CRYP_BYTE_SWAP) || \ 624 ((DATATYPE) == CRYP_BIT_SWAP)) 625 626 #define IS_CRYP_INIT(CONFIG)(((CONFIG) == CRYP_KEYIVCONFIG_ALWAYS) || \ 627 ((CONFIG) == CRYP_KEYIVCONFIG_ONCE)) 628 629 #define IS_CRYP_BUFFERSIZE(ALGO, DATAWIDTH, SIZE) \ 630 (((((ALGO) == CRYP_AES_CTR)) && \ 631 ((((DATAWIDTH) == CRYP_DATAWIDTHUNIT_WORD) && (((SIZE) % 4U) == 0U)) || \ 632 (((DATAWIDTH) == CRYP_DATAWIDTHUNIT_BYTE) && (((SIZE) % 16U) == 0U)))) || \ 633 (((ALGO) == CRYP_AES_ECB) || ((ALGO) == CRYP_AES_CBC) || \ 634 ((ALGO)== CRYP_AES_GCM_GMAC) || ((ALGO) == CRYP_AES_CCM))) 635 636 637 /** 638 * @} 639 */ 640 641 642 /* Private constants ---------------------------------------------------------*/ 643 /* Private defines -----------------------------------------------------------*/ 644 /** @defgroup CRYP_Private_Defines CRYP Private Defines 645 * @{ 646 */ 647 648 /** 649 * @} 650 */ 651 652 /* Private variables ---------------------------------------------------------*/ 653 /* Private functions ---------------------------------------------------------*/ 654 /** @defgroup CRYP_Private_Functions CRYP Private Functions 655 * @{ 656 */ 657 658 /** 659 * @} 660 */ 661 662 /** 663 * @} 664 */ 665 666 #endif /* AES */ 667 /** 668 * @} 669 */ 670 671 #ifdef __cplusplus 672 } 673 #endif 674 675 #endif /* STM32H5xx_HAL_CRYP_H */ 676