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