1 /** 2 ****************************************************************************** 3 * @file stm32u5xx_hal_pka.h 4 * @author MCD Application Team 5 * @brief Header file of PKA HAL module. 6 ****************************************************************************** 7 * @attention 8 * 9 * Copyright (c) 2021 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 STM32U5xx_HAL_PKA_H 22 #define STM32U5xx_HAL_PKA_H 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 /* Includes ------------------------------------------------------------------*/ 29 #include "stm32u5xx_hal_def.h" 30 31 /** @addtogroup STM32U5xx_HAL_Driver 32 * @{ 33 */ 34 35 #if defined(PKA) && defined(HAL_PKA_MODULE_ENABLED) 36 37 /** @addtogroup PKA 38 * @{ 39 */ 40 41 /* Exported types ------------------------------------------------------------*/ 42 /** @defgroup PKA_Exported_Types PKA Exported Types 43 * @{ 44 */ 45 46 /** @defgroup HAL_state_structure_definition HAL state structure definition 47 * @brief HAL State structures definition 48 * @{ 49 */ 50 typedef enum 51 { 52 HAL_PKA_STATE_RESET = 0x00U, /*!< PKA not yet initialized or disabled */ 53 HAL_PKA_STATE_READY = 0x01U, /*!< PKA initialized and ready for use */ 54 HAL_PKA_STATE_BUSY = 0x02U, /*!< PKA internal processing is ongoing */ 55 HAL_PKA_STATE_ERROR = 0x03U, /*!< PKA error state */ 56 } 57 HAL_PKA_StateTypeDef; 58 59 /** 60 * @} 61 */ 62 63 #if (USE_HAL_PKA_REGISTER_CALLBACKS == 1) 64 /** @defgroup HAL_callback_id HAL callback ID enumeration 65 * @{ 66 */ 67 typedef enum 68 { 69 HAL_PKA_OPERATION_COMPLETE_CB_ID = 0x00U, /*!< PKA End of operation callback ID */ 70 HAL_PKA_ERROR_CB_ID = 0x01U, /*!< PKA Error callback ID */ 71 HAL_PKA_MSPINIT_CB_ID = 0x02U, /*!< PKA Msp Init callback ID */ 72 HAL_PKA_MSPDEINIT_CB_ID = 0x03U /*!< PKA Msp DeInit callback ID */ 73 } HAL_PKA_CallbackIDTypeDef; 74 75 /** 76 * @} 77 */ 78 79 #endif /* USE_HAL_PKA_REGISTER_CALLBACKS */ 80 81 /** @defgroup PKA_Error_Code_definition PKA Error Code definition 82 * @brief PKA Error Code definition 83 * @{ 84 */ 85 #define HAL_PKA_ERROR_NONE (0x00000000U) 86 #define HAL_PKA_ERROR_ADDRERR (0x00000001U) 87 #define HAL_PKA_ERROR_RAMERR (0x00000002U) 88 #define HAL_PKA_ERROR_TIMEOUT (0x00000004U) 89 #define HAL_PKA_ERROR_OPERATION (0x00000008U) 90 #if (USE_HAL_PKA_REGISTER_CALLBACKS == 1) 91 #define HAL_PKA_ERROR_INVALID_CALLBACK (0x00000010U) /*!< Invalid Callback error */ 92 #endif /* USE_HAL_PKA_REGISTER_CALLBACKS */ 93 94 /** 95 * @} 96 */ 97 98 /** @defgroup PKA_handle_Structure_definition PKA handle Structure definition 99 * @brief PKA handle Structure definition 100 * @{ 101 */ 102 #if (USE_HAL_PKA_REGISTER_CALLBACKS == 1) 103 typedef struct __PKA_HandleTypeDef 104 #else 105 typedef struct 106 #endif /* USE_HAL_PKA_REGISTER_CALLBACKS */ 107 { 108 PKA_TypeDef *Instance; /*!< Register base address */ 109 __IO HAL_PKA_StateTypeDef State; /*!< PKA state */ 110 __IO uint32_t ErrorCode; /*!< PKA Error code */ 111 #if (USE_HAL_PKA_REGISTER_CALLBACKS == 1) 112 void (* OperationCpltCallback)(struct __PKA_HandleTypeDef *hpka); /*!< PKA End of operation callback */ 113 void (* ErrorCallback)(struct __PKA_HandleTypeDef *hpka); /*!< PKA Error callback */ 114 void (* MspInitCallback)(struct __PKA_HandleTypeDef *hpka); /*!< PKA Msp Init callback */ 115 void (* MspDeInitCallback)(struct __PKA_HandleTypeDef *hpka); /*!< PKA Msp DeInit callback */ 116 #endif /* USE_HAL_PKA_REGISTER_CALLBACKS */ 117 } PKA_HandleTypeDef; 118 /** 119 * @} 120 */ 121 122 #if (USE_HAL_PKA_REGISTER_CALLBACKS == 1) 123 /** @defgroup PKA_Callback_definition PKA Callback pointer definition 124 * @brief PKA Callback pointer definition 125 * @{ 126 */ 127 typedef void (*pPKA_CallbackTypeDef)(PKA_HandleTypeDef *hpka); /*!< Pointer to a PKA callback function */ 128 /** 129 * @} 130 */ 131 #endif /* USE_HAL_PKA_REGISTER_CALLBACKS */ 132 /** @defgroup PKA_Operation PKA operation structure definition 133 * @brief Input and output data definition 134 * @{ 135 */ 136 137 typedef struct 138 { 139 uint32_t scalarMulSize; /*!< Number of element in scalarMul array */ 140 uint32_t modulusSize; /*!< Number of element in modulus, coefA, pointX and pointY arrays */ 141 uint32_t coefSign; /*!< Curve coefficient a sign */ 142 const uint8_t *coefA; /*!< Pointer to curve coefficient |a| (Array of modulusSize elements) */ 143 const uint8_t *coefB; /*!< pointer to curve coefficient b */ 144 const uint8_t *modulus; /*!< Pointer to curve modulus value p (Array of modulusSize elements) */ 145 const uint8_t *pointX; /*!< Pointer to point P coordinate xP (Array of modulusSize elements) */ 146 const uint8_t *pointY; /*!< Pointer to point P coordinate yP (Array of modulusSize elements) */ 147 const uint8_t *scalarMul; /*!< Pointer to scalar multiplier k (Array of scalarMulSize elements) */ 148 const uint8_t *primeOrder; /*!< pointer to order of the curve */ 149 } PKA_ECCMulInTypeDef; 150 151 typedef struct 152 { 153 uint32_t modulusSize; /*!< Number of element in coefA, coefB, modulus, pointX and pointY arrays */ 154 uint32_t coefSign; /*!< Curve coefficient a sign */ 155 const uint8_t *coefA; /*!< Pointer to curve coefficient |a| (Array of modulusSize elements) */ 156 const uint8_t *coefB; /*!< Pointer to curve coefficient b (Array of modulusSize elements) */ 157 const uint8_t *modulus; /*!< Pointer to curve modulus value p (Array of modulusSize elements) */ 158 const uint8_t *pointX; /*!< Pointer to point P coordinate xP (Array of modulusSize elements) */ 159 const uint8_t *pointY; /*!< Pointer to point P coordinate yP (Array of modulusSize elements) */ 160 const uint32_t *pMontgomeryParam; /*!< pointer to montgomery param R2 (modulus N) */ 161 } PKA_PointCheckInTypeDef; 162 163 typedef struct 164 { 165 uint32_t size; /*!< Number of element in popA array */ 166 const uint8_t *pOpDp; /*!< Pointer to operand dP (Array of size/2 elements) */ 167 const uint8_t *pOpDq; /*!< Pointer to operand dQ (Array of size/2 elements) */ 168 const uint8_t *pOpQinv; /*!< Pointer to operand qinv (Array of size/2 elements) */ 169 const uint8_t *pPrimeP; /*!< Pointer to prime p (Array of size/2 elements) */ 170 const uint8_t *pPrimeQ; /*!< Pointer to prime Q (Array of size/2 elements) */ 171 const uint8_t *popA; /*!< Pointer to operand A (Array of size elements) */ 172 } PKA_RSACRTExpInTypeDef; 173 174 typedef struct 175 { 176 uint32_t primeOrderSize; /*!< Number of element in primeOrder array */ 177 uint32_t modulusSize; /*!< Number of element in modulus array */ 178 uint32_t coefSign; /*!< Curve coefficient a sign */ 179 const uint8_t *coef; /*!< Pointer to curve coefficient |a| (Array of modulusSize elements) */ 180 const uint8_t *modulus; /*!< Pointer to curve modulus value p (Array of modulusSize elements) */ 181 const uint8_t *basePointX; /*!< Pointer to curve base point xG (Array of modulusSize elements) */ 182 const uint8_t *basePointY; /*!< Pointer to curve base point yG (Array of modulusSize elements) */ 183 const uint8_t *pPubKeyCurvePtX; /*!< Pointer to public-key curve point xQ (Array of modulusSize elements) */ 184 const uint8_t *pPubKeyCurvePtY; /*!< Pointer to public-key curve point yQ (Array of modulusSize elements) */ 185 const uint8_t *RSign; /*!< Pointer to signature part r (Array of primeOrderSize elements) */ 186 const uint8_t *SSign; /*!< Pointer to signature part s (Array of primeOrderSize elements) */ 187 const uint8_t *hash; /*!< Pointer to hash of the message e (Array of primeOrderSize elements) */ 188 const uint8_t *primeOrder; /*!< Pointer to order of the curve n (Array of primeOrderSize elements) */ 189 } PKA_ECDSAVerifInTypeDef; 190 191 typedef struct 192 { 193 uint32_t primeOrderSize; /*!< Number of element in primeOrder array */ 194 uint32_t modulusSize; /*!< Number of element in modulus array */ 195 uint32_t coefSign; /*!< Curve coefficient a sign */ 196 const uint8_t *coef; /*!< Pointer to curve coefficient |a| (Array of modulusSize elements) */ 197 const uint8_t *coefB; /*!< Pointer to B coefficient (Array of modulusSize elements) */ 198 const uint8_t *modulus; /*!< Pointer to curve modulus value p (Array of modulusSize elements) */ 199 const uint8_t *integer; /*!< Pointer to random integer k (Array of primeOrderSize elements) */ 200 const uint8_t *basePointX; /*!< Pointer to curve base point xG (Array of modulusSize elements) */ 201 const uint8_t *basePointY; /*!< Pointer to curve base point yG (Array of modulusSize elements) */ 202 const uint8_t *hash; /*!< Pointer to hash of the message (Array of primeOrderSize elements) */ 203 const uint8_t *privateKey; /*!< Pointer to private key d (Array of primeOrderSize elements) */ 204 const uint8_t *primeOrder; /*!< Pointer to order of the curve n (Array of primeOrderSize elements) */ 205 } PKA_ECDSASignInTypeDef; 206 207 typedef struct 208 { 209 uint8_t *RSign; /*!< Pointer to signature part r (Array of modulusSize elements) */ 210 uint8_t *SSign; /*!< Pointer to signature part s (Array of modulusSize elements) */ 211 } PKA_ECDSASignOutTypeDef; 212 213 typedef struct 214 { 215 uint8_t *ptX; /*!< Pointer to point P coordinate xP (Array of modulusSize elements) */ 216 uint8_t *ptY; /*!< Pointer to point P coordinate yP (Array of modulusSize elements) */ 217 } PKA_ECDSASignOutExtParamTypeDef, PKA_ECCMulOutTypeDef, PKA_ECCProjective2AffineOutTypeDef, 218 PKA_ECCDoubleBaseLadderOutTypeDef; 219 220 typedef struct 221 { 222 uint8_t *ptX; /*!< pointer to point P coordinate xP */ 223 uint8_t *ptY; /*!< pointer to point P coordinate yP */ 224 uint8_t *ptZ; /*!< pointer to point P coordinate zP */ 225 } PKA_ECCCompleteAdditionOutTypeDef; 226 227 typedef struct 228 { 229 uint32_t expSize; /*!< Number of element in pExp array */ 230 uint32_t OpSize; /*!< Number of element in pOp1 and pMod arrays */ 231 const uint8_t *pExp; /*!< Pointer to Exponent (Array of expSize elements) */ 232 const uint8_t *pOp1; /*!< Pointer to Operand (Array of OpSize elements) */ 233 const uint8_t *pMod; /*!< Pointer to modulus (Array of OpSize elements) */ 234 } PKA_ModExpInTypeDef; 235 236 typedef struct 237 { 238 uint32_t expSize; /*!< Size of the operand in bytes */ 239 uint32_t OpSize; /*!< Size of the operand in bytes */ 240 const uint8_t *pOp1; /*!< Pointer to Operand 1 */ 241 const uint8_t *pExp; /*!< Pointer to Exponent */ 242 const uint8_t *pMod; /*!< Pointer to Operand 1 */ 243 const uint8_t *pPhi; /*!< Pointer to Phi value */ 244 } PKA_ModExpProtectModeInTypeDef; 245 246 typedef struct 247 { 248 uint32_t expSize; /*!< Number of element in pExp and pMontgomeryParam arrays */ 249 uint32_t OpSize; /*!< Number of element in pOp1 and pMod arrays */ 250 const uint8_t *pExp; /*!< Pointer to Exponent (Array of expSize elements) */ 251 const uint8_t *pOp1; /*!< Pointer to Operand (Array of OpSize elements) */ 252 const uint8_t *pMod; /*!< Pointer to modulus (Array of OpSize elements) */ 253 const uint32_t *pMontgomeryParam; /*!< Pointer to Montgomery parameter (Array of expSize/4 elements) */ 254 } PKA_ModExpFastModeInTypeDef; 255 256 typedef struct 257 { 258 uint32_t size; /*!< Number of element in pOp1 array */ 259 const uint8_t *pOp1; /*!< Pointer to Operand (Array of size elements) */ 260 } PKA_MontgomeryParamInTypeDef; 261 262 typedef struct 263 { 264 uint32_t size; /*!< Number of element in pOp1 and pOp2 arrays */ 265 const uint32_t *pOp1; /*!< Pointer to Operand 1 (Array of size elements) */ 266 const uint32_t *pOp2; /*!< Pointer to Operand 2 (Array of size elements) */ 267 } PKA_AddInTypeDef, PKA_SubInTypeDef, PKA_MulInTypeDef, PKA_CmpInTypeDef; 268 269 typedef struct 270 { 271 uint32_t size; /*!< Number of element in pOp1 array */ 272 const uint32_t *pOp1; /*!< Pointer to Operand 1 (Array of size elements) */ 273 const uint8_t *pMod; /*!< Pointer to modulus value n (Array of size*4 elements) */ 274 } PKA_ModInvInTypeDef; 275 276 typedef struct 277 { 278 uint32_t OpSize; /*!< Number of element in pOp1 array */ 279 uint32_t modSize; /*!< Number of element in pMod array */ 280 const uint32_t *pOp1; /*!< Pointer to Operand 1 (Array of OpSize elements) */ 281 const uint8_t *pMod; /*!< Pointer to modulus value n (Array of modSize elements) */ 282 } PKA_ModRedInTypeDef; 283 284 typedef struct 285 { 286 uint32_t size; /*!< Number of element in pOp1 and pOp2 arrays */ 287 const uint32_t *pOp1; /*!< Pointer to Operand 1 (Array of size elements) */ 288 const uint32_t *pOp2; /*!< Pointer to Operand 2 (Array of size elements) */ 289 const uint8_t *pOp3; /*!< Pointer to Operand 3 (Array of size*4 elements) */ 290 } PKA_ModAddInTypeDef, PKA_ModSubInTypeDef, PKA_MontgomeryMulInTypeDef; 291 292 typedef struct 293 { 294 uint32_t primeOrderSize; /*!< curve prime order n length */ 295 uint32_t modulusSize; /*!< curve modulus p length */ 296 uint32_t coefSign; /*!< curve coefficient a sign */ 297 const uint8_t *coefA; /*!< pointer to curve coefficient |a| */ 298 const uint8_t *modulus; /*!< pointer to curve modulus value p */ 299 const uint8_t *integerK; /*!< pointer to cryptographically secure random integer k */ 300 const uint8_t *integerM; /*!< pointer to cryptographically secure random integer m */ 301 const uint8_t *basePointX1; /*!< pointer to curve base first point coordinate x */ 302 const uint8_t *basePointY1; /*!< pointer to curve base first point coordinate y */ 303 const uint8_t *basePointZ1; /*!< pointer to curve base first point coordinate z */ 304 const uint8_t *basePointX2; /*!< pointer to curve base second point coordinate x */ 305 const uint8_t *basePointY2; /*!< pointer to curve base second point coordinate y */ 306 const uint8_t *basePointZ2; /*!< pointer to curve base second point coordinate z */ 307 } PKA_ECCDoubleBaseLadderInTypeDef; 308 309 typedef struct 310 { 311 uint32_t modulusSize; /*!< curve modulus p length */ 312 const uint8_t *modulus; /*!< pointer to curve modulus value p */ 313 const uint8_t *basePointX; /*!< pointer to curve base point coordinate x */ 314 const uint8_t *basePointY; /*!< pointer to curve base point coordinate y */ 315 const uint8_t *basePointZ; /*!< pointer to curve base point coordinate z */ 316 const uint32_t *pMontgomeryParam; /*!< pointer to montgomery parameter R2 modulus n*/ 317 } PKA_ECCProjective2AffineInTypeDef; 318 319 typedef struct 320 { 321 uint32_t modulusSize; /*!< curve modulus p length */ 322 uint32_t coefSign; /*!< curve coefficient a sign */ 323 const uint8_t *modulus; /*!< pointer to curve modulus value p */ 324 const uint8_t *coefA; /*!< pointer to curve coefficient |a| */ 325 const uint8_t *basePointX1; /*!< pointer to curve base first point coordinate x */ 326 const uint8_t *basePointY1; /*!< pointer to curve base first point coordinate y */ 327 const uint8_t *basePointZ1; /*!< pointer to curve base first point coordinate z */ 328 const uint8_t *basePointX2; /*!< pointer to curve base second point coordinate x */ 329 const uint8_t *basePointY2; /*!< pointer to curve base second point coordinate y */ 330 const uint8_t *basePointZ2; /*!< pointer to curve base second point coordinate z */ 331 } PKA_ECCCompleteAdditionInTypeDef; 332 /** 333 * @} 334 */ 335 336 /** 337 * @} 338 */ 339 340 /* Exported constants --------------------------------------------------------*/ 341 /** @defgroup PKA_Exported_Constants PKA Exported Constants 342 * @{ 343 */ 344 345 /** @defgroup PKA_Mode PKA mode 346 * @{ 347 */ 348 #define PKA_MODE_MONTGOMERY_PARAM (0x00000001U) 349 #define PKA_MODE_MODULAR_EXP (0x00000000U) 350 #define PKA_MODE_MODULAR_EXP_FAST_MODE (0x00000002U) 351 #define PKA_MODE_ECC_MUL (0x00000020U) 352 #define PKA_MODE_ECDSA_SIGNATURE (0x00000024U) 353 #define PKA_MODE_ECDSA_VERIFICATION (0x00000026U) 354 #define PKA_MODE_POINT_CHECK (0x00000028U) 355 #define PKA_MODE_RSA_CRT_EXP (0x00000007U) 356 #define PKA_MODE_MODULAR_INV (0x00000008U) 357 #define PKA_MODE_ARITHMETIC_ADD (0x00000009U) 358 #define PKA_MODE_ARITHMETIC_SUB (0x0000000AU) 359 #define PKA_MODE_ARITHMETIC_MUL (0x0000000BU) 360 #define PKA_MODE_COMPARISON (0x0000000CU) 361 #define PKA_MODE_MODULAR_RED (0x0000000DU) 362 #define PKA_MODE_MODULAR_ADD (0x0000000EU) 363 #define PKA_MODE_MODULAR_SUB (0x0000000FU) 364 #define PKA_MODE_MONTGOMERY_MUL (0x00000010U) 365 #define PKA_MODE_ECC_PROJECTIVE_AFF (0x0000002FU) 366 #define PKA_MODE_DOUBLE_BASE_LADDER (0x00000027U) 367 #define PKA_MODE_ECC_COMPLETE_ADD (0x00000023U) 368 #define PKA_MODE_MODULAR_EXP_PROTECT (0x00000003U) 369 /** 370 * @} 371 */ 372 373 /** @defgroup PKA_Interrupt_configuration_definition PKA Interrupt configuration definition 374 * @brief PKA Interrupt definition 375 * @{ 376 */ 377 #define PKA_IT_PROCEND PKA_CR_PROCENDIE 378 #define PKA_IT_ADDRERR PKA_CR_ADDRERRIE 379 #define PKA_IT_RAMERR PKA_CR_RAMERRIE 380 #define PKA_IT_OPERR PKA_CR_OPERRIE 381 382 /** 383 * @} 384 */ 385 386 /** @defgroup PKA_Flag_definition PKA Flag definition 387 * @{ 388 */ 389 #define PKA_FLAG_PROCEND PKA_SR_PROCENDF 390 #define PKA_FLAG_ADDRERR PKA_SR_ADDRERRF 391 #define PKA_FLAG_RAMERR PKA_SR_RAMERRF 392 #define PKA_FLAG_OPERR PKA_SR_OPERRF 393 394 /** 395 * @} 396 */ 397 398 /** @defgroup PKA_Operation_Status PKA Operation Status 399 * @{ 400 */ 401 #define PKA_NO_ERROR 0xD60DUL 402 #define PKA_FAILED_COMPUTATION 0xCBC9UL 403 #define PKA_RPART_SIGNATURE_NULL 0xA3B7UL 404 #define PKA_SPART_SIGNATURE_NULL 0xF946UL 405 406 /** 407 * @} 408 */ 409 410 /** 411 * @} 412 */ 413 414 /* Exported macros -----------------------------------------------------------*/ 415 416 /** @defgroup PKA_Exported_Macros PKA Exported Macros 417 * @{ 418 */ 419 420 /** @brief Reset PKA handle state. 421 * @param __HANDLE__ specifies the PKA Handle 422 * @retval None 423 */ 424 #if (USE_HAL_PKA_REGISTER_CALLBACKS == 1) 425 #define __HAL_PKA_RESET_HANDLE_STATE(__HANDLE__) do{ \ 426 (__HANDLE__)->State = HAL_PKA_STATE_RESET; \ 427 (__HANDLE__)->MspInitCallback = NULL; \ 428 (__HANDLE__)->MspDeInitCallback = NULL; \ 429 } while(0) 430 #else 431 #define __HAL_PKA_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_PKA_STATE_RESET) 432 #endif /* USE_HAL_PKA_REGISTER_CALLBACKS */ 433 434 /** @brief Enable the specified PKA interrupt. 435 * @param __HANDLE__ specifies the PKA Handle 436 * @param __INTERRUPT__ specifies the interrupt source to enable. 437 * This parameter can be one of the following values: 438 * @arg @ref PKA_IT_PROCEND End Of Operation interrupt enable 439 * @arg @ref PKA_IT_ADDRERR Address error interrupt enable 440 * @arg @ref PKA_IT_RAMERR RAM error interrupt enable 441 * @arg @ref PKA_IT_OPERR Operation error interrupt enable 442 * @retval None 443 */ 444 #define __HAL_PKA_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR |= (__INTERRUPT__)) 445 446 /** @brief Disable the specified PKA interrupt. 447 * @param __HANDLE__ specifies the PKA Handle 448 * @param __INTERRUPT__ specifies the interrupt source to disable. 449 * This parameter can be one of the following values: 450 * @arg @ref PKA_IT_PROCEND End Of Operation interrupt enable 451 * @arg @ref PKA_IT_ADDRERR Address error interrupt enable 452 * @arg @ref PKA_IT_RAMERR RAM error interrupt enable 453 * @arg @ref PKA_IT_OPERR Operation error interrupt enable 454 * @retval None 455 */ 456 #define __HAL_PKA_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR &= (~(__INTERRUPT__))) 457 458 /** @brief Check whether the specified PKA interrupt source is enabled or not. 459 * @param __HANDLE__ specifies the PKA Handle 460 * @param __INTERRUPT__ specifies the PKA interrupt source to check. 461 * This parameter can be one of the following values: 462 * @arg @ref PKA_IT_PROCEND End Of Operation interrupt enable 463 * @arg @ref PKA_IT_ADDRERR Address error interrupt enable 464 * @arg @ref PKA_IT_RAMERR RAM error interrupt enable 465 * @arg @ref PKA_IT_OPERR Operation error interrupt enable 466 * @retval The new state of __INTERRUPT__ (SET or RESET) 467 */ 468 #define __HAL_PKA_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->CR\ 469 & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET) 470 471 /** @brief Check whether the specified PKA flag is set or not. 472 * @param __HANDLE__ specifies the PKA Handle 473 * @param __FLAG__ specifies the flag to check. 474 * This parameter can be one of the following values: 475 * @arg @ref PKA_FLAG_PROCEND End Of Operation 476 * @arg @ref PKA_FLAG_ADDRERR Address error 477 * @arg @ref PKA_FLAG_RAMERR RAM error 478 * @arg @ref PKA_FLAG_OPERR Operation error 479 * @retval The new state of __FLAG__ (SET or RESET) 480 */ 481 #define __HAL_PKA_GET_FLAG(__HANDLE__, __FLAG__) (((((__HANDLE__)->Instance->SR)\ 482 & (__FLAG__)) == (__FLAG__)) ? SET : RESET) 483 484 /** @brief Clear the PKA pending flags which are cleared by writing 1 in a specific bit. 485 * @param __HANDLE__ specifies the PKA Handle 486 * @param __FLAG__ specifies the flag to clear. 487 * This parameter can be any combination of the following values: 488 * @arg @ref PKA_FLAG_PROCEND End Of Operation 489 * @arg @ref PKA_FLAG_ADDRERR Address error 490 * @arg @ref PKA_FLAG_RAMERR RAM error 491 * @arg @ref PKA_FLAG_OPERR Operation error 492 * @retval None 493 */ 494 #define __HAL_PKA_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->CLRFR = (__FLAG__)) 495 496 /** @brief Enable the specified PKA peripheral. 497 * @param __HANDLE__ specifies the PKA Handle 498 * @retval None 499 */ 500 #define __HAL_PKA_ENABLE(__HANDLE__) (SET_BIT((__HANDLE__)->Instance->CR, PKA_CR_EN)) 501 502 /** @brief Disable the specified PKA peripheral. 503 * @param __HANDLE__ specifies the PKA Handle 504 * @retval None 505 */ 506 #define __HAL_PKA_DISABLE(__HANDLE__) (CLEAR_BIT((__HANDLE__)->Instance->CR, PKA_CR_EN)) 507 508 /** @brief Start a PKA operation. 509 * @param __HANDLE__ specifies the PKA Handle 510 * @retval None 511 */ 512 #define __HAL_PKA_START(__HANDLE__) (SET_BIT((__HANDLE__)->Instance->CR, PKA_CR_START)) 513 /** 514 * @} 515 */ 516 517 /* Private macros --------------------------------------------------------*/ 518 /* Exported functions --------------------------------------------------------*/ 519 /** @addtogroup PKA_Exported_Functions 520 * @{ 521 */ 522 523 /** @addtogroup PKA_Exported_Functions_Group1 524 * @{ 525 */ 526 /* Initialization and de-initialization functions *****************************/ 527 HAL_StatusTypeDef HAL_PKA_Init(PKA_HandleTypeDef *hpka); 528 HAL_StatusTypeDef HAL_PKA_DeInit(PKA_HandleTypeDef *hpka); 529 void HAL_PKA_MspInit(PKA_HandleTypeDef *hpka); 530 void HAL_PKA_MspDeInit(PKA_HandleTypeDef *hpka); 531 532 #if (USE_HAL_PKA_REGISTER_CALLBACKS == 1) 533 /* Callbacks Register/UnRegister functions ***********************************/ 534 HAL_StatusTypeDef HAL_PKA_RegisterCallback(PKA_HandleTypeDef *hpka, HAL_PKA_CallbackIDTypeDef CallbackID, 535 pPKA_CallbackTypeDef pCallback); 536 HAL_StatusTypeDef HAL_PKA_UnRegisterCallback(PKA_HandleTypeDef *hpka, HAL_PKA_CallbackIDTypeDef CallbackID); 537 #endif /* USE_HAL_PKA_REGISTER_CALLBACKS */ 538 539 /** 540 * @} 541 */ 542 543 /** @addtogroup PKA_Exported_Functions_Group2 544 * @{ 545 */ 546 /* IO operation functions *****************************************************/ 547 /* High Level Functions *******************************************************/ 548 HAL_StatusTypeDef HAL_PKA_ModExp(PKA_HandleTypeDef *hpka, PKA_ModExpInTypeDef *in, uint32_t Timeout); 549 HAL_StatusTypeDef HAL_PKA_ModExp_IT(PKA_HandleTypeDef *hpka, PKA_ModExpInTypeDef *in); 550 HAL_StatusTypeDef HAL_PKA_ModExpFastMode(PKA_HandleTypeDef *hpka, PKA_ModExpFastModeInTypeDef *in, uint32_t Timeout); 551 HAL_StatusTypeDef HAL_PKA_ModExpFastMode_IT(PKA_HandleTypeDef *hpka, PKA_ModExpFastModeInTypeDef *in); 552 HAL_StatusTypeDef HAL_PKA_ModExpProtectMode(PKA_HandleTypeDef *hpka, PKA_ModExpProtectModeInTypeDef *in, 553 uint32_t Timeout); 554 HAL_StatusTypeDef HAL_PKA_ModExpProtectMode_IT(PKA_HandleTypeDef *hpka, PKA_ModExpProtectModeInTypeDef *in); 555 void HAL_PKA_ModExp_GetResult(PKA_HandleTypeDef *hpka, uint8_t *pRes); 556 557 HAL_StatusTypeDef HAL_PKA_ECDSASign(PKA_HandleTypeDef *hpka, PKA_ECDSASignInTypeDef *in, uint32_t Timeout); 558 HAL_StatusTypeDef HAL_PKA_ECDSASign_IT(PKA_HandleTypeDef *hpka, PKA_ECDSASignInTypeDef *in); 559 void HAL_PKA_ECDSASign_GetResult(PKA_HandleTypeDef *hpka, PKA_ECDSASignOutTypeDef *out, 560 PKA_ECDSASignOutExtParamTypeDef *outExt); 561 562 HAL_StatusTypeDef HAL_PKA_ECDSAVerif(PKA_HandleTypeDef *hpka, PKA_ECDSAVerifInTypeDef *in, uint32_t Timeout); 563 HAL_StatusTypeDef HAL_PKA_ECDSAVerif_IT(PKA_HandleTypeDef *hpka, PKA_ECDSAVerifInTypeDef *in); 564 uint32_t HAL_PKA_ECDSAVerif_IsValidSignature(PKA_HandleTypeDef const *const hpka); 565 566 HAL_StatusTypeDef HAL_PKA_RSACRTExp(PKA_HandleTypeDef *hpka, PKA_RSACRTExpInTypeDef *in, uint32_t Timeout); 567 HAL_StatusTypeDef HAL_PKA_RSACRTExp_IT(PKA_HandleTypeDef *hpka, PKA_RSACRTExpInTypeDef *in); 568 void HAL_PKA_RSACRTExp_GetResult(PKA_HandleTypeDef *hpka, uint8_t *pRes); 569 570 HAL_StatusTypeDef HAL_PKA_PointCheck(PKA_HandleTypeDef *hpka, PKA_PointCheckInTypeDef *in, uint32_t Timeout); 571 HAL_StatusTypeDef HAL_PKA_PointCheck_IT(PKA_HandleTypeDef *hpka, PKA_PointCheckInTypeDef *in); 572 uint32_t HAL_PKA_PointCheck_IsOnCurve(PKA_HandleTypeDef const *const hpka); 573 574 HAL_StatusTypeDef HAL_PKA_ECCMul(PKA_HandleTypeDef *hpka, PKA_ECCMulInTypeDef *in, uint32_t Timeout); 575 HAL_StatusTypeDef HAL_PKA_ECCMul_IT(PKA_HandleTypeDef *hpka, PKA_ECCMulInTypeDef *in); 576 void HAL_PKA_ECCMul_GetResult(PKA_HandleTypeDef *hpka, PKA_ECCMulOutTypeDef *out); 577 578 HAL_StatusTypeDef HAL_PKA_Add(PKA_HandleTypeDef *hpka, PKA_AddInTypeDef *in, uint32_t Timeout); 579 HAL_StatusTypeDef HAL_PKA_Add_IT(PKA_HandleTypeDef *hpka, PKA_AddInTypeDef *in); 580 HAL_StatusTypeDef HAL_PKA_Sub(PKA_HandleTypeDef *hpka, PKA_SubInTypeDef *in, uint32_t Timeout); 581 HAL_StatusTypeDef HAL_PKA_Sub_IT(PKA_HandleTypeDef *hpka, PKA_SubInTypeDef *in); 582 HAL_StatusTypeDef HAL_PKA_Cmp(PKA_HandleTypeDef *hpka, PKA_CmpInTypeDef *in, uint32_t Timeout); 583 HAL_StatusTypeDef HAL_PKA_Cmp_IT(PKA_HandleTypeDef *hpka, PKA_CmpInTypeDef *in); 584 HAL_StatusTypeDef HAL_PKA_Mul(PKA_HandleTypeDef *hpka, PKA_MulInTypeDef *in, uint32_t Timeout); 585 HAL_StatusTypeDef HAL_PKA_Mul_IT(PKA_HandleTypeDef *hpka, PKA_MulInTypeDef *in); 586 HAL_StatusTypeDef HAL_PKA_ModAdd(PKA_HandleTypeDef *hpka, PKA_ModAddInTypeDef *in, uint32_t Timeout); 587 HAL_StatusTypeDef HAL_PKA_ModAdd_IT(PKA_HandleTypeDef *hpka, PKA_ModAddInTypeDef *in); 588 HAL_StatusTypeDef HAL_PKA_ModSub(PKA_HandleTypeDef *hpka, PKA_ModSubInTypeDef *in, uint32_t Timeout); 589 HAL_StatusTypeDef HAL_PKA_ModSub_IT(PKA_HandleTypeDef *hpka, PKA_ModSubInTypeDef *in); 590 HAL_StatusTypeDef HAL_PKA_ModInv(PKA_HandleTypeDef *hpka, PKA_ModInvInTypeDef *in, uint32_t Timeout); 591 HAL_StatusTypeDef HAL_PKA_ModInv_IT(PKA_HandleTypeDef *hpka, PKA_ModInvInTypeDef *in); 592 HAL_StatusTypeDef HAL_PKA_ModRed(PKA_HandleTypeDef *hpka, PKA_ModRedInTypeDef *in, uint32_t Timeout); 593 HAL_StatusTypeDef HAL_PKA_ModRed_IT(PKA_HandleTypeDef *hpka, PKA_ModRedInTypeDef *in); 594 HAL_StatusTypeDef HAL_PKA_MontgomeryMul(PKA_HandleTypeDef *hpka, PKA_MontgomeryMulInTypeDef *in, uint32_t Timeout); 595 HAL_StatusTypeDef HAL_PKA_MontgomeryMul_IT(PKA_HandleTypeDef *hpka, PKA_MontgomeryMulInTypeDef *in); 596 void HAL_PKA_Arithmetic_GetResult(PKA_HandleTypeDef *hpka, uint32_t *pRes); 597 598 HAL_StatusTypeDef HAL_PKA_MontgomeryParam(PKA_HandleTypeDef *hpka, PKA_MontgomeryParamInTypeDef *in, uint32_t Timeout); 599 HAL_StatusTypeDef HAL_PKA_MontgomeryParam_IT(PKA_HandleTypeDef *hpka, PKA_MontgomeryParamInTypeDef *in); 600 void HAL_PKA_MontgomeryParam_GetResult(PKA_HandleTypeDef *hpka, uint32_t *pRes); 601 602 HAL_StatusTypeDef HAL_PKA_ECCDoubleBaseLadder(PKA_HandleTypeDef *hpka, PKA_ECCDoubleBaseLadderInTypeDef *in, 603 uint32_t Timeout); 604 HAL_StatusTypeDef HAL_PKA_ECCDoubleBaseLadder_IT(PKA_HandleTypeDef *hpka, PKA_ECCDoubleBaseLadderInTypeDef *in); 605 void HAL_PKA_ECCDoubleBaseLadder_GetResult(PKA_HandleTypeDef *hpka, PKA_ECCDoubleBaseLadderOutTypeDef *out); 606 607 HAL_StatusTypeDef HAL_PKA_ECCProjective2Affine(PKA_HandleTypeDef *hpka, PKA_ECCProjective2AffineInTypeDef *in, 608 uint32_t Timeout); 609 HAL_StatusTypeDef HAL_PKA_ECCProjective2Affine_IT(PKA_HandleTypeDef *hpka, PKA_ECCProjective2AffineInTypeDef *in); 610 void HAL_PKA_ECCProjective2Affine_GetResult(PKA_HandleTypeDef *hpka, PKA_ECCProjective2AffineOutTypeDef *out); 611 612 HAL_StatusTypeDef HAL_PKA_ECCCompleteAddition(PKA_HandleTypeDef *hpka, PKA_ECCCompleteAdditionInTypeDef *in, 613 uint32_t Timeout); 614 HAL_StatusTypeDef HAL_PKA_ECCCompleteAddition_IT(PKA_HandleTypeDef *hpka, PKA_ECCCompleteAdditionInTypeDef *in); 615 void HAL_PKA_ECCCompleteAddition_GetResult(PKA_HandleTypeDef *hpka, PKA_ECCCompleteAdditionOutTypeDef *out); 616 617 HAL_StatusTypeDef HAL_PKA_Abort(PKA_HandleTypeDef *hpka); 618 void HAL_PKA_RAMReset(PKA_HandleTypeDef *hpka); 619 void HAL_PKA_OperationCpltCallback(PKA_HandleTypeDef *hpka); 620 void HAL_PKA_ErrorCallback(PKA_HandleTypeDef *hpka); 621 void HAL_PKA_IRQHandler(PKA_HandleTypeDef *hpka); 622 /** 623 * @} 624 */ 625 626 /** @addtogroup PKA_Exported_Functions_Group3 627 * @{ 628 */ 629 /* Peripheral State and Error functions ***************************************/ 630 HAL_PKA_StateTypeDef HAL_PKA_GetState(PKA_HandleTypeDef *hpka); 631 uint32_t HAL_PKA_GetError(PKA_HandleTypeDef *hpka); 632 /** 633 * @} 634 */ 635 636 /** 637 * @} 638 */ 639 640 /** 641 * @} 642 */ 643 644 #endif /* defined(PKA) && defined(HAL_PKA_MODULE_ENABLED) */ 645 646 /** 647 * @} 648 */ 649 650 #ifdef __cplusplus 651 } 652 #endif 653 654 #endif /* STM32U5xx_HAL_PKA_H */ 655 656