1 /** 2 ****************************************************************************** 3 * @file stm32l5xx_hal_cryp.h 4 * @author MCD Application Team 5 * @brief Header file of CRYP HAL module. 6 ****************************************************************************** 7 * @attention 8 * 9 * Copyright (c) 2019 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 STM32L5xx_HAL_CRYP_H 21 #define STM32L5xx_HAL_CRYP_H 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /* Includes ------------------------------------------------------------------*/ 28 #include "stm32l5xx_hal_def.h" 29 30 /** @addtogroup STM32L5xx_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 57 This parameter can be a value 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 75 } CRYP_ConfigTypeDef; 76 77 78 /** 79 * @brief CRYP State Structure definition 80 */ 81 82 typedef enum 83 { 84 HAL_CRYP_STATE_RESET = 0x00U, /*!< CRYP not yet initialized or disabled */ 85 HAL_CRYP_STATE_READY = 0x01U, /*!< CRYP initialized and ready for use */ 86 HAL_CRYP_STATE_BUSY = 0x02U, /*!< CRYP BUSY, internal processing is ongoing */ 87 #if (USE_HAL_CRYP_SUSPEND_RESUME == 1U) 88 HAL_CRYP_STATE_SUSPENDED = 0x03U, /*!< CRYP suspended */ 89 #endif /* USE_HAL_CRYP_SUSPEND_RESUME */ 90 } HAL_CRYP_STATETypeDef; 91 92 #if (USE_HAL_CRYP_SUSPEND_RESUME == 1U) 93 /** 94 * @brief HAL CRYP mode suspend definitions 95 */ 96 typedef enum 97 { 98 HAL_CRYP_SUSPEND_NONE = 0x00U, /*!< CRYP processing suspension not requested */ 99 HAL_CRYP_SUSPEND = 0x01U /*!< CRYP processing suspension requested */ 100 } HAL_SuspendTypeDef; 101 #endif /* USE_HAL_CRYP_SUSPEND_RESUME */ 102 103 /** 104 * @brief CRYP handle Structure definition 105 */ 106 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1) 107 typedef struct __CRYP_HandleTypeDef 108 #else 109 typedef struct 110 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */ 111 { 112 AES_TypeDef *Instance; /*!< AES Register base address */ 113 114 CRYP_ConfigTypeDef Init; /*!< CRYP required parameters */ 115 116 FunctionalState AutoKeyDerivation; /*!< Used only in TinyAES to allow to bypass or not key write-up before decryption. 117 This parameter can be a value of ENABLE/DISABLE */ 118 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 */ 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 194 FunctionalState AutoKeyDerivation_saved; /*!< copy of CRYP handle auto key derivation parameter */ 195 196 #endif /* USE_HAL_CRYP_SUSPEND_RESUME */ 197 198 } CRYP_HandleTypeDef; 199 200 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1U) 201 /** @defgroup HAL_CRYP_Callback_ID_enumeration_definition HAL CRYP Callback ID enumeration definition 202 * @brief HAL CRYP Callback ID enumeration definition 203 * @{ 204 */ 205 typedef enum 206 { 207 HAL_CRYP_MSPINIT_CB_ID = 0x00U, /*!< CRYP MspInit callback ID */ 208 HAL_CRYP_MSPDEINIT_CB_ID = 0x01U, /*!< CRYP MspDeInit callback ID */ 209 HAL_CRYP_INPUT_COMPLETE_CB_ID = 0x02U, /*!< CRYP Input FIFO transfer completed callback ID */ 210 HAL_CRYP_OUTPUT_COMPLETE_CB_ID = 0x03U, /*!< CRYP Output FIFO transfer completed callback ID */ 211 HAL_CRYP_ERROR_CB_ID = 0x04U, /*!< CRYP Error callback ID */ 212 } HAL_CRYP_CallbackIDTypeDef; 213 /** 214 * @} 215 */ 216 217 /** @defgroup HAL_CRYP_Callback_pointer_definition HAL CRYP Callback pointer definition 218 * @brief HAL CRYP Callback pointer definition 219 * @{ 220 */ 221 222 typedef void (*pCRYP_CallbackTypeDef)(CRYP_HandleTypeDef *hcryp); /*!< pointer to a common CRYP callback function */ 223 224 /** 225 * @} 226 */ 227 228 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */ 229 230 /** 231 * @} 232 */ 233 234 /* Exported constants --------------------------------------------------------*/ 235 /** @defgroup CRYP_Exported_Constants CRYP Exported Constants 236 * @{ 237 */ 238 239 /** @defgroup CRYP_Error_Definition CRYP Error Definition 240 * @{ 241 */ 242 #define HAL_CRYP_ERROR_NONE 0x00000000U /*!< No error */ 243 #define HAL_CRYP_ERROR_WRITE 0x00000001U /*!< Write error */ 244 #define HAL_CRYP_ERROR_READ 0x00000002U /*!< Read error */ 245 #define HAL_CRYP_ERROR_DMA 0x00000004U /*!< DMA error */ 246 #define HAL_CRYP_ERROR_BUSY 0x00000008U /*!< Busy flag error */ 247 #define HAL_CRYP_ERROR_TIMEOUT 0x00000010U /*!< Timeout error */ 248 #define HAL_CRYP_ERROR_NOT_SUPPORTED 0x00000020U /*!< Not supported mode */ 249 #define HAL_CRYP_ERROR_AUTH_TAG_SEQUENCE 0x00000040U /*!< Sequence are not respected only for GCM or CCM */ 250 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1U) 251 #define HAL_CRYP_ERROR_INVALID_CALLBACK ((uint32_t)0x00000080U) /*!< Invalid Callback error */ 252 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */ 253 254 /** 255 * @} 256 */ 257 258 /** @defgroup CRYP_Data_Width_Unit CRYP Data Width Unit 259 * @{ 260 */ 261 262 #define CRYP_DATAWIDTHUNIT_WORD 0x00000000U /*!< By default, size unit is word */ 263 #define CRYP_DATAWIDTHUNIT_BYTE 0x00000001U /*!< By default, size unit is byte */ 264 265 /** 266 * @} 267 */ 268 269 /** @defgroup CRYP_Header_Width_Unit CRYP Header Width Unit 270 * @{ 271 */ 272 273 #define CRYP_HEADERWIDTHUNIT_WORD 0x00000000U /*!< By default, header size unit is word */ 274 #define CRYP_HEADERWIDTHUNIT_BYTE 0x00000001U /*!< By default, header size unit is byte */ 275 276 /** 277 * @} 278 */ 279 280 /** @defgroup CRYP_Algorithm_Mode CRYP Algorithm Mode 281 * @{ 282 */ 283 284 #define CRYP_AES_ECB 0x00000000U /*!< Electronic codebook chaining algorithm */ 285 #define CRYP_AES_CBC AES_CR_CHMOD_0 /*!< Cipher block chaining algorithm */ 286 #define CRYP_AES_CTR AES_CR_CHMOD_1 /*!< Counter mode chaining algorithm */ 287 #define CRYP_AES_GCM_GMAC (AES_CR_CHMOD_0 | AES_CR_CHMOD_1) /*!< Galois counter mode - Galois message authentication code */ 288 #define CRYP_AES_CCM AES_CR_CHMOD_2 /*!< Counter with Cipher Mode */ 289 290 /** 291 * @} 292 */ 293 294 /** @defgroup CRYP_Key_Size CRYP Key Size 295 * @{ 296 */ 297 298 #define CRYP_KEYSIZE_128B 0x00000000U /*!< 128-bit long key */ 299 #define CRYP_KEYSIZE_256B AES_CR_KEYSIZE /*!< 256-bit long key */ 300 301 /** 302 * @} 303 */ 304 305 /** @defgroup CRYP_Data_Type CRYP Data Type 306 * @{ 307 */ 308 309 #define CRYP_DATATYPE_32B 0x00000000U /*!< 32-bit data type (no swapping) */ 310 #define CRYP_DATATYPE_16B AES_CR_DATATYPE_0 /*!< 16-bit data type (half-word swapping) */ 311 #define CRYP_DATATYPE_8B AES_CR_DATATYPE_1 /*!< 8-bit data type (byte swapping) */ 312 #define CRYP_DATATYPE_1B AES_CR_DATATYPE /*!< 1-bit data type (bit swapping) */ 313 314 /** 315 * @} 316 */ 317 318 /** @defgroup CRYP_Interrupt CRYP Interrupt 319 * @{ 320 */ 321 322 #define CRYP_IT_CCFIE AES_CR_CCFIE /*!< Computation Complete interrupt enable */ 323 #define CRYP_IT_ERRIE AES_CR_ERRIE /*!< Error interrupt enable */ 324 #define CRYP_IT_WRERR AES_SR_WRERR /*!< Write Error */ 325 #define CRYP_IT_RDERR AES_SR_RDERR /*!< Read Error */ 326 #define CRYP_IT_CCF AES_SR_CCF /*!< Computation completed */ 327 328 /** 329 * @} 330 */ 331 332 /** @defgroup CRYP_Flags CRYP Flags 333 * @{ 334 */ 335 336 /* status flags */ 337 #define CRYP_FLAG_BUSY AES_SR_BUSY /*!< GCM process suspension forbidden */ 338 #define CRYP_FLAG_WRERR AES_SR_WRERR /*!< Write Error */ 339 #define CRYP_FLAG_RDERR AES_SR_RDERR /*!< Read error */ 340 #define CRYP_FLAG_CCF AES_SR_CCF /*!< Computation completed */ 341 /* clearing flags */ 342 #define CRYP_CCF_CLEAR AES_CR_CCFC /*!< Computation Complete Flag Clear */ 343 #define CRYP_ERR_CLEAR AES_CR_ERRC /*!< Error Flag Clear */ 344 345 /** 346 * @} 347 */ 348 349 /** @defgroup CRYP_Configuration_Skip CRYP Key and IV Configuration Skip Mode 350 * @{ 351 */ 352 353 #define CRYP_KEYIVCONFIG_ALWAYS 0x00000000U /*!< Peripheral Key and IV configuration to do systematically */ 354 #define CRYP_KEYIVCONFIG_ONCE 0x00000001U /*!< Peripheral Key and IV configuration to do only once */ 355 356 /** 357 * @} 358 */ 359 360 361 /** 362 * @} 363 */ 364 365 /* Exported macros -----------------------------------------------------------*/ 366 /** @defgroup CRYP_Exported_Macros CRYP Exported Macros 367 * @{ 368 */ 369 370 /** @brief Reset CRYP handle state 371 * @param __HANDLE__ specifies the CRYP handle. 372 * @retval None 373 */ 374 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1U) 375 #define __HAL_CRYP_RESET_HANDLE_STATE(__HANDLE__) do{\ 376 (__HANDLE__)->State = HAL_CRYP_STATE_RESET;\ 377 (__HANDLE__)->MspInitCallback = NULL;\ 378 (__HANDLE__)->MspDeInitCallback = NULL;\ 379 }while(0U) 380 #else 381 #define __HAL_CRYP_RESET_HANDLE_STATE(__HANDLE__) ( (__HANDLE__)->State = HAL_CRYP_STATE_RESET) 382 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */ 383 384 /** 385 * @brief Enable/Disable the CRYP peripheral. 386 * @param __HANDLE__ specifies the CRYP handle. 387 * @retval None 388 */ 389 390 #define __HAL_CRYP_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= AES_CR_EN) 391 #define __HAL_CRYP_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~AES_CR_EN) 392 393 394 /** @brief Check whether the specified CRYP status flag is set or not. 395 * @param __HANDLE__ specifies the CRYP handle. 396 * @param __FLAG__ specifies the flag to check. 397 * This parameter can be one of the following values for TinyAES: 398 * @arg @ref CRYP_FLAG_BUSY GCM process suspension forbidden 399 * @arg @ref CRYP_IT_WRERR Write Error 400 * @arg @ref CRYP_IT_RDERR Read Error 401 * @arg @ref CRYP_IT_CCF Computation Complete 402 * This parameter can be one of the following values for CRYP: 403 * @arg CRYP_FLAG_BUSY: The CRYP core is currently processing a block of data 404 * or a key preparation (for AES decryption). 405 * @arg CRYP_FLAG_IFEM: Input FIFO is empty 406 * @arg CRYP_FLAG_IFNF: Input FIFO is not full 407 * @arg CRYP_FLAG_INRIS: Input FIFO service raw interrupt is pending 408 * @arg CRYP_FLAG_OFNE: Output FIFO is not empty 409 * @arg CRYP_FLAG_OFFU: Output FIFO is full 410 * @arg CRYP_FLAG_OUTRIS: Input FIFO service raw interrupt is pending 411 * @retval The state of __FLAG__ (TRUE or FALSE). 412 */ 413 414 #define CRYP_FLAG_MASK 0x0000001FU 415 #define __HAL_CRYP_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__)) 416 417 /** @brief Clear the CRYP pending status flag. 418 * @param __HANDLE__ specifies the CRYP handle. 419 * @param __FLAG__ specifies the flag to clear. 420 * This parameter can be one of the following values: 421 * @arg @ref CRYP_ERR_CLEAR Read (RDERR) or Write Error (WRERR) Flag Clear 422 * @arg @ref CRYP_CCF_CLEAR Computation Complete Flag (CCF) Clear 423 * @retval None 424 */ 425 426 #define __HAL_CRYP_CLEAR_FLAG(__HANDLE__, __FLAG__) SET_BIT((__HANDLE__)->Instance->CR, (__FLAG__)) 427 428 429 /** @brief Check whether the specified CRYP interrupt source is enabled or not. 430 * @param __HANDLE__ specifies the CRYP handle. 431 * @param __INTERRUPT__ CRYP interrupt source to check 432 * This parameter can be one of the following values for TinyAES: 433 * @arg @ref CRYP_IT_ERRIE Error interrupt (used for RDERR and WRERR) 434 * @arg @ref CRYP_IT_CCFIE Computation Complete interrupt 435 * @retval State of interruption (TRUE or FALSE). 436 */ 437 438 #define __HAL_CRYP_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR &\ 439 (__INTERRUPT__)) == (__INTERRUPT__)) 440 441 /** @brief Check whether the specified CRYP interrupt is set or not. 442 * @param __HANDLE__ specifies the CRYP handle. 443 * @param __INTERRUPT__ specifies the interrupt to check. 444 * This parameter can be one of the following values for TinyAES: 445 * @arg @ref CRYP_IT_WRERR Write Error 446 * @arg @ref CRYP_IT_RDERR Read Error 447 * @arg @ref CRYP_IT_CCF Computation Complete 448 * This parameter can be one of the following values for CRYP: 449 * @arg CRYP_IT_INI: Input FIFO service masked interrupt status 450 * @arg CRYP_IT_OUTI: Output FIFO service masked interrupt status 451 * @retval The state of __INTERRUPT__ (TRUE or FALSE). 452 */ 453 454 #define __HAL_CRYP_GET_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->SR & (__INTERRUPT__)) == (__INTERRUPT__)) 455 456 /** 457 * @brief Enable the CRYP interrupt. 458 * @param __HANDLE__ specifies the CRYP handle. 459 * @param __INTERRUPT__ CRYP Interrupt. 460 * This parameter can be one of the following values for TinyAES: 461 * @arg @ref CRYP_IT_ERRIE Error interrupt (used for RDERR and WRERR) 462 * @arg @ref CRYP_IT_CCFIE Computation Complete interrupt 463 * This parameter can be one of the following values for CRYP: 464 * @ CRYP_IT_INI : Input FIFO service interrupt mask. 465 * @ CRYP_IT_OUTI : Output FIFO service interrupt mask.CRYP interrupt. 466 * @retval None 467 */ 468 469 #define __HAL_CRYP_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR) |= (__INTERRUPT__)) 470 471 /** 472 * @brief Disable the CRYP interrupt. 473 * @param __HANDLE__ specifies the CRYP handle. 474 * @param __INTERRUPT__ CRYP Interrupt. 475 * This parameter can be one of the following values for TinyAES: 476 * @arg @ref CRYP_IT_ERRIE Error interrupt (used for RDERR and WRERR) 477 * @arg @ref CRYP_IT_CCFIE Computation Complete interrupt 478 * This parameter can be one of the following values for CRYP: 479 * @ CRYP_IT_INI : Input FIFO service interrupt mask. 480 * @ CRYP_IT_OUTI : Output FIFO service interrupt mask.CRYP interrupt. 481 * @retval None 482 */ 483 484 #define __HAL_CRYP_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR) &= ~(__INTERRUPT__)) 485 486 /** 487 * @} 488 */ 489 490 /* Include CRYP HAL Extended module */ 491 #include "stm32l5xx_hal_cryp_ex.h" 492 493 /* Exported functions --------------------------------------------------------*/ 494 /** @defgroup CRYP_Exported_Functions CRYP Exported Functions 495 * @{ 496 */ 497 498 /** @addtogroup CRYP_Exported_Functions_Group1 499 * @{ 500 */ 501 HAL_StatusTypeDef HAL_CRYP_Init(CRYP_HandleTypeDef *hcryp); 502 HAL_StatusTypeDef HAL_CRYP_DeInit(CRYP_HandleTypeDef *hcryp); 503 void HAL_CRYP_MspInit(CRYP_HandleTypeDef *hcryp); 504 void HAL_CRYP_MspDeInit(CRYP_HandleTypeDef *hcryp); 505 HAL_StatusTypeDef HAL_CRYP_SetConfig(CRYP_HandleTypeDef *hcryp, CRYP_ConfigTypeDef *pConf); 506 HAL_StatusTypeDef HAL_CRYP_GetConfig(CRYP_HandleTypeDef *hcryp, CRYP_ConfigTypeDef *pConf); 507 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1U) 508 HAL_StatusTypeDef HAL_CRYP_RegisterCallback(CRYP_HandleTypeDef *hcryp, HAL_CRYP_CallbackIDTypeDef CallbackID, 509 pCRYP_CallbackTypeDef pCallback); 510 HAL_StatusTypeDef HAL_CRYP_UnRegisterCallback(CRYP_HandleTypeDef *hcryp, HAL_CRYP_CallbackIDTypeDef CallbackID); 511 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */ 512 #if (USE_HAL_CRYP_SUSPEND_RESUME == 1U) 513 void HAL_CRYP_ProcessSuspend(CRYP_HandleTypeDef *hcryp); 514 HAL_StatusTypeDef HAL_CRYP_Suspend(CRYP_HandleTypeDef *hcryp); 515 HAL_StatusTypeDef HAL_CRYP_Resume(CRYP_HandleTypeDef *hcryp); 516 #endif /* defined (USE_HAL_CRYP_SUSPEND_RESUME) */ 517 /** 518 * @} 519 */ 520 521 /** @addtogroup CRYP_Exported_Functions_Group2 522 * @{ 523 */ 524 525 /* encryption/decryption ***********************************/ 526 HAL_StatusTypeDef HAL_CRYP_Encrypt(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output, 527 uint32_t Timeout); 528 HAL_StatusTypeDef HAL_CRYP_Decrypt(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output, 529 uint32_t Timeout); 530 HAL_StatusTypeDef HAL_CRYP_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output); 531 HAL_StatusTypeDef HAL_CRYP_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output); 532 HAL_StatusTypeDef HAL_CRYP_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output); 533 HAL_StatusTypeDef HAL_CRYP_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output); 534 535 /** 536 * @} 537 */ 538 539 540 /** @addtogroup CRYP_Exported_Functions_Group3 541 * @{ 542 */ 543 /* Interrupt Handler functions **********************************************/ 544 void HAL_CRYP_IRQHandler(CRYP_HandleTypeDef *hcryp); 545 HAL_CRYP_STATETypeDef HAL_CRYP_GetState(CRYP_HandleTypeDef *hcryp); 546 void HAL_CRYP_InCpltCallback(CRYP_HandleTypeDef *hcryp); 547 void HAL_CRYP_OutCpltCallback(CRYP_HandleTypeDef *hcryp); 548 void HAL_CRYP_ErrorCallback(CRYP_HandleTypeDef *hcryp); 549 uint32_t HAL_CRYP_GetError(CRYP_HandleTypeDef *hcryp); 550 551 /** 552 * @} 553 */ 554 555 /** 556 * @} 557 */ 558 559 /* Private macros --------------------------------------------------------*/ 560 /** @defgroup CRYP_Private_Macros CRYP Private Macros 561 * @{ 562 */ 563 564 /** @defgroup CRYP_IS_CRYP_Definitions CRYP Private macros to check input parameters 565 * @{ 566 */ 567 568 #define IS_CRYP_ALGORITHM(ALGORITHM) (((ALGORITHM) == CRYP_AES_ECB) || \ 569 ((ALGORITHM) == CRYP_AES_CBC) || \ 570 ((ALGORITHM) == CRYP_AES_CTR) || \ 571 ((ALGORITHM) == CRYP_AES_GCM_GMAC)|| \ 572 ((ALGORITHM) == CRYP_AES_CCM)) 573 574 575 #define IS_CRYP_KEYSIZE(KEYSIZE)(((KEYSIZE) == CRYP_KEYSIZE_128B) || \ 576 ((KEYSIZE) == CRYP_KEYSIZE_256B)) 577 578 #define IS_CRYP_DATATYPE(DATATYPE)(((DATATYPE) == CRYP_DATATYPE_32B) || \ 579 ((DATATYPE) == CRYP_DATATYPE_16B) || \ 580 ((DATATYPE) == CRYP_DATATYPE_8B) || \ 581 ((DATATYPE) == CRYP_DATATYPE_1B)) 582 583 #define IS_CRYP_INIT(CONFIG)(((CONFIG) == CRYP_KEYIVCONFIG_ALWAYS) || \ 584 ((CONFIG) == CRYP_KEYIVCONFIG_ONCE)) 585 586 #define IS_CRYP_BUFFERSIZE(ALGO, DATAWIDTH, SIZE) \ 587 (((((ALGO) == CRYP_AES_CTR)) && \ 588 ((((DATAWIDTH) == CRYP_DATAWIDTHUNIT_WORD) && (((SIZE) % 4U) == 0U)) || \ 589 (((DATAWIDTH) == CRYP_DATAWIDTHUNIT_BYTE) && (((SIZE) % 16U) == 0U)))) || \ 590 (((ALGO) == CRYP_AES_ECB) || ((ALGO) == CRYP_AES_CBC) || \ 591 ((ALGO)== CRYP_AES_GCM_GMAC) || ((ALGO) == CRYP_AES_CCM))) 592 593 /** 594 * @} 595 */ 596 597 /** 598 * @} 599 */ 600 601 602 /* Private constants ---------------------------------------------------------*/ 603 /** @defgroup CRYP_Private_Constants CRYP Private Constants 604 * @{ 605 */ 606 607 /** 608 * @} 609 */ 610 /* Private defines -----------------------------------------------------------*/ 611 /** @defgroup CRYP_Private_Defines CRYP Private Defines 612 * @{ 613 */ 614 615 /** 616 * @} 617 */ 618 619 /* Private variables ---------------------------------------------------------*/ 620 /** @defgroup CRYP_Private_Variables CRYP Private Variables 621 * @{ 622 */ 623 624 /** 625 * @} 626 */ 627 628 /* Private functions ---------------------------------------------------------*/ 629 /** @defgroup CRYP_Private_Functions CRYP Private Functions 630 * @{ 631 */ 632 633 /** 634 * @} 635 */ 636 637 /** 638 * @} 639 */ 640 641 #endif /* AES */ 642 /** 643 * @} 644 */ 645 646 #ifdef __cplusplus 647 } 648 #endif 649 650 #endif /* STM32L5xx_HAL_CRYP_H */ 651