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