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