1 /** 2 ****************************************************************************** 3 * @file stm32n6xx_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 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 STM32N6xx_HAL_CRYP_H 21 #define STM32N6xx_HAL_CRYP_H 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 #if defined(USE_HAL_SAES_ONLY) && (USE_HAL_SAES_ONLY == 1U) 28 #if !defined(USE_HAL_CRYP_ONLY) 29 #define USE_HAL_CRYP_ONLY 0U 30 #elif (USE_HAL_CRYP_ONLY == 1U) 31 #error ' USE_HAL_CRYP_ONLY and USE_HAL_SAES_ONLY cannot be set both to 1U ' 32 #endif /* defined (USE_HAL_CRYP_ONLY) */ 33 #endif /* defined (USE_HAL_SAES_ONLY) */ 34 35 #if defined(USE_HAL_CRYP_ONLY) && (USE_HAL_CRYP_ONLY == 1U) 36 #if !defined(USE_HAL_SAES_ONLY) 37 #define USE_HAL_SAES_ONLY 0U 38 #elif (USE_HAL_SAES_ONLY == 1U) 39 #error ' USE_HAL_CRYP_ONLY and USE_HAL_SAES_ONLY cannot be set both to 1U ' 40 #endif /* defined (USE_HAL_SAES_ONLY) */ 41 #endif /* defined (USE_HAL_CRYP_ONLY) */ 42 43 /* Includes ------------------------------------------------------------------*/ 44 #include "stm32n6xx_hal_def.h" 45 46 /** @addtogroup STM32N6xx_HAL_Driver 47 * @{ 48 */ 49 #if defined (CRYP) 50 /** @addtogroup CRYP 51 * @{ 52 */ 53 54 /* Exported types ------------------------------------------------------------*/ 55 /** @defgroup CRYP_Exported_Types CRYP Exported Types 56 * @{ 57 */ 58 59 /** 60 * @brief CRYP Init Structure definition 61 */ 62 63 typedef struct 64 { 65 uint32_t DataType; /*!< 32-bit data, 16-bit data, 8-bit data or 1-bit string. 66 This parameter can be a value of @ref CRYP_Data_Type */ 67 uint32_t KeySize; /*!< Used only in AES mode : 128, 192 or 256 bit key length in CRYP1. 68 This parameter can be a value of @ref CRYP_Key_Size */ 69 uint32_t *pKey; /*!< The key used for encryption/decryption */ 70 uint32_t *pInitVect; /*!< The initialization vector used also as initialization 71 counter in CTR mode */ 72 uint32_t Algorithm; /*!< AES Algorithm ECB/CBC/CTR/GCM or CCM 73 This parameter can be a value of @ref CRYP_CR_ALGOMODE */ 74 uint32_t *Header; /*!< used only in AES GCM and CCM Algorithm for authentication, 75 GCM : also known as Additional Authentication Data 76 CCM : named B1 composed of the associated data length and Associated Data. */ 77 uint32_t HeaderSize; /*!< The size of header buffer in word */ 78 uint32_t *B0; /*!< B0 is first authentication block used only in AES CCM mode */ 79 uint32_t DataWidthUnit; /*!< Data With Unit, this parameter can be value of @ref CRYP_Data_Width_Unit*/ 80 uint32_t HeaderWidthUnit; /*!< Header Width Unit, this parameter can be value 81 of @ref CRYP_Header_Width_Unit */ 82 uint32_t KeyIVConfigSkip; /*!< CRYP peripheral Key and IV configuration skip, 83 to configure Key and Initialization 84 Vector only once and to skip configuration for consecutive processing. 85 This parameter can be a value of @ref CRYP_Configuration_Skip */ 86 uint32_t KeyMode; /*!< Key mode selection, this parameter can be a value of @ref CRYP_Key_Mode */ 87 uint32_t KeySelect; /*!< Only for SAES : Key selection, this parameter can be a value 88 of @ref CRYP_Key_Select */ 89 uint32_t KeyProtection; /*!< Only for SAES : Key protection, this parameter can be a value of @ref CRYP_Key_Protection */ 90 91 } CRYP_ConfigTypeDef; 92 93 94 /** 95 * @brief CRYP State Structure definition 96 */ 97 98 typedef enum 99 { 100 HAL_CRYP_STATE_RESET = 0x00U, /*!< CRYP not yet initialized or disabled */ 101 HAL_CRYP_STATE_READY = 0x01U, /*!< CRYP initialized and ready for use */ 102 HAL_CRYP_STATE_BUSY = 0x02U, /*!< CRYP BUSY, internal processing is ongoing */ 103 #if (USE_HAL_CRYP_SUSPEND_RESUME == 1U) 104 HAL_CRYP_STATE_SUSPENDED = 0x03U, /*!< CRYP suspended */ 105 #endif /* USE_HAL_CRYP_SUSPEND_RESUME */ 106 } HAL_CRYP_STATETypeDef; 107 108 109 #if (USE_HAL_CRYP_SUSPEND_RESUME == 1U) 110 /** 111 * @brief HAL CRYP mode suspend definitions 112 */ 113 114 typedef enum 115 { 116 HAL_CRYP_SUSPEND_NONE = 0x00U, /*!< CRYP processing suspension not requested */ 117 HAL_CRYP_SUSPEND = 0x01U /*!< CRYP processing suspension requested */ 118 } HAL_SuspendTypeDef; 119 #endif /* USE_HAL_CRYP_SUSPEND_RESUME */ 120 121 /** 122 * @brief CRYP handle Structure definition 123 */ 124 125 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1U) 126 typedef struct __CRYP_HandleTypeDef 127 #else 128 typedef struct 129 #endif /* (USE_HAL_CRYP_REGISTER_CALLBACKS) */ 130 { 131 void *Instance; /*!< CRYP or SAES registers base address */ 132 133 CRYP_ConfigTypeDef Init; /*!< CRYP required parameters */ 134 135 uint32_t *pCrypInBuffPtr; /*!< Pointer to CRYP processing (encryption, decryption,...) 136 buffer */ 137 138 uint32_t *pCrypOutBuffPtr; /*!< Pointer to CRYP processing (encryption, decryption,...) 139 buffer */ 140 141 __IO uint16_t CrypHeaderCount; /*!< Counter of header data */ 142 143 __IO uint16_t CrypInCount; /*!< Counter of input data */ 144 145 __IO uint16_t CrypOutCount; /*!< Counter of output data */ 146 147 uint16_t Size; /*!< length of input data in word or in byte, 148 according to DataWidthUnit */ 149 150 uint32_t Phase; /*!< CRYP peripheral phase */ 151 152 DMA_HandleTypeDef *hdmain; /*!< CRYP In DMA handle parameters */ 153 154 DMA_HandleTypeDef *hdmaout; /*!< CRYP Out DMA handle parameters */ 155 156 HAL_LockTypeDef Lock; /*!< CRYP locking object */ 157 158 __IO HAL_CRYP_STATETypeDef State; /*!< CRYP peripheral state */ 159 160 __IO uint32_t ErrorCode; /*!< CRYP peripheral error code */ 161 162 uint32_t Version; /*!< CRYP1 IP version*/ 163 164 uint32_t KeyIVConfig; /*!< CRYP peripheral Key and IV configuration flag, used when 165 configuration can be skipped */ 166 167 uint32_t SizesSum; /*!< Sum of successive payloads lengths (in bytes), stored 168 for a single signature computation after several 169 messages processing */ 170 171 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1U) 172 void (*InCpltCallback)(struct __CRYP_HandleTypeDef *hcryp); /*!< CRYP Input FIFO transfer completed callback */ 173 void (*OutCpltCallback)(struct __CRYP_HandleTypeDef *hcryp); /*!< CRYP Output FIFO transfer completed callback */ 174 void (*ErrorCallback)(struct __CRYP_HandleTypeDef *hcryp); /*!< CRYP Error callback */ 175 176 void (* MspInitCallback)(struct __CRYP_HandleTypeDef *hcryp); /*!< CRYP Msp Init callback */ 177 void (* MspDeInitCallback)(struct __CRYP_HandleTypeDef *hcryp); /*!< CRYP Msp DeInit callback */ 178 179 #endif /* (USE_HAL_CRYP_REGISTER_CALLBACKS) */ 180 181 #if (USE_HAL_CRYP_SUSPEND_RESUME == 1U) 182 183 __IO HAL_SuspendTypeDef SuspendRequest; /*!< CRYP peripheral suspension request flag */ 184 185 CRYP_ConfigTypeDef Init_saved; /*!< copy of CRYP required parameters when processing 186 is suspended */ 187 188 uint32_t *pCrypInBuffPtr_saved; /*!< copy of CRYP input pointer when processing 189 is suspended */ 190 191 uint32_t *pCrypOutBuffPtr_saved; /*!< copy of CRYP output pointer when processing 192 is suspended */ 193 194 uint32_t CrypInCount_saved; /*!< copy of CRYP input data counter when processing 195 is suspended */ 196 197 uint32_t CrypOutCount_saved; /*!< copy of CRYP output data counter when processing 198 is suspended */ 199 200 uint32_t Phase_saved; /*!< copy of CRYP authentication phase when processing 201 is suspended */ 202 203 __IO HAL_CRYP_STATETypeDef State_saved; /*!< copy of CRYP peripheral state when processing 204 is suspended */ 205 206 uint32_t IV_saved[4]; /*!< copy of Initialisation Vector registers */ 207 208 uint32_t SUSPxR_saved[16]; /*!< copy of suspension registers */ 209 210 uint32_t CR_saved; /*!< copy of CRYP control register when processing 211 is suspended*/ 212 213 uint32_t Key_saved[8]; /*!< copy of key registers */ 214 215 uint16_t Size_saved; /*!< copy of input buffer size */ 216 217 uint16_t CrypHeaderCount_saved; /*!< copy of CRYP header data counter when processing 218 is suspended */ 219 220 uint32_t SizesSum_saved; /*!< copy of SizesSum when processing is suspended */ 221 222 uint32_t ResumingFlag; /*!< resumption flag to bypass steps already carried out */ 223 224 uint32_t SuspendedProcessing; /*< Report whether interruption or DMA-mode processing 225 was suspended */ 226 #endif /* USE_HAL_CRYP_SUSPEND_RESUME */ 227 228 } CRYP_HandleTypeDef; 229 230 231 /** 232 * @} 233 */ 234 235 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1U) 236 /** @defgroup HAL_CRYP_Callback_ID_enumeration_definition HAL CRYP Callback ID enumeration definition 237 * @brief HAL CRYP Callback ID enumeration definition 238 * @{ 239 */ 240 typedef enum 241 { 242 HAL_CRYP_INPUT_COMPLETE_CB_ID = 0x01U, /*!< CRYP Input FIFO transfer completed callback ID */ 243 HAL_CRYP_OUTPUT_COMPLETE_CB_ID = 0x02U, /*!< CRYP Output FIFO transfer completed callback ID */ 244 HAL_CRYP_ERROR_CB_ID = 0x03U, /*!< CRYP Error callback ID */ 245 HAL_CRYP_MSPINIT_CB_ID = 0x04U, /*!< CRYP MspInit callback ID */ 246 HAL_CRYP_MSPDEINIT_CB_ID = 0x05U /*!< CRYP MspDeInit callback ID */ 247 248 } HAL_CRYP_CallbackIDTypeDef; 249 /** 250 * @} 251 */ 252 253 /** @defgroup HAL_CRYP_Callback_pointer_definition HAL CRYP Callback pointer definition 254 * @brief HAL CRYP Callback pointer definition 255 * @{ 256 */ 257 258 typedef void (*pCRYP_CallbackTypeDef)(CRYP_HandleTypeDef *hcryp); /*!< pointer to a common CRYP callback function */ 259 260 /** 261 * @} 262 */ 263 264 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */ 265 266 /* Exported constants --------------------------------------------------------*/ 267 /** @defgroup CRYP_Exported_Constants CRYP Exported Constants 268 * @{ 269 */ 270 271 /** @defgroup CRYP_Error_Definition CRYP Error Definition 272 * @{ 273 */ 274 #define HAL_CRYP_ERROR_NONE 0x00000000U /*!< No error */ 275 #define HAL_CRYP_ERROR_WRITE 0x00000001U /*!< Write error */ 276 #define HAL_CRYP_ERROR_READ 0x00000002U /*!< Read error */ 277 #define HAL_CRYP_ERROR_DMA 0x00000004U /*!< DMA error */ 278 #define HAL_CRYP_ERROR_BUSY 0x00000008U /*!< Busy flag error */ 279 #define HAL_CRYP_ERROR_TIMEOUT 0x00000010U /*!< Timeout error */ 280 #define HAL_CRYP_ERROR_NOT_SUPPORTED 0x00000020U /*!< Not supported mode */ 281 #define HAL_CRYP_ERROR_AUTH_TAG_SEQUENCE 0x00000040U /*!< Sequence are not respected only for GCM or CCM */ 282 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1U) 283 #define HAL_CRYP_ERROR_INVALID_CALLBACK ((uint32_t)0x00000080U) /*!< Invalid Callback error */ 284 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */ 285 #define HAL_CRYP_ERROR_KEY 0x00000100U /*!< Key error */ 286 #define HAL_CRYP_ERROR_RNG 0x00000200U /*!< RNG error */ 287 288 /** 289 * @} 290 */ 291 292 293 /** @defgroup CRYP_Data_Width_Unit CRYP Data Width Unit 294 * @{ 295 */ 296 297 #define CRYP_DATAWIDTHUNIT_WORD 0x00000000U /*!< By default, size unit is word */ 298 #define CRYP_DATAWIDTHUNIT_BYTE 0x00000001U /*!< By default, size unit is byte */ 299 300 /** 301 * @} 302 */ 303 304 /** @defgroup CRYP_Header_Width_Unit CRYP Header Width Unit 305 * @{ 306 */ 307 308 #define CRYP_HEADERWIDTHUNIT_WORD 0x00000000U /*!< By default, size unit is word */ 309 #define CRYP_HEADERWIDTHUNIT_BYTE 0x00000001U /*!< By default, size unit is byte */ 310 311 /** 312 * @} 313 */ 314 315 #if !defined(USE_HAL_SAES_ONLY) || (USE_HAL_SAES_ONLY == 1) 316 /** @defgroup SAES_CR_CHMOD SAES CHMOD Selection 317 * @{ 318 */ 319 320 #define SAES_CR_CHMOD_AES_ECB ((uint32_t)0x00000000) 321 #define SAES_CR_CHMOD_AES_CBC (SAES_CR_CHMOD_0) 322 #define SAES_CR_CHMOD_AES_CTR (SAES_CR_CHMOD_1) 323 #define SAES_CR_CHMOD_AES_GCM (SAES_CR_CHMOD_0 | SAES_CR_CHMOD_1) 324 #define SAES_CR_CHMOD_AES_CCM (SAES_CR_CHMOD_2) 325 326 /** 327 * @} 328 */ 329 #endif /* USE_HAL_SAES_ONLY */ 330 331 /** @defgroup CRYP_CR_ALGOMODE CRYP Algorithm Mode 332 * @{ 333 */ 334 335 #define CRYP_AES_ECB (CRYP_CR_ALGOMODE_2) 336 #define CRYP_AES_CBC (CRYP_CR_ALGOMODE_0 | CRYP_CR_ALGOMODE_2) 337 #define CRYP_AES_CTR (CRYP_CR_ALGOMODE_1 | CRYP_CR_ALGOMODE_2) 338 #define CRYP_AES_KEY (CRYP_CR_ALGOMODE_0 | CRYP_CR_ALGOMODE_1 | CRYP_CR_ALGOMODE_2) 339 #define CRYP_AES_GCM (CRYP_CR_ALGOMODE_3) 340 #define CRYP_AES_CCM (CRYP_CR_ALGOMODE_0 | CRYP_CR_ALGOMODE_3) 341 342 /** 343 * @} 344 */ 345 346 /** @defgroup CRYP_Key_Size CRYP Key Size 347 * @{ 348 */ 349 350 #define CRYP_KEYSIZE_128B 0x00000000U 351 #define CRYP_KEYSIZE_192B CRYP_CR_KEYSIZE_0 352 #define CRYP_KEYSIZE_256B CRYP_CR_KEYSIZE_1 353 354 /** 355 * @} 356 */ 357 358 /** @defgroup CRYP_Data_Type CRYP Data Type 359 * @{ 360 */ 361 362 #define CRYP_DATATYPE_32B 0x00000000U 363 #define CRYP_DATATYPE_16B CRYP_CR_DATATYPE_0 364 #define CRYP_DATATYPE_8B CRYP_CR_DATATYPE_1 365 #define CRYP_DATATYPE_1B CRYP_CR_DATATYPE 366 367 #define CRYP_NO_SWAP CRYP_DATATYPE_32B /*!< 32-bit data type (no swapping) */ 368 #define CRYP_HALFWORD_SWAP CRYP_DATATYPE_16B /*!< 16-bit data type (half-word swapping) */ 369 #define CRYP_BYTE_SWAP CRYP_DATATYPE_8B /*!< 8-bit data type (byte swapping) */ 370 #define CRYP_BIT_SWAP CRYP_DATATYPE_1B /*!< 1-bit data type (bit swapping) */ 371 /** 372 * @} 373 */ 374 375 /** @defgroup CRYP_Interrupt CRYP and SAES peripherals interrupts 376 * @{ 377 */ 378 379 #define CRYP_IT_INI CRYP_IMSCR_INIM /*!< CRYP peripheral input FIFO Interrupt */ 380 #define CRYP_IT_OUTI CRYP_IMSCR_OUTIM /*!< CRYP peripheral output FIFO Interrupt */ 381 382 #define CRYP_IT_CCFIE SAES_IER_CCFIE /*!< SAES peripheral computation Complete interrupt enable */ 383 #define CRYP_IT_RWEIE SAES_IER_RWEIE /*!< SAES peripheral read or write Error interrupt enable */ 384 #define CRYP_IT_KEIE SAES_IER_KEIE /*!< SAES peripheral key error interrupt enable */ 385 #define CRYP_IT_RNGEIE SAES_IER_RNGEIE /*!< SAES peripheral RNG error interrupt enable */ 386 387 /** 388 * @} 389 */ 390 391 /** @defgroup CRYP_Flags CRYP & SAES Flags 392 * @{ 393 */ 394 395 /* Flags in the SR register */ 396 #define CRYP_FLAG_IFEM CRYP_SR_IFEM /*!< CRYP peripheral Input FIFO is empty */ 397 #define CRYP_FLAG_IFNF CRYP_SR_IFNF /*!< CRYP peripheral Input FIFO is not Full */ 398 #define CRYP_FLAG_OFNE CRYP_SR_OFNE /*!< CRYP peripheral Output FIFO is not empty */ 399 #define CRYP_FLAG_OFFU CRYP_SR_OFFU /*!< CRYP peripheral Output FIFO is Full */ 400 #define CRYP_FLAG_KERF CRYP_SR_KERF /*!< CRYP peripheral Key error flag */ 401 /* Flags in the RISR register */ 402 #define CRYP_FLAG_OUTRIS 0x01000002U /*!< Output FIFO service raw interrupt status */ 403 #define CRYP_FLAG_INRIS 0x01000001U /*!< Input FIFO service raw interrupt status*/ 404 405 #define CRYP_FLAG_BUSY CRYP_SR_BUSY /*!< The CRYP peripheral is currently processing a block of data 406 or a key preparation (for AES decryption). */ 407 408 409 #define CRYP_FLAG_KEYVALID CRYP_SR_KEYVALID /*!< CRYP or SAES peripheral Key valid flag */ 410 411 #define SAES_FLAG_BUSY SAES_SR_BUSY /*!< The SAES peripheral is currently processing a block of data 412 or a key preparation (for AES decryption). */ 413 414 #define CRYP_FLAG_WRERR (SAES_SR_WRERR | 0x80000000U) /*!< SAES peripheral Write Error flag */ 415 #define CRYP_FLAG_RDERR (SAES_SR_RDERR | 0x80000000U) /*!< SAES peripheral Read error flag */ 416 #define CRYP_FLAG_CCF SAES_SR_CCF /*!< SAES peripheral Computation completed flag 417 as AES_ISR_CCF */ 418 #define CRYP_FLAG_KEIF SAES_ISR_KEIF /*!< SAES peripheral Key error interrupt flag */ 419 #define CRYP_FLAG_RWEIF SAES_ISR_RWEIF /*!< SAES peripheral Read or Write error Interrupt flag */ 420 #define CRYP_FLAG_RNGEIF SAES_ISR_RNGEIF /*!< SAES peripheral RNG error Interrupt flag */ 421 /** 422 * @} 423 */ 424 425 /** @defgroup CRYP_CLEAR_Flags SAES peripheral Clear Flags 426 * @{ 427 */ 428 #define CRYP_CLEAR_CCF SAES_ICR_CCF /*!< SAES peripheral clear Computation Complete Flag */ 429 #define CRYP_CLEAR_RWEIF SAES_ICR_RWEIF /*!< SAES peripheral clear Error Flag : RWEIF in SAES_ISR and 430 both RDERR and WRERR flags in SAES_SR */ 431 #define CRYP_CLEAR_KEIF SAES_ICR_KEIF /*!< SAES peripheral clear Key Error Flag: KEIF in SAES_ISR */ 432 #define CRYP_CLEAR_RNGEIF SAES_ICR_RNGEIF /*!< SAES peripheral clear RNG error Flag */ 433 434 /** 435 * @} 436 */ 437 438 439 /** @defgroup CRYP_Configuration_Skip CRYP Key and IV Configuration Skip Mode 440 * @{ 441 */ 442 443 #define CRYP_KEYIVCONFIG_ALWAYS 0x00000000U /*!< Peripheral Key and IV configuration 444 to do systematically */ 445 #define CRYP_KEYIVCONFIG_ONCE 0x00000001U /*!< Peripheral Key and IV configuration 446 to do only once */ 447 #define CRYP_KEYNOCONFIG 0x00000002U /*!< Peripheral Key configuration to not do */ 448 449 /** 450 * @} 451 */ 452 453 /** @defgroup CRYP_Key_Mode CRYP or SAES Key Mode 454 * @{ 455 */ 456 457 #define CRYP_KEYMODE_NORMAL 0x00000000U /*!< Normal key usage, Key registers are freely usable */ 458 #define CRYP_KEYMODE_WRAPPED SAES_CR_KMOD_0 /*!< Only for SAES, Wrapped key: to encrypt 459 or decrypt AES keys */ 460 #define CRYP_KEYMODE_SHARED SAES_CR_KMOD_1 /*!< Key shared by SAES peripheral */ 461 /** 462 * @} 463 */ 464 465 /** @defgroup CRYP_Key_Select SAES Key Select 466 * @{ 467 */ 468 469 #define CRYP_KEYSEL_NORMAL 0x00000000U /*!< Normal key, key registers SAES_KEYx or CRYP_KEYx */ 470 #define CRYP_KEYSEL_HW SAES_CR_KEYSEL_0 /*!< Only for SAES, Hardware key : derived hardware 471 unique key (DHUK 256-bit) */ 472 #define CRYP_KEYSEL_SW SAES_CR_KEYSEL_1 /*!< Only for SAES, Software key : boot hardware 473 key BHK (256-bit) */ 474 #define CRYP_KEYSEL_HSW SAES_CR_KEYSEL_2 /*!< Only for SAES, DHUK XOR BHK Hardware unique 475 key XOR software key */ 476 #define CRYP_KEYSEL_AHK (SAES_CR_KEYSEL_1|SAES_CR_KEYSEL_0) /*!< Only for SAES, Software key : 477 application hardware key AHK (128- or 256-bit) */ 478 #define CRYP_KEYSEL_DUK_AHK (SAES_CR_KEYSEL_2|SAES_CR_KEYSEL_0) /*!< Only for SAES, DHUK XOR AHK */ 479 #define CRYP_KEYSEL_TEST_KEY (SAES_CR_KEYSEL_2|SAES_CR_KEYSEL_1|SAES_CR_KEYSEL_0) /*!< Test mode key (256-bit 480 hardware constant key 0xA5A5...A5A5) */ 481 /** 482 * @} 483 */ 484 485 #if !defined(USE_HAL_SAES_ONLY) || (USE_HAL_SAES_ONLY == 1) 486 /** @defgroup CRYP_Key_Protection SAES Key Protection 487 * @{ 488 */ 489 490 #define CRYP_KEYPROT_ENABLE SAES_CR_KEYPROT /*!< Only for SAES, Key can't be shared between 491 two applications with different security contexts */ 492 #define CRYP_KEYPROT_DISABLE 0x00000000U /*!< Only for SAES, Key can be shared between 493 two applications with different security contexts */ 494 495 /** 496 * @} 497 */ 498 499 /** @defgroup CRYP_Key_Shared SAES Key Shared with Peripheral 500 * @{ 501 */ 502 503 #define CRYP_KEYSHARED_CRYP 0x00000000U /*!< Only for SAES, key is shared with CRYP peripheral */ 504 505 /** 506 * @} 507 */ 508 509 /** @defgroup CRYP_Mode SAES processing mode 510 * @{ 511 */ 512 513 #define CRYP_MODE_ENCRYPT 0x00000000U /*!< SAES peripheral encryption mode */ 514 #define CRYP_MODE_KEY_DERIVATION SAES_CR_MODE_0 /*!< SAES peripheral key derivation */ 515 #define CRYP_MODE_DECRYPT SAES_CR_MODE_1 /*!< SAES peripheral decryption mode */ 516 517 /** 518 * @} 519 */ 520 #endif /* USE_HAL_SAES_ONLY */ 521 522 /** @defgroup CRYP_Mode SAES processing mode 523 * @{ 524 */ 525 526 #define CRYP_OPERATINGMODE_ENCRYPT 0x00000000U /*!< CRYP peripheral encryption mode */ 527 #define CRYP_OPERATINGMODE_DECRYPT CRYP_CR_ALGODIR /*!< CRYP peripheral decryption mode */ 528 529 /** 530 * @} 531 */ 532 533 /* Exported macros -----------------------------------------------------------*/ 534 /** @defgroup CRYP_Exported_Macros CRYP Exported Macros 535 * @{ 536 */ 537 538 /** 539 * @brief Inform about which IP is the current INSTANCE: CRYP or SAES. 540 * @param INSTANCE: specifies the HW instance. 541 * @retval None 542 */ 543 #define IS_CRYP_INSTANCE(INSTANCE) ((INSTANCE) == CRYP) 544 #define IS_SAES_INSTANCE(INSTANCE) ((INSTANCE) == SAES) 545 546 /** @brief Reset CRYP handle state 547 * @param __HANDLE__ specifies the CRYP handle. 548 * @retval None 549 */ 550 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1U) 551 #define __HAL_CRYP_RESET_HANDLE_STATE(__HANDLE__) do{\ 552 (__HANDLE__)->State = HAL_CRYP_STATE_RESET;\ 553 (__HANDLE__)->MspInitCallback = NULL;\ 554 (__HANDLE__)->MspDeInitCallback = NULL;\ 555 }while(0) 556 #else 557 #define __HAL_CRYP_RESET_HANDLE_STATE(__HANDLE__) ( (__HANDLE__)->State = HAL_CRYP_STATE_RESET) 558 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */ 559 560 /** 561 * @brief Enable/Disable the CRYP or SAES peripheral. 562 * @param __HANDLE__: specifies the CRYP handle. 563 * @retval None 564 */ 565 566 #define __HAL_CRYP_ENABLE(__HANDLE__) ((IS_CRYP_INSTANCE((__HANDLE__)->Instance)) ? \ 567 (((CRYP_TypeDef *)((__HANDLE__)->Instance))->CR |= CRYP_CR_CRYPEN) :\ 568 (((SAES_TypeDef *)((__HANDLE__)->Instance))->CR |= SAES_CR_EN)) 569 570 #define __HAL_CRYP_DISABLE(__HANDLE__) ((IS_CRYP_INSTANCE((__HANDLE__)->Instance)) ? \ 571 (((CRYP_TypeDef *)((__HANDLE__)->Instance))->CR &= ~CRYP_CR_CRYPEN) :\ 572 (((SAES_TypeDef *)((__HANDLE__)->Instance))->CR &= ~SAES_CR_EN)) 573 574 /** @brief Check whether the specified CRYP or SAES peripheral status flag is set or not. 575 * @param __FLAG__: specifies the flag to check. 576 * This parameter can be one of the following values: 577 * @arg CRYP_FLAG_BUSY: The CRYP core is currently processing a block of data 578 * or a key preparation (for AES decryption) 579 * @arg @ref CRYP_FLAG_KEYVALID Key valid flag 580 * @arg @ref CRYP_FLAG_KEIF Key error flag 581 * @arg CRYP_FLAG_IFEM: Input FIFO is empty (CRYP peripheral only) 582 * @arg CRYP_FLAG_IFNF: Input FIFO is not full (CRYP peripheral only) 583 * @arg CRYP_FLAG_INRIS: Input FIFO service raw interrupt is pending (CRYP peripheral only) 584 * @arg CRYP_FLAG_OFNE: Output FIFO is not empty (CRYP peripheral only) 585 * @arg CRYP_FLAG_OFFU: Output FIFO is full (CRYP peripheral only) 586 * @arg CRYP_FLAG_OUTRIS: Input FIFO service raw interrupt is pending (CRYP peripheral only) 587 * @arg @ref CRYP_FLAG_WRERR Write Error flag (SAES peripheral only) 588 * @arg @ref CRYP_FLAG_RDERR Read Error flag (SAES peripheral only) 589 * @arg @ref CRYP_FLAG_CCF Computation Complete flag (SAES peripheral only) 590 * @arg @ref CRYP_FLAG_RWEIF Read/write Error flag (SAES peripheral only) 591 * @arg @ref CRYP_FLAG_RNGEIF RNG Error flag (SAES peripheral only) 592 * @retval The state of __FLAG__ (TRUE or FALSE). 593 */ 594 #define CRYP_FLAG_MASK 0x0000001FU 595 596 #define __HAL_CRYP_GET_FLAG(__HANDLE__, __FLAG__) ((IS_CRYP_INSTANCE((__HANDLE__)->Instance)) ?\ 597 ((__FLAG__) == CRYP_FLAG_KEYVALID )?((((((CRYP_TypeDef *) \ 598 ((__HANDLE__)->Instance))))->SR \ 599 & (CRYP_FLAG_KEYVALID)) == (CRYP_FLAG_KEYVALID)) : \ 600 ((__FLAG__) == CRYP_FLAG_BUSY )?((((((CRYP_TypeDef *) \ 601 ((__HANDLE__)->Instance))))->SR \ 602 & (CRYP_FLAG_BUSY)) == (CRYP_FLAG_BUSY)) : \ 603 ((__FLAG__) == CRYP_FLAG_KEIF )?((((((CRYP_TypeDef *) \ 604 ((__HANDLE__)->Instance))))->SR \ 605 & (CRYP_FLAG_KERF)) == (CRYP_FLAG_KERF)) : \ 606 ((((uint8_t)((__FLAG__) >> 24)) == 0x01U)?(((((CRYP_TypeDef *) \ 607 ((__HANDLE__)->Instance))->RISR) & ((__FLAG__) & \ 608 CRYP_FLAG_MASK)) == ((__FLAG__) & CRYP_FLAG_MASK)): \ 609 (((((CRYP_TypeDef *)((__HANDLE__)->Instance))->RISR) & ((__FLAG__)\ 610 & CRYP_FLAG_MASK)) == ((__FLAG__) & CRYP_FLAG_MASK))) :\ 611 (\ 612 ((__FLAG__) == CRYP_FLAG_KEYVALID )?((((SAES_TypeDef *)\ 613 (((SAES_TypeDef *)((__HANDLE__)->Instance))))->SR \ 614 & (CRYP_FLAG_KEYVALID)) == (CRYP_FLAG_KEYVALID)) : \ 615 ((__FLAG__) == CRYP_FLAG_BUSY )?((((SAES_TypeDef *) \ 616 ((__HANDLE__)->Instance))->SR \ 617 & (CRYP_FLAG_BUSY)) == (CRYP_FLAG_BUSY)) : \ 618 ((__FLAG__) == CRYP_FLAG_WRERR )?((((SAES_TypeDef *) \ 619 ((__HANDLE__)->Instance))->SR \ 620 & (CRYP_FLAG_WRERR & 0x7FFFFFFFU)) == \ 621 (CRYP_FLAG_WRERR & 0x7FFFFFFFU)) : \ 622 ((__FLAG__) == CRYP_FLAG_RDERR )?((((SAES_TypeDef *) \ 623 ((__HANDLE__)->Instance))->SR \ 624 & (CRYP_FLAG_RDERR & 0x7FFFFFFFU)) == \ 625 (CRYP_FLAG_RDERR & 0x7FFFFFFFU)) : \ 626 ((__FLAG__) == CRYP_FLAG_RNGEIF )?((((SAES_TypeDef *) \ 627 ((__HANDLE__)->Instance))->ISR \ 628 & (CRYP_FLAG_RNGEIF)) == (CRYP_FLAG_RNGEIF)) : \ 629 ((__FLAG__) == CRYP_FLAG_KEIF )?((((SAES_TypeDef *) \ 630 ((__HANDLE__)->Instance))->ISR \ 631 & (CRYP_FLAG_KEIF)) == (CRYP_FLAG_KEIF)) : \ 632 ((__FLAG__) == CRYP_FLAG_RWEIF )?((((SAES_TypeDef *) \ 633 ((__HANDLE__)->Instance))->ISR \ 634 & (CRYP_FLAG_RWEIF)) == (CRYP_FLAG_RWEIF)) : \ 635 ((((SAES_TypeDef *)((__HANDLE__)->Instance))->ISR & \ 636 (CRYP_FLAG_CCF)) == (CRYP_FLAG_CCF)))) 637 638 #if !defined(USE_HAL_SAES_ONLY) || (USE_HAL_SAES_ONLY == 1) 639 /** @brief Clear the SAES peripheral pending status flag. 640 * @param __HANDLE__ specifies the SAES handle. 641 * @param __FLAG__ specifies the flag to clear. 642 * This parameter can be one of the following values: 643 * @arg @ref CRYP_CLEAR_RWEIF Read (RDERR), Write (WRERR) or Read/write (RWEIF) Error Flag Clear 644 * @arg @ref CRYP_CLEAR_CCF Computation Complete Flag (CCF) Clear 645 * @arg @ref CRYP_CLEAR_KEIF Key error interrupt flag clear 646 * @arg @ref CRYP_CLEAR_RNGEIF RNG error interrupt flag clear 647 * @retval None 648 */ 649 #define __HAL_CRYP_CLEAR_FLAG(__HANDLE__, __FLAG__) WRITE_REG(((SAES_TypeDef *)((__HANDLE__)->Instance))->ICR,\ 650 (__FLAG__)) 651 #endif /* USE_HAL_SAES_ONLY */ 652 653 #if !defined(USE_HAL_CRYP_ONLY) || (USE_HAL_CRYP_ONLY == 1) 654 /** @brief Check whether the specified CRYP peripheral interrupt is set or not. 655 * @param __HANDLE__: specifies the CRYP handle. 656 * @param __INTERRUPT__: specifies the interrupt to check. 657 * This parameter can be one of the following values: 658 * @arg CRYP_IT_INI: Input FIFO service masked interrupt status 659 * @arg CRYP_IT_OUTI: Output FIFO service masked interrupt status 660 * @retval The state of __INTERRUPT__ (TRUE or FALSE). 661 */ 662 663 #define __HAL_CRYP_GET_IT(__HANDLE__, __INTERRUPT__) ((((CRYP_TypeDef *)((__HANDLE__)->Instance))->MISR\ 664 & (__INTERRUPT__)) == (__INTERRUPT__)) 665 #endif /* USE_HAL_CRYP_ONLY */ 666 667 /** 668 * @brief Enable the CRYP or SAES peripheral interrupt. 669 * @param __HANDLE__: specifies the CRYP handle. 670 * @param __INTERRUPT__: Interrupt. 671 * This parameter can be one of the following values: 672 * @arg @ref CRYP_IT_INI Input FIFO service interrupt mask (CRYP peripheral only) 673 * @arg @ref CRYP_IT_OUTI Output FIFO service interrupt mask (CRYP peripheral only) 674 * @arg @ref CRYP_IT_RWEIE Error interrupt (used for RDERR and WRERR) (SAES peripheral only) 675 * @arg @ref CRYP_IT_CCFIE Computation Complete interrupt (SAES peripheral only) 676 * @arg @ref CRYP_IT_KEIE Key error interrupt (SAES peripheral only) 677 * @arg @ref CRYP_IT_RNGEIE RNG interrupt (SAES peripheral only) 678 * @retval None 679 */ 680 681 #define __HAL_CRYP_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((IS_CRYP_INSTANCE((__HANDLE__)->Instance)) ?\ 682 ((((CRYP_TypeDef *)((__HANDLE__)->Instance))->IMSCR) |= \ 683 (__INTERRUPT__)) : ((((SAES_TypeDef *) \ 684 ((__HANDLE__)->Instance))->IER) |= (__INTERRUPT__))) 685 686 /** 687 * @brief Disable the CRYP or SAES peripheral interrupt. 688 * @param __HANDLE__: specifies the CRYP handle. 689 * @param __INTERRUPT__: Interrupt. 690 * This parameter can be one of the following values: 691 * @arg @ref CRYP_IT_INI Input FIFO service interrupt mask (CRYP peripheral only) 692 * @arg @ref CRYP_IT_OUTI Output FIFO service interrupt mask (CRYP peripheral only) 693 * @arg @ref CRYP_IT_RWEIE Error interrupt (used for RDERR and WRERR) (SAES peripheral only) 694 * @arg @ref CRYP_IT_CCFIE Computation Complete interrupt (SAES peripheral only) 695 * @arg @ref CRYP_IT_KEIE Key error interrupt (SAES peripheral only) 696 * @arg @ref CRYP_IT_RNGEIE RNG interrupt (SAES peripheral only) 697 * @retval None 698 */ 699 700 #define __HAL_CRYP_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((IS_CRYP_INSTANCE((__HANDLE__)->Instance)) ?\ 701 ((((CRYP_TypeDef *)((__HANDLE__)->Instance))->IMSCR) &= \ 702 ~(__INTERRUPT__)) : ((((SAES_TypeDef *) \ 703 ((__HANDLE__)->Instance))->IER) &= ~(__INTERRUPT__))) 704 705 #if !defined(USE_HAL_SAES_ONLY) || (USE_HAL_SAES_ONLY == 1) 706 /** @brief Check whether the specified SAES peripheral interrupt source is enabled or not. 707 * @param __HANDLE__ specifies the CRYP handle. 708 * @param __INTERRUPT__ interrupt source to check 709 * This parameter can be one of the following values for TinyAES: 710 * @arg @ref CRYP_IT_RWEIE Error interrupt (used for RDERR and WRERR) 711 * @arg @ref CRYP_IT_CCFIE Computation Complete interrupt 712 * @arg @ref CRYP_IT_KEIE Key error interrupt 713 * @arg @ref CRYP_IT_RNGEIE RNG error interrupt 714 * @retval State of interruption (TRUE or FALSE). 715 */ 716 717 #define __HAL_CRYP_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((SAES_TypeDef *)((__HANDLE__)->Instance))->IER\ 718 & (__INTERRUPT__)) == (__INTERRUPT__)) 719 #endif /* USE_HAL_SAES_ONLY */ 720 /** 721 * @} 722 */ 723 724 /* Include CRYP HAL Extended module */ 725 #include "stm32n6xx_hal_cryp_ex.h" 726 727 /* Exported functions --------------------------------------------------------*/ 728 /** @defgroup CRYP_Exported_Functions CRYP Exported Functions 729 * @{ 730 */ 731 732 /** @addtogroup CRYP_Exported_Functions_Group1 733 * @{ 734 */ 735 HAL_StatusTypeDef HAL_CRYP_Init(CRYP_HandleTypeDef *hcryp); 736 HAL_StatusTypeDef HAL_CRYP_DeInit(CRYP_HandleTypeDef *hcryp); 737 void HAL_CRYP_MspInit(CRYP_HandleTypeDef *hcryp); 738 void HAL_CRYP_MspDeInit(CRYP_HandleTypeDef *hcryp); 739 HAL_StatusTypeDef HAL_CRYP_SetConfig(CRYP_HandleTypeDef *hcryp, CRYP_ConfigTypeDef *pConf); 740 HAL_StatusTypeDef HAL_CRYP_GetConfig(CRYP_HandleTypeDef *hcryp, CRYP_ConfigTypeDef *pConf); 741 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1U) 742 HAL_StatusTypeDef HAL_CRYP_RegisterCallback(CRYP_HandleTypeDef *hcryp, HAL_CRYP_CallbackIDTypeDef CallbackID, 743 pCRYP_CallbackTypeDef pCallback); 744 HAL_StatusTypeDef HAL_CRYP_UnRegisterCallback(CRYP_HandleTypeDef *hcryp, HAL_CRYP_CallbackIDTypeDef CallbackID); 745 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */ 746 #if (USE_HAL_CRYP_SUSPEND_RESUME == 1U) 747 void HAL_CRYP_ProcessSuspend(CRYP_HandleTypeDef *hcryp); 748 HAL_StatusTypeDef HAL_CRYP_DMAProcessSuspend(CRYP_HandleTypeDef *hcryp); 749 HAL_StatusTypeDef HAL_CRYP_Suspend(CRYP_HandleTypeDef *hcryp); 750 HAL_StatusTypeDef HAL_CRYP_Resume(CRYP_HandleTypeDef *hcryp); 751 #endif /* defined (USE_HAL_CRYP_SUSPEND_RESUME) */ 752 /** 753 * @} 754 */ 755 756 /** @addtogroup CRYP_Exported_Functions_Group2 757 * @{ 758 */ 759 760 /* encryption/decryption ***********************************/ 761 HAL_StatusTypeDef HAL_CRYP_Encrypt(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output, 762 uint32_t Timeout); 763 HAL_StatusTypeDef HAL_CRYP_Decrypt(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output, 764 uint32_t Timeout); 765 HAL_StatusTypeDef HAL_CRYP_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output); 766 HAL_StatusTypeDef HAL_CRYP_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output); 767 HAL_StatusTypeDef HAL_CRYP_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output); 768 HAL_StatusTypeDef HAL_CRYP_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output); 769 770 /** 771 * @} 772 */ 773 774 775 /** @addtogroup CRYP_Exported_Functions_Group3 776 * @{ 777 */ 778 /* Interrupt Handler functions **********************************************/ 779 void HAL_CRYP_IRQHandler(CRYP_HandleTypeDef *hcryp); 780 HAL_CRYP_STATETypeDef HAL_CRYP_GetState(const CRYP_HandleTypeDef *hcryp); 781 void HAL_CRYP_InCpltCallback(CRYP_HandleTypeDef *hcryp); 782 void HAL_CRYP_OutCpltCallback(CRYP_HandleTypeDef *hcryp); 783 void HAL_CRYP_ErrorCallback(CRYP_HandleTypeDef *hcryp); 784 uint32_t HAL_CRYP_GetError(const CRYP_HandleTypeDef *hcryp); 785 786 /** 787 * @} 788 */ 789 790 /** 791 * @} 792 */ 793 794 /* Private macros --------------------------------------------------------*/ 795 /** @defgroup CRYP_Private_Macros CRYP Private Macros 796 * @{ 797 */ 798 799 /** @defgroup CRYP_IS_CRYP_Definitions CRYP Private macros to check input parameters 800 * @{ 801 */ 802 803 #define IS_CRYP_ALGORITHM(ALGORITHM) (((ALGORITHM) == CRYP_AES_ECB) || \ 804 ((ALGORITHM) == CRYP_AES_CBC) || \ 805 ((ALGORITHM) == CRYP_AES_CTR) || \ 806 ((ALGORITHM) == CRYP_AES_GCM) || \ 807 ((ALGORITHM) == CRYP_AES_CCM)) 808 809 #define IS_CRYP_KEYSIZE(KEYSIZE) (((KEYSIZE) == CRYP_KEYSIZE_128B) || \ 810 ((KEYSIZE) == CRYP_KEYSIZE_192B) || \ 811 ((KEYSIZE) == CRYP_KEYSIZE_256B)) 812 813 #define IS_CRYP_DATATYPE(DATATYPE) (((DATATYPE) == CRYP_DATATYPE_32B) || \ 814 ((DATATYPE) == CRYP_DATATYPE_16B) || \ 815 ((DATATYPE) == CRYP_DATATYPE_8B) || \ 816 ((DATATYPE) == CRYP_DATATYPE_1B)) 817 818 #define IS_CRYP_INIT(CONFIG) (((CONFIG) == CRYP_KEYIVCONFIG_ALWAYS) || \ 819 ((CONFIG) == CRYP_KEYIVCONFIG_ONCE) || \ 820 ((CONFIG) == CRYP_KEYNOCONFIG)) 821 822 #define IS_CRYP_KEYIVCONFIG(CONFIG) (((KEYSIZE) == CRYP_KEYSIZE_128B) || \ 823 ((KEYSIZE) == CRYP_KEYSIZE_192B) || \ 824 ((KEYSIZE) == CRYP_KEYSIZE_256B)) 825 826 #if !defined(USE_HAL_SAES_ONLY) || (USE_HAL_SAES_ONLY == 1) 827 #define IS_CRYP_KEYMODE(MODE) (((MODE) == CRYP_KEYMODE_NORMAL) || \ 828 ((MODE) == CRYP_KEYMODE_SHARED)) 829 830 #define IS_SAES_ALGORITHM(ALGORITHM) (((ALGORITHM) == CRYP_AES_ECB) || \ 831 ((ALGORITHM) == CRYP_AES_CBC) || \ 832 ((ALGORITHM) == CRYP_AES_CTR) || \ 833 ((ALGORITHM) == CRYP_AES_GCM) || \ 834 ((ALGORITHM) == CRYP_AES_CCM)) 835 836 #define IS_SAES_KEYSIZE(KEYSIZE) (((KEYSIZE) == CRYP_KEYSIZE_128B) || \ 837 ((KEYSIZE) == CRYP_KEYSIZE_256B)) 838 839 #define IS_SAES_DATATYPE(DATATYPE) (((DATATYPE) == SAES_DATATYPE_32B) || \ 840 ((DATATYPE) == SAES_DATATYPE_16B) || \ 841 ((DATATYPE) == SAES_DATATYPE_8B) || \ 842 ((DATATYPE) == SAES_DATATYPE_1B)) 843 844 #define IS_SAES_KEYMODE(MODE) (((MODE) == CRYP_KEYMODE_NORMAL) || \ 845 ((MODE) == CRYP_KEYMODE_WRAPPED) || \ 846 ((MODE) == CRYP_KEYMODE_SHARED)) 847 848 #define IS_SAES_KEYPROT(PROTECTION) (((PROTECTION) == CRYP_KEYPROT_ENABLE) || \ 849 ((PROTECTION) == CRYP_KEYPROT_DISABLE)) 850 851 #define IS_SAES_KEYSEL(SELECTION) (((SELECTION) == CRYP_KEYSEL_NORMAL) || \ 852 ((SELECTION) == CRYP_KEYSEL_HW) || \ 853 ((SELECTION) == CRYP_KEYSEL_SW) || \ 854 ((SELECTION) == CRYP_KEYSEL_HSW) || \ 855 ((SELECTION) == CRYP_KEYSEL_AHK) || \ 856 ((SELECTION) == CRYP_KEYSEL_DUK_AHK) || \ 857 ((SELECTION) == CRYP_KEYSEL_TEST_KEY)) 858 859 #define IS_SAES_KEYSHARED(PERIPHERAL) ((PERIPHERAL) == CRYP_KEYSHARED_CRYP) 860 /** 861 * @} 862 */ 863 #endif /* USE_HAL_SAES_ONLY */ 864 865 /** @defgroup SAES_CONV_Definitions SAES Private macros to convert input parameters from CRYP peripheral to 866 SAES peripheral format 867 * @{ 868 */ 869 #if !defined(USE_HAL_SAES_ONLY) || (USE_HAL_SAES_ONLY == 1) 870 #define SAES_CONV_DATATYPE(__DATATYPE__) ((__DATATYPE__) >> (CRYP_CR_DATATYPE_Pos - SAES_CR_DATATYPE_Pos)) 871 872 #define SAES_CONV_KEYSIZE(__KEY__) (((__KEY__)\ 873 & CRYP_CR_KEYSIZE_1) << (SAES_CR_KEYSIZE_Pos - (CRYP_CR_KEYSIZE_Pos + 1U))) 874 875 #define SAES_CONV_ALGO(__ALGO__) (((__ALGO__)\ 876 & (CRYP_CR_ALGOMODE_1 | CRYP_CR_ALGOMODE_0)) << (SAES_CR_CHMOD_Pos - \ 877 CRYP_CR_ALGOMODE_Pos)) 878 #endif /* USE_HAL_SAES_ONLY */ 879 #define CRYP_CONV_ALGODIR(__ALGODIR__) (((__ALGODIR__)\ 880 & SAES_CR_MODE_1) >> ((SAES_CR_MODE_Pos + 1U) - CRYP_CR_ALGODIR_Pos)) 881 882 /** 883 * @} 884 */ 885 886 887 /** 888 * @} 889 */ 890 891 892 /* Private constants ---------------------------------------------------------*/ 893 /** @defgroup CRYP_Private_Constants CRYP Private Constants 894 * @{ 895 */ 896 897 /** 898 * @} 899 */ 900 /* Private defines -----------------------------------------------------------*/ 901 /** @defgroup CRYP_Private_Defines CRYP Private Defines 902 * @{ 903 */ 904 905 /** 906 * @} 907 */ 908 909 /* Private variables ---------------------------------------------------------*/ 910 /** @defgroup CRYP_Private_Variables CRYP Private Variables 911 * @{ 912 */ 913 914 /** 915 * @} 916 */ 917 /* Private functions prototypes ----------------------------------------------*/ 918 /** @defgroup CRYP_Private_Functions_Prototypes CRYP Private Functions Prototypes 919 * @{ 920 */ 921 922 /** 923 * @} 924 */ 925 926 /* Private functions ---------------------------------------------------------*/ 927 /** @defgroup CRYP_Private_Functions CRYP Private Functions 928 * @{ 929 */ 930 931 /** 932 * @} 933 */ 934 935 936 /** 937 * @} 938 */ 939 940 941 #endif /* CRYP */ 942 /** 943 * @} 944 */ 945 946 #ifdef __cplusplus 947 } 948 #endif 949 950 /** 951 * @} 952 */ 953 954 #endif /* STM32N6xx_HAL_CRYP_H */ 955