1 /** 2 **************************************************************************************** 3 * 4 * @file gr55xx_hal_pkc.h 5 * @author BLE Driver Team 6 * @brief Header file containing functions prototypes of PKC HAL library. 7 * 8 **************************************************************************************** 9 * @attention 10 #####Copyright (c) 2019 GOODIX 11 All rights reserved. 12 13 Redistribution and use in source and binary forms, with or without 14 modification, are permitted provided that the following conditions are met: 15 * Redistributions of source code must retain the above copyright 16 notice, this list of conditions and the following disclaimer. 17 * Redistributions in binary form must reproduce the above copyright 18 notice, this list of conditions and the following disclaimer in the 19 documentation and/or other materials provided with the distribution. 20 * Neither the name of GOODIX nor the names of its contributors may be used 21 to endorse or promote products derived from this software without 22 specific prior written permission. 23 24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE 28 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 POSSIBILITY OF SUCH DAMAGE. 35 **************************************************************************************** 36 */ 37 38 /** @addtogroup PERIPHERAL Peripheral Driver 39 * @{ 40 */ 41 42 /** @addtogroup HAL_DRIVER HAL Driver 43 * @{ 44 */ 45 46 /** @defgroup HAL_PKC PKC 47 * @brief PKC HAL module driver. 48 * @{ 49 */ 50 51 /* Define to prevent recursive inclusion -------------------------------------*/ 52 #ifndef __GR55xx_HAL_PKC_H__ 53 #define __GR55xx_HAL_PKC_H__ 54 55 /* Includes ------------------------------------------------------------------*/ 56 #include "gr55xx_ll_pkc.h" 57 #include "gr55xx_hal_def.h" 58 59 #ifdef __cplusplus 60 extern "C" { 61 #endif 62 63 /* Exported types ------------------------------------------------------------*/ 64 /** @addtogroup HAL_PKC_ENUMERATIONS Enumerations 65 * @{ 66 */ 67 68 /** @defgroup HAL_PKC_state HAL PKC state 69 * @{ 70 */ 71 72 /** 73 * @brief HAL PKC State Enumerations definition 74 */ 75 typedef enum { 76 HAL_PKC_STATE_RESET = 0x00, /**< Peripheral not initialized */ 77 HAL_PKC_STATE_READY = 0x01, /**< Peripheral initialized and ready for use */ 78 HAL_PKC_STATE_BUSY = 0x02, /**< Peripheral in indirect mode and busy */ 79 HAL_PKC_STATE_ERROR = 0x04, /**< Peripheral in error */ 80 HAL_PKC_STATE_TIMEOUT = 0x08, /**< Peripheral in timeout */ 81 } hal_pkc_state_t; 82 83 /** @} */ 84 85 /** @} */ 86 87 /** @addtogroup HAL_PKC_STRUCTURES Structures 88 * @{ 89 */ 90 91 /** @defgroup PKC_Configuration PKC Configuration 92 * @{ 93 */ 94 95 /** 96 * @brief PKC ECC Point Structure definition 97 */ 98 typedef struct _ll_ecc_point ecc_point_t; 99 100 /** 101 * @brief PKC ECC P-256 Elliptic Curve Init Structure definition 102 */ 103 typedef struct _ll_ecc_curve_init ecc_curve_init_t; 104 105 /** 106 * @brief PKC Init Structure definition 107 */ 108 typedef struct { 109 ecc_curve_init_t *p_ecc_curve; /**< Specifies the pointer to elliptic curve description */ 110 111 uint32_t data_bits; /**< Specifies the Data size: 256 ~ 2048 bits */ 112 113 uint32_t secure_mode; /**< Specifies the Secure Mode. It indicates that DPA-resistance software 114 algorithm and hardware measures are applied at a cost of about 115 35%- 50% performance loss. 116 This parameter can be a value of @ref PKC_Secure_Mode. */ 117 118 uint32_t (*random_func)(void); /**< Specifies the function to generate random number. */ 119 } pkc_init_t; 120 121 /** @} */ 122 123 /** @defgroup PKC_handle PKC handle 124 * @{ 125 */ 126 127 /** 128 * @brief PKC handle Structure definition 129 */ 130 typedef struct _pkc_handle { 131 pkc_regs_t *p_instance; /**< PKC registers base address */ 132 133 pkc_init_t init; /**< PKC operation parameters */ 134 135 void *p_result; /**< Pointer to PKC result buffer */ 136 137 uint32_t shift_count; /**< Count to left shift */ 138 139 uint32_t *p_P; /**< Prime number */ 140 141 __IO hal_lock_t lock; /**< Locking object */ 142 143 __IO hal_pkc_state_t state; /**< PKC operation state */ 144 145 __IO uint32_t error_code; /**< PKC Error code */ 146 147 uint32_t timeout; /**< Timeout for the PKC operation */ 148 149 uint32_t retention[1]; /**< pkc important register information. */ 150 } pkc_handle_t; 151 /** @} */ 152 153 /** @defgroup PKC_Expression_Input PKC expression input 154 * @{ 155 */ 156 157 /** 158 * @brief PKC ECC Point Multiplication expression input 159 * @note Result = K * Point 160 */ 161 typedef struct _pkc_ecc_point_multi { 162 uint32_t *p_K; /**< Pointer to operand K */ 163 ecc_point_t *p_ecc_point; /**< Pointer to ECC Point */ 164 } pkc_ecc_point_multi_t; 165 166 /** 167 * @brief PKC RSA Modular Exponentiation expression input 168 * @note Result = A^B mod P 169 */ 170 typedef struct _pkc_rsa_modular_exponent { 171 uint32_t *p_A; /**< Pointer to operand A */ 172 uint32_t *p_B; /**< Pointer to operand B */ 173 uint32_t *p_P; /**< Pointer to prime number P */ 174 uint32_t *p_P_R2; /**< P_R2 = R^2 mod P, where R = 2^DataBits */ 175 uint32_t ConstP; /**< Montgomery multiplication constant of P */ 176 } pkc_rsa_modular_exponent_t; 177 178 /** 179 * @brief PKC Modular Addition expression input 180 * @note Result = (A + B) mod P 181 */ 182 typedef struct _pkc_modular_add { 183 uint32_t *p_A; /**< Pointer to operand A */ 184 uint32_t *p_B; /**< Pointer to operand B */ 185 uint32_t *p_P; /**< Pointer to prime number P */ 186 } pkc_modular_add_t; 187 188 /** 189 * @brief PKC Modular Subtraction expression input 190 * @note Result = (A - B) mod P 191 */ 192 typedef struct _pkc_modular_sub { 193 uint32_t *p_A; /**< Pointer to operand A */ 194 uint32_t *p_B; /**< Pointer to operand B */ 195 uint32_t *p_P; /**< Pointer to prime number P */ 196 } pkc_modular_sub_t; 197 198 /** 199 * @brief PKC Modular Left Shift expression input 200 * @note Result = (A << ShiftBits) mod P 201 */ 202 typedef struct _pkc_modular_shift { 203 uint32_t *p_A; /**< Pointer to operand A */ 204 uint32_t shift_bits; /**< Pointer to operand A */ 205 uint32_t *p_P; /**< Pointer to prime number P */ 206 } pkc_modular_shift_t; 207 208 /** 209 * @brief PKC Modular Comparison expression input 210 * @note Result = A mod P 211 */ 212 typedef struct _pkc_modular_compare { 213 uint32_t *p_A; /**< Pointer to operand A */ 214 uint32_t *p_P; /**< Pointer to prime number P */ 215 } pkc_modular_compare_t; 216 217 /** 218 * @brief PKC Montgomery Modular Multiplication expression input 219 * @note Result = A * B * R^(-1) mod P, where R = 2^DataBits 220 */ 221 typedef struct _pkc_montgomery_multi { 222 uint32_t *p_A; /**< Pointer to operand A */ 223 uint32_t *p_B; /**< Pointer to operand B */ 224 uint32_t *p_P; /**< Pointer to prime number P */ 225 uint32_t ConstP; /**< Montgomery multiplication constant for P, 226 where constp = (-P[0])^(-1) mod 2^32 */ 227 } pkc_montgomery_multi_t; 228 229 /** 230 * @brief PKC Montgomery Inversion expression input 231 * @note Result = A^(-1) * 2^(K) mod P 232 */ 233 typedef struct _pkc_montgomery_inversion { 234 uint32_t *p_A; /**< Pointer to operand A */ 235 uint32_t *p_P; /**< Pointer to prime number P */ 236 uint32_t ConstP; /**< Montgomery multiplication constant for P, 237 where ConstP = (-P[0])^(-1) mod 2^32 */ 238 } pkc_montgomery_inversion_t; 239 240 /** 241 * @brief PKC Big Number Multiplication expression input 242 * @note Result = A * B, up to 1024 bits 243 */ 244 typedef struct _pkc_big_number_multi { 245 uint32_t *p_A; /**< Pointer to operand A */ 246 uint32_t *p_B; /**< Pointer to operand B */ 247 } pkc_big_number_multi_t; 248 249 /** 250 * @brief PKC Big Number Addition expression input 251 * @note Result = A + B, up to 2048 bits 252 */ 253 typedef struct _pkc_big_number_add { 254 uint32_t *p_A; /**< Pointer to operand A */ 255 uint32_t *p_B; /**< Pointer to operand B */ 256 } pkc_big_number_add_t; 257 258 /** @} */ 259 260 /** @} */ 261 262 /** @addtogroup HAL_PKC_CALLBACK_STRUCTURES Callback Structures 263 * @{ 264 */ 265 266 /** @defgroup HAL_PKC_Callback Callback 267 * @{ 268 */ 269 270 /** 271 * @brief HAL_PKC Callback function definition 272 */ 273 274 typedef struct _hal_pkc_callback { 275 void (*pkc_msp_init)(pkc_handle_t *p_pkc); /**< PKC init MSP callback */ 276 void (*pkc_msp_deinit)(pkc_handle_t *p_pkc); /**< PKC de-init MSP callback */ 277 void (*pkc_done_callback)(pkc_handle_t *p_pkc); /**< PKC calculate done callback */ 278 void (*pkc_error_callback)(pkc_handle_t *p_pkc); /**< PKC error callback */ 279 void (*pkc_overflow_callback)(pkc_handle_t *p_pkc); /**< PKC over flow callback */ 280 } hal_pkc_callback_t; 281 282 /** @} */ 283 284 /** @} */ 285 286 /** 287 * @defgroup HAL_PKC_MACRO Defines 288 * @{ 289 */ 290 291 /* Exported constants --------------------------------------------------------*/ 292 /** @defgroup PKC_Exported_Constants PKC Exported Constants 293 * @{ 294 */ 295 296 /** @defgroup PKC_Error_Code PKC Error Code 297 * @{ 298 */ 299 #define HAL_PKC_ERROR_NONE ((uint32_t)0x00000000) /**< No error */ 300 #define HAL_PKC_ERROR_TIMEOUT ((uint32_t)0x00000001) /**< Timeout error */ 301 #define HAL_PKC_ERROR_TRANSFER ((uint32_t)0x00000002) /**< Transfer error */ 302 #define HAL_PKC_ERROR_OVERFLOW ((uint32_t)0x00000004) /**< Result overflow error */ 303 #define HAL_PKC_ERROR_INVALID_PARAM ((uint32_t)0x00000008) /**< Invalid parameters error */ 304 #define HAL_PKC_ERROR_INVERSE_K ((uint32_t)0x00000010) /**< Inverse K error */ 305 #define HAL_PKC_ERROR_IRREVERSIBLE ((uint32_t)0x00000020) /**< Irreversible error */ 306 /** @} */ 307 308 /** @defgroup PKC_Secure_Mode PKC Secure Mode 309 * @{ 310 */ 311 #define PKC_SECURE_MODE_DISABLE ((uint32_t)0x00000000) /**< Secure mode disable */ 312 #define PKC_SECURE_MODE_ENABLE ((uint32_t)0x00000001) /**< Secure mode enable */ 313 /** @} */ 314 315 /** @defgroup PKC_Operation_Mode PKC Operation Mode 316 * @{ 317 */ 318 #define PKC_OPERATION_MODE_MULTI LL_PKC_operation_mode_MULTIPLY /**< Multiplication operation mode */ 319 #define PKC_OPERATION_MODE_INVER LL_PKC_operation_mode_INVERTION /**< Inversion operation mode */ 320 #define PKC_OPERATION_MODE_ADD LL_PKC_operation_mode_ADD /**< Addition operation mode */ 321 #define PKC_OPERATION_MODE_SUB LL_PKC_operation_mode_SUB /**< Subtraction operation mode */ 322 #define PKC_OPERATION_MODE_CMP LL_PKC_operation_mode_COMPARE /**< Comparison operation mode */ 323 #define PKC_OPERATION_MODE_LSHIFT LL_PKC_operation_mode_LEFTSHIFT /**< Left Shift operation mode */ 324 #define PKC_OPERATION_MODE_BIGMULTI LL_PKC_operation_mode_BIGINTEGERMULTIPLY /**< Big Number Multiplication 325 operation mode */ 326 #define PKC_OPERATION_MODE_BIGADD LL_PKC_operation_mode_BIGINTEGERADD /**< Big Number Addition 327 operation mode */ 328 /** @} */ 329 330 /** @defgroup PKC_Bits_Length PKC Bits Length 331 * @{ 332 */ 333 #define PKC_BITS_LENGTH_MIN LL_PKC_BITS_LENGTH_MIN /**< Min value of bits length */ 334 #define PKC_BITS_LENGTH_MAX LL_PKC_BITS_LENGTH_MAX /**< Max value of bits length */ 335 #define PKC_BIGMULTI_BITS_LENGTH_MAX LL_PKC_BIGMULTI_BITS_LENGTH_MAX /**< Max value of big number multiplication 336 bits length */ 337 /** @} */ 338 339 /** @defgroup PKC_Flags PKC Flags 340 * @{ 341 */ 342 #define PKC_FLAG_BUSY LL_PKC_WORKSTAT_BUSY /**< Busy flag */ 343 /** @} */ 344 345 /** @defgroup PKC_Interrupt_definition PKC Interrupt_definition 346 * @{ 347 */ 348 #define PKC_IT_DONE LL_PKC_INTEN_DONE /**< Operation Done Interrupt source */ 349 #define PKC_IT_ERR LL_PKC_INTEN_ERR /**< Operation Error Interrupt source */ 350 #define PKC_IT_OVF LL_PKC_INTEN_BAOVF /**< Big Integer Result Overflow Interrupt source */ 351 /** @} */ 352 353 /** @defgroup PKC_Timeout_definition PKC Timeout_definition 354 * @{ 355 */ 356 #define HAL_PKC_TIMEOUT_DEFAULT_VALUE ((uint32_t)5000) /**< The default value of PKC timeout is 5s */ 357 /** @} */ 358 359 /** @} */ 360 361 /* Exported macro ------------------------------------------------------------*/ 362 /** @defgroup PKC_Exported_Macros PKC Exported Macros 363 * @{ 364 */ 365 366 /** @brief Reset PKC handle states. 367 * @param __HANDLE__ PKC handle. 368 * @retval None 369 */ 370 #define HAL_PKC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->state = HAL_PKC_STATE_RESET) 371 372 /** @brief Reset the specified PKC peripheral. 373 * @param __HANDLE__ PKC handle. 374 * @retval None 375 */ 376 #define HAL_PKC_RESET(__HANDLE__) \ 377 do { \ 378 CLEAR_BITS((__HANDLE__)->p_instance->CTRL, PKC_CTRL_SWRST); \ 379 SET_BITS((__HANDLE__)->p_instance->CTRL, PKC_CTRL_SWRST); \ 380 } while (0) 381 382 383 /** @brief Enable the specified PKC peripheral. 384 * @param __HANDLE__ Specifies the PKC Handle. 385 * @retval None 386 */ 387 #define HAL_PKC_ENABLE(__HANDLE__) SET_BITS((__HANDLE__)->p_instance->CTRL, PKC_CTRL_EN) 388 389 /** @brief Disable the specified PKC peripheral. 390 * @param __HANDLE__ Specifies the PKC Handle. 391 * @retval None 392 */ 393 #define HAL_PKC_DISABLE(__HANDLE__) CLEAR_BITS((__HANDLE__)->p_instance->CTRL, PKC_CTRL_EN) 394 395 /** @brief Enable the specified PKC interrupts. 396 * @param __HANDLE__ Specifies the PKC Handle. 397 * @param __INTERRUPT__ Specifies the interrupt source to enable. 398 * This parameter can be one of the following values: 399 * @arg @ref PKC_IT_DONE Operation Done Interrupt source 400 * @arg @ref PKC_IT_ERR Operation Error Interrupt source 401 * @arg @ref PKC_IT_OVF Big Integer Result Overflow Interrupt source 402 * @retval None 403 */ 404 #define HAL_PKC_ENABLE_IT(__HANDLE__, __INTERRUPT__) SET_BITS((__HANDLE__)->p_instance->INTEN, (__INTERRUPT__)) 405 406 /** @brief Disable the specified PKC interrupts. 407 * @param __HANDLE__ Specifies the PKC Handle. 408 * @param __INTERRUPT__ Specifies the interrupt source to disable. 409 * This parameter can be one of the following values: 410 * @arg @ref PKC_IT_DONE Operation Done Interrupt source 411 * @arg @ref PKC_IT_ERR Operation Error Interrupt source 412 * @arg @ref PKC_IT_OVF Big Integer Result Overflow Interrupt source 413 * @retval None 414 */ 415 #define HAL_PKC_DISABLE_IT(__HANDLE__, __INTERRUPT__) CLEAR_BITS((__HANDLE__)->p_instance->INTEN, (__INTERRUPT__)) 416 417 /** @brief Check whether the specified PKC interrupt flag is set or not. 418 * @param __HANDLE__ Specifies the PKC Handle. 419 * @param __FLAG__ Specifies the interrupt flag to check. 420 * This parameter can be one of the following values: 421 * @arg @ref PKC_IT_DONE Operation Done Interrupt source 422 * @arg @ref PKC_IT_ERR Operation Error Interrupt source 423 * @arg @ref PKC_IT_OVF Big Integer Result Overflow Interrupt source 424 * @retval The new state of __FLAG__ (TRUE or FALSE). 425 */ 426 #define HAL_PKC_GET_FLAG_IT(__HANDLE__, __FLAG__) \ 427 (READ_BITS((__HANDLE__)->p_instance->INTSTAT, (__FLAG__)) == (__FLAG__)) 428 429 /** @brief Clear the specified PKC interrupt flag. 430 * @param __HANDLE__ Specifies the PKC Handle. 431 * @param __FLAG__ Specifies the interrupt flag to clear. 432 * This parameter can be one of the following values: 433 * @arg @ref PKC_IT_DONE Operation Done Interrupt source 434 * @arg @ref PKC_IT_ERR Operation Error Interrupt source 435 * @arg @ref PKC_IT_OVF Big Integer Result Overflow Interrupt source 436 * @retval None 437 */ 438 #define HAL_PKC_CLEAR_FLAG_IT(__HANDLE__, __FLAG__) SET_BITS((__HANDLE__)->p_instance->INTSTAT, (__FLAG__)) 439 440 /** @brief Check whether the specified PKC flag is set or not. 441 * @param __HANDLE__ Specifies the PKC Handle. 442 * @param __FLAG__ Specifies the flag to check. 443 * This parameter can be one of the following values: 444 * @arg @ref PKC_FLAG_BUSY Busy flag 445 * @retval The new state of __FLAG__ (TRUE or FALSE). 446 */ 447 #define HAL_PKC_GET_FLAG(__HANDLE__, __FLAG__) \ 448 ((READ_BITS((__HANDLE__)->p_instance->WORKSTAT, (__FLAG__)) != 0) ? SET : RESET) 449 450 /** @} */ 451 452 /* Private macros ------------------------------------------------------------*/ 453 /** @defgroup PKC_Private_Macro PKC Private Macros 454 * @{ 455 */ 456 457 /** @brief Check if PKC Bits Length is valid. 458 * @param __BITS__ PKC Bits Length. 459 * @retval SET (__BITS__ is valid) or RESET (__BITS__ is invalid) 460 */ 461 #define IS_PKC_BITS_LENGTH(__BITS__) (((__BITS__) >= PKC_BITS_LENGTH_MIN) && ((__BITS__) <= PKC_BITS_LENGTH_MAX)) 462 463 /** @brief Check if PKC Big Number Multiplication Bits Length is valid. 464 * @param __BITS__ PKC Big Number Multiplication Bits Length. 465 * @retval SET (__BITS__ is valid) or RESET (__BITS__ is invalid) 466 */ 467 #define IS_PKC_BIGMULTI_BITS_LENGTH(__BITS__) \ 468 (((__BITS__) >= PKC_BITS_LENGTH_MIN) && ((__BITS__) <= PKC_BIGMULTI_BITS_LENGTH_MAX)) 469 470 /** @brief Check if PKC Secure Mode is valid. 471 * @param __MODE__ PKC Secure Mode. 472 * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid) 473 */ 474 #define IS_PKC_SECURE_MODE(__MODE__) (((__MODE__) == PKC_SECURE_MODE_DISABLE) || \ 475 ((__MODE__) == PKC_SECURE_MODE_ENABLE)) 476 477 /** @brief Check if PKC Operation Mode is valid. 478 * @param __MODE__ PKC Operation Mode. 479 * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid) 480 */ 481 #define IS_PKC_OPERATION_MODE(__MODE__) (((__MODE__) == PKC_OPERATION_MODE_MULTI) || \ 482 ((__MODE__) == PKC_OPERATION_MODE_INVER) || \ 483 ((__MODE__) == PKC_OPERATION_MODE_ADD) || \ 484 ((__MODE__) == PKC_OPERATION_MODE_SUB) || \ 485 ((__MODE__) == PKC_OPERATION_MODE_CMP) || \ 486 ((__MODE__) == PKC_OPERATION_MODE_LSHIFT) || \ 487 ((__MODE__) == PKC_OPERATION_MODE_BIGMULTI) || \ 488 ((__MODE__) == PKC_OPERATION_MODE_BIGADD)) 489 490 /** @} */ 491 492 /** @} */ 493 494 /* Exported functions --------------------------------------------------------*/ 495 /** @addtogroup HAL_PKC_DRIVER_FUNCTIONS Functions 496 * @{ 497 */ 498 499 /** @defgroup PKC_Exported_Functions_Group1 Initialization and de-initialization functions 500 * @brief Initialization and de-initialization functions 501 * 502 @verbatim 503 =============================================================================== 504 ##### Initialization and de-initialization functions ##### 505 =============================================================================== 506 [..] This subsection provides a set of functions allowing to initialize and 507 de-initialize the PKC peripheral. 508 509 (+) User must implement hal_pkc_msp_init() function in which it configures 510 all related peripherals resources (IT and NVIC ). 511 512 (+) Call the function hal_pkc_init() to configure the selected device with 513 the selected configuration: 514 (++) pECC_Curve 515 (++) DataBits 516 (++) SecureMode 517 (++) pRandomFunc 518 519 (+) Call the function hal_pkc_deinit() to restore the default configuration 520 of the selected PKC peripheral. 521 522 @endverbatim 523 * @{ 524 */ 525 526 /** 527 **************************************************************************************** 528 * @brief Initialize the PKC according to the specified parameters 529 * in the pkc_init_t and initialize the associated handle. 530 * @param[in] p_pkc: Pointer to a PKC handle which contains the configuration 531 * information for the specified PKC module. 532 * @retval ::HAL_OK: Operation is OK. 533 * @retval ::HAL_ERROR: Parameter error or operation not supported. 534 * @retval ::HAL_BUSY: Driver is busy. 535 * @retval ::HAL_TIMEOUT: Timeout occurred. 536 **************************************************************************************** 537 */ 538 hal_status_t hal_pkc_init(pkc_handle_t *p_pkc); 539 540 /** 541 **************************************************************************************** 542 * @brief De-initialize the PKC peripheral. 543 * @param[in] p_pkc: Pointer to a PKC handle which contains the configuration 544 * information for the specified PKC module. 545 * @retval ::HAL_OK: Operation is OK. 546 * @retval ::HAL_ERROR: Parameter error or operation not supported. 547 * @retval ::HAL_BUSY: Driver is busy. 548 * @retval ::HAL_TIMEOUT: Timeout occurred. 549 **************************************************************************************** 550 */ 551 hal_status_t hal_pkc_deinit(pkc_handle_t *p_pkc); 552 553 /** 554 **************************************************************************************** 555 * @brief Initialize the PKC MSP. 556 * @note This function should not be modified. When the callback is needed, 557 the hal_pkc_msp_deinit can be implemented in the user file. 558 * @param[in] p_pkc: Pointer to a PKC handle which contains the configuration 559 * information for the specified PKC module. 560 **************************************************************************************** 561 */ 562 void hal_pkc_msp_init(pkc_handle_t *p_pkc); 563 564 /** 565 **************************************************************************************** 566 * @brief De-initialize the PKC MSP. 567 * @note This function should not be modified. When the callback is needed, 568 the hal_pkc_msp_deinit can be implemented in the user file. 569 * @param[in] p_pkc: Pointer to a PKC handle which contains the configuration 570 * information for the specified PKC module. 571 **************************************************************************************** 572 */ 573 void hal_pkc_msp_deinit(pkc_handle_t *p_pkc); 574 575 /** @} */ 576 577 /** @defgroup PKC_Exported_Functions_Group2 IO Operation Functions 578 * @brief Data transfers functions 579 * 580 @verbatim 581 ============================================================================== 582 ##### IO operation functions ##### 583 =============================================================================== 584 [..] 585 This subsection provides a set of functions allowing to manage the PKC 586 data transfers. 587 588 (#) There are two modes of transfer: 589 (++) Blocking mode: The communication is performed in polling mode. 590 The HAL status of all data processing is returned by the same function 591 after finishing transfer. 592 (++) No-Blocking mode: The communication is performed using Interrupts 593 , These APIs return the HAL status. 594 The end of the data processing will be indicated through the 595 dedicated PKC IRQ when using Interrupt mode. 596 The hal_pkc_done_callback() user callbacks will be executed respectively at the end of the calculate process 597 The hal_pkc_error_callback() user callback will be executed when a communication error is detected 598 599 @endverbatim 600 * @{ 601 */ 602 603 /** 604 **************************************************************************************** 605 * @brief Execute RSA Modular Exponentiation in blocking mode. 606 * @note The computed result will be stored in the buffter pointed by p_pkc->pResult. 607 * @param[in] p_pkc: Pointer to a PKC handle which contains the configuration 608 * information for the specified PKC module. 609 * @param[in] p_input: Pointer to an expression structure which contains the input computing parameters. 610 * @param[in] timeout: Timeout duration 611 * @retval ::HAL_OK: Operation is OK. 612 * @retval ::HAL_ERROR: Parameter error or operation not supported. 613 * @retval ::HAL_BUSY: Driver is busy. 614 * @retval ::HAL_TIMEOUT: Timeout occurred. 615 **************************************************************************************** 616 */ 617 hal_status_t hal_pkc_rsa_modular_exponent(pkc_handle_t *p_pkc, pkc_rsa_modular_exponent_t *p_input, uint32_t timeout); 618 619 /** 620 **************************************************************************************** 621 * @brief Execute ECC Point Multiplication in blocking mode. 622 * @note The computed result will be stored in the buffter pointed by p_pkc->pResult. 623 * @param[in] p_pkc: Pointer to a PKC handle which contains the configuration 624 * information for the specified PKC module. 625 * @param[in] p_input: Pointer to an expression structure which contains the input computing parameters. 626 * @param[in] timeout: Timeout duration 627 * @retval ::HAL_OK: Operation is OK. 628 * @retval ::HAL_ERROR: Parameter error or operation not supported. 629 * @retval ::HAL_BUSY: Driver is busy. 630 * @retval ::HAL_TIMEOUT: Timeout occurred. 631 **************************************************************************************** 632 */ 633 hal_status_t hal_pkc_ecc_point_multi(pkc_handle_t *p_pkc, pkc_ecc_point_multi_t *p_input, uint32_t timeout); 634 635 /** 636 **************************************************************************************** 637 * @brief Execute ECC Point Multiplication in non-blocking mode with Interrupt. 638 * @note The computed result will be stored in the buffter pointed by p_pkc->pResult. 639 * @param[in] p_pkc: Pointer to a PKC handle which contains the configuration 640 * information for the specified PKC module. 641 * @param[in] p_input: Pointer to an expression structure which contains the input computing parameters. 642 * @retval ::HAL_OK: Operation is OK. 643 * @retval ::HAL_ERROR: Parameter error or operation not supported. 644 * @retval ::HAL_BUSY: Driver is busy. 645 * @retval ::HAL_TIMEOUT: Timeout occurred. 646 **************************************************************************************** 647 */ 648 hal_status_t hal_pkc_ecc_point_multi_it(pkc_handle_t *p_pkc, pkc_ecc_point_multi_t *p_input); 649 650 /** 651 **************************************************************************************** 652 * @brief Execute Modular Addition in blocking mode. 653 * @note The computed result will be stored in the buffter pointed by p_pkc->pResult. 654 * @param[in] p_pkc: Pointer to a PKC handle which contains the configuration 655 * information for the specified PKC module. 656 * @param[in] p_input: Pointer to an expression structure which contains the input computing parameters. 657 * @param[in] timeout: Timeout duration 658 * @retval ::HAL_OK: Operation is OK. 659 * @retval ::HAL_ERROR: Parameter error or operation not supported. 660 * @retval ::HAL_BUSY: Driver is busy. 661 * @retval ::HAL_TIMEOUT: Timeout occurred. 662 **************************************************************************************** 663 */ 664 hal_status_t hal_pkc_modular_add(pkc_handle_t *p_pkc, pkc_modular_add_t *p_input, uint32_t timeout); 665 666 /** 667 **************************************************************************************** 668 * @brief Execute Modular Addition in non-blocking mode with Interrupt. 669 * @note The computed result will be stored in the buffter pointed by p_pkc->pResult. 670 * @param[in] p_pkc: Pointer to a PKC handle which contains the configuration 671 * information for the specified PKC module. 672 * @param[in] p_input: Pointer to an expression structure which contains the input computing parameters. 673 * @retval ::HAL_OK: Operation is OK. 674 * @retval ::HAL_ERROR: Parameter error or operation not supported. 675 * @retval ::HAL_BUSY: Driver is busy. 676 * @retval ::HAL_TIMEOUT: Timeout occurred. 677 **************************************************************************************** 678 */ 679 hal_status_t hal_pkc_modular_add_it(pkc_handle_t *p_pkc, pkc_modular_add_t *p_input); 680 681 /** 682 **************************************************************************************** 683 * @brief Execute Modular Subtraction in blocking mode. 684 * @note The computed result will be stored in the buffter pointed by p_pkc->pResult. 685 * @param[in] p_pkc: Pointer to a PKC handle which contains the configuration 686 * information for the specified PKC module. 687 * @param[in] p_input: Pointer to an expression structure which contains the input computing parameters. 688 * @param[in] timeout: Timeout duration 689 * @retval ::HAL_OK: Operation is OK. 690 * @retval ::HAL_ERROR: Parameter error or operation not supported. 691 * @retval ::HAL_BUSY: Driver is busy. 692 * @retval ::HAL_TIMEOUT: Timeout occurred. 693 **************************************************************************************** 694 */ 695 hal_status_t hal_pkc_modular_sub(pkc_handle_t *p_pkc, pkc_modular_sub_t *p_input, uint32_t timeout); 696 697 /** 698 **************************************************************************************** 699 * @brief Execute Modular Subtraction in non-blocking mode with Interrupt. 700 * @note The computed result will be stored in the buffter pointed by p_pkc->pResult. 701 * @param[in] p_pkc: Pointer to a PKC handle which contains the configuration 702 * information for the specified PKC module. 703 * @param[in] p_input: Pointer to an expression structure which contains the input computing parameters. 704 * @retval ::HAL_OK: Operation is OK. 705 * @retval ::HAL_ERROR: Parameter error or operation not supported. 706 * @retval ::HAL_BUSY: Driver is busy. 707 * @retval ::HAL_TIMEOUT: Timeout occurred. 708 **************************************************************************************** 709 */ 710 hal_status_t hal_pkc_modular_sub_it(pkc_handle_t *p_pkc, pkc_modular_sub_t *p_input); 711 712 /** 713 **************************************************************************************** 714 * @brief Execute Modular Left Shift in blocking mode. 715 * @note The computed result will be stored in the buffter pointed by p_pkc->pResult. 716 * @param[in] p_pkc: Pointer to a PKC handle which contains the configuration 717 * information for the specified PKC module. 718 * @param[in] p_input: Pointer to an expression structure which contains the input computing parameters. 719 * @param[in] timeout: Timeout duration 720 * @retval ::HAL_OK: Operation is OK. 721 * @retval ::HAL_ERROR: Parameter error or operation not supported. 722 * @retval ::HAL_BUSY: Driver is busy. 723 * @retval ::HAL_TIMEOUT: Timeout occurred. 724 **************************************************************************************** 725 */ 726 hal_status_t hal_pkc_modular_left_shift(pkc_handle_t *p_pkc, pkc_modular_shift_t *p_input, uint32_t timeout); 727 728 /** 729 **************************************************************************************** 730 * @brief Execute Modular Left Shift in non-blocking mode with Interrupt. 731 * @note The computed result will be stored in the buffter pointed by p_pkc->pResult. 732 * @param[in] p_pkc: Pointer to a PKC handle which contains the configuration 733 * information for the specified PKC module. 734 * @param[in] p_input: Pointer to an expression structure which contains the input computing parameters. 735 * @retval ::HAL_OK: Operation is OK. 736 * @retval ::HAL_ERROR: Parameter error or operation not supported. 737 * @retval ::HAL_BUSY: Driver is busy. 738 * @retval ::HAL_TIMEOUT: Timeout occurred. 739 **************************************************************************************** 740 */ 741 hal_status_t hal_pkc_modular_left_shift_it(pkc_handle_t *p_pkc, pkc_modular_shift_t *p_input); 742 743 /** 744 **************************************************************************************** 745 * @brief Execute Modular Comparison in blocking mode. 746 * @note The computed result will be stored in the buffter pointed by p_pkc->pResult. 747 * @param[in] p_pkc: Pointer to a PKC handle which contains the configuration 748 * information for the specified PKC module. 749 * @param[in] p_input: Pointer to an expression structure which contains the input computing parameters. 750 * @param[in] timeout: Timeout duration 751 * @retval ::HAL_OK: Operation is OK. 752 * @retval ::HAL_ERROR: Parameter error or operation not supported. 753 * @retval ::HAL_BUSY: Driver is busy. 754 * @retval ::HAL_TIMEOUT: Timeout occurred. 755 **************************************************************************************** 756 */ 757 hal_status_t hal_pkc_modular_compare(pkc_handle_t *p_pkc, pkc_modular_compare_t *p_input, uint32_t timeout); 758 759 /** 760 **************************************************************************************** 761 * @brief Execute Modular Comparison in non-blocking mode with Interrupt. 762 * @note The computed result will be stored in the buffter pointed by p_pkc->pResult. 763 * @param[in] p_pkc: Pointer to a PKC handle which contains the configuration 764 * information for the specified PKC module. 765 * @param[in] p_input: Pointer to an expression structure which contains the input computing parameters. 766 * @retval ::HAL_OK: Operation is OK. 767 * @retval ::HAL_ERROR: Parameter error or operation not supported. 768 * @retval ::HAL_BUSY: Driver is busy. 769 * @retval ::HAL_TIMEOUT: Timeout occurred. 770 **************************************************************************************** 771 */ 772 hal_status_t hal_pkc_modular_compare_it(pkc_handle_t *p_pkc, pkc_modular_compare_t *p_input); 773 774 /** 775 **************************************************************************************** 776 * @brief Execute Montgomery Modular Multiplication in blocking mode. 777 * @note The computed result will be stored in the buffter pointed by p_pkc->pResult. 778 * @param[in] p_pkc: Pointer to a PKC handle which contains the configuration 779 * information for the specified PKC module. 780 * @param[in] p_input: Pointer to an expression structure which contains the input computing parameters. 781 * @param[in] timeout: Timeout duration 782 * @retval ::HAL_OK: Operation is OK. 783 * @retval ::HAL_ERROR: Parameter error or operation not supported. 784 * @retval ::HAL_BUSY: Driver is busy. 785 * @retval ::HAL_TIMEOUT: Timeout occurred. 786 **************************************************************************************** 787 */ 788 hal_status_t hal_pkc_montgomery_multi(pkc_handle_t *p_pkc, pkc_montgomery_multi_t *p_input, uint32_t timeout); 789 790 /** 791 **************************************************************************************** 792 * @brief Execute Montgomery Modular Multiplication in non-blocking mode with Interrupt. 793 * @note The computed result will be stored in the buffter pointed by p_pkc->pResult. 794 * @param[in] p_pkc: Pointer to a PKC handle which contains the configuration 795 * information for the specified PKC module. 796 * @param[in] p_input: Pointer to an expression structure which contains the input computing parameters. 797 * @retval ::HAL_OK: Operation is OK. 798 * @retval ::HAL_ERROR: Parameter error or operation not supported. 799 * @retval ::HAL_BUSY: Driver is busy. 800 * @retval ::HAL_TIMEOUT: Timeout occurred. 801 **************************************************************************************** 802 */ 803 hal_status_t hal_pkc_montgomery_multi_it(pkc_handle_t *p_pkc, pkc_montgomery_multi_t *p_input); 804 805 /** 806 **************************************************************************************** 807 * @brief Execute Montgomery Inversion in blocking mode. 808 * @note The computed result will be stored in the buffter pointed by p_pkc->pResult. 809 * @param[in] p_pkc: Pointer to a PKC handle which contains the configuration 810 * information for the specified PKC module. 811 * @param[in] p_input: Pointer to an expression structure which contains the input computing parameters. 812 * @param[in] timeout: Timeout duration 813 * @retval ::HAL_OK: Operation is OK. 814 * @retval ::HAL_ERROR: Parameter error or operation not supported. 815 * @retval ::HAL_BUSY: Driver is busy. 816 * @retval ::HAL_TIMEOUT: Timeout occurred. 817 **************************************************************************************** 818 */ 819 hal_status_t hal_pkc_montgomery_inversion(pkc_handle_t *p_pkc, pkc_montgomery_inversion_t *p_input, uint32_t timeout); 820 821 /** 822 **************************************************************************************** 823 * @brief Execute Montgomery Inversion in non-blocking mode with Interrupt. 824 * @note The computed result will be stored in the buffter pointed by p_pkc->pResult. 825 * @param[in] p_pkc: Pointer to a PKC handle which contains the configuration 826 * information for the specified PKC module. 827 * @param[in] p_input: Pointer to an expression structure which contains the input computing parameters. 828 * @retval ::HAL_OK: Operation is OK. 829 * @retval ::HAL_ERROR: Parameter error or operation not supported. 830 * @retval ::HAL_BUSY: Driver is busy. 831 * @retval ::HAL_TIMEOUT: Timeout occurred. 832 **************************************************************************************** 833 */ 834 hal_status_t hal_pkc_montgomery_inversion_it(pkc_handle_t *p_pkc, pkc_montgomery_inversion_t *p_input); 835 836 /** 837 **************************************************************************************** 838 * @brief Execute Big Number Multiplication in blocking mode. 839 * @note The computed result will be stored in the buffter pointed by p_pkc->pResult. 840 * @param[in] p_pkc: Pointer to a PKC handle which contains the configuration 841 * information for the specified PKC module. 842 * @param[in] p_input: Pointer to an expression structure which contains the input computing parameters. 843 * @param[in] timeout: Timeout duration 844 * @retval ::HAL_OK: Operation is OK. 845 * @retval ::HAL_ERROR: Parameter error or operation not supported. 846 * @retval ::HAL_BUSY: Driver is busy. 847 * @retval ::HAL_TIMEOUT: Timeout occurred. 848 **************************************************************************************** 849 */ 850 hal_status_t hal_pkc_big_number_multi(pkc_handle_t *p_pkc, pkc_big_number_multi_t *p_input, uint32_t timeout); 851 852 /** 853 **************************************************************************************** 854 * @brief Execute Big Number Multiplication in non-blocking mode with Interrupt. 855 * @note The computed result will be stored in the buffter pointed by p_pkc->pResult. 856 * @param[in] p_pkc: Pointer to a PKC handle which contains the configuration 857 * information for the specified PKC module. 858 * @param[in] p_input: Pointer to an expression structure which contains the input computing parameters. 859 * @retval ::HAL_OK: Operation is OK. 860 * @retval ::HAL_ERROR: Parameter error or operation not supported. 861 * @retval ::HAL_BUSY: Driver is busy. 862 * @retval ::HAL_TIMEOUT: Timeout occurred. 863 **************************************************************************************** 864 */ 865 hal_status_t hal_pkc_big_number_multi_it(pkc_handle_t *p_pkc, pkc_big_number_multi_t *p_input); 866 867 /** 868 **************************************************************************************** 869 * @brief Execute Big Number Addition in blocking mode. 870 * @note The computed result will be stored in the buffter pointed by p_pkc->pResult. 871 * @param[in] p_pkc: Pointer to a PKC handle which contains the configuration 872 * information for the specified PKC module. 873 * @param[in] p_input: Pointer to an expression structure which contains the input computing parameters. 874 * @param[in] timeout: Timeout duration 875 * @retval ::HAL_OK: Operation is OK. 876 * @retval ::HAL_ERROR: Parameter error or operation not supported. 877 * @retval ::HAL_BUSY: Driver is busy. 878 * @retval ::HAL_TIMEOUT: Timeout occurred. 879 **************************************************************************************** 880 */ 881 hal_status_t hal_pkc_big_number_add(pkc_handle_t *p_pkc, pkc_big_number_add_t *p_input, uint32_t timeout); 882 883 /** 884 **************************************************************************************** 885 * @brief Execute Big Number Addition in non-blocking mode with Interrupt. 886 * @note The computed result will be stored in the buffter pointed by p_pkc->pResult. 887 * @param[in] p_pkc: Pointer to a PKC handle which contains the configuration 888 * information for the specified PKC module. 889 * @param[in] p_input: Pointer to an expression structure which contains the input computing parameters. 890 * @retval ::HAL_OK: Operation is OK. 891 * @retval ::HAL_ERROR: Parameter error or operation not supported. 892 * @retval ::HAL_BUSY: Driver is busy. 893 * @retval ::HAL_TIMEOUT: Timeout occurred. 894 **************************************************************************************** 895 */ 896 hal_status_t hal_pkc_big_number_add_it(pkc_handle_t *p_pkc, pkc_big_number_add_t *p_input); 897 898 /** @} */ 899 900 /** @addtogroup PKC_IRQ_Handler_and_Callbacks IRQ Handler and Callbacks 901 * @brief IRQ Handler and Callbacks functions 902 * @{ 903 */ 904 905 /** 906 **************************************************************************************** 907 * @brief Handle PKC interrupt request. 908 * @param[in] p_pkc: Pointer to a PKC handle which contains the configuration 909 * information for the specified PKC module. 910 **************************************************************************************** 911 */ 912 void hal_pkc_irq_handler(pkc_handle_t *p_pkc); 913 914 /** 915 **************************************************************************************** 916 * @brief PKC calculate done callback. 917 * @param[in] p_pkc: Pointer to a PKC handle which contains the configuration 918 * information for the specified PKC module. 919 **************************************************************************************** 920 */ 921 void hal_pkc_done_callback(pkc_handle_t *p_pkc); 922 923 /** 924 **************************************************************************************** 925 * @brief PKC error callback. 926 * @param[in] p_pkc: Pointer to a PKC handle which contains the configuration 927 * information for the specified PKC module. 928 **************************************************************************************** 929 */ 930 void hal_pkc_error_callback(pkc_handle_t *p_pkc); 931 932 /** 933 **************************************************************************************** 934 * @brief PKC over flow callback. 935 * @param[in] p_pkc: Pointer to a PKC handle which contains the configuration 936 * information for the specified PKC module. 937 **************************************************************************************** 938 */ 939 void hal_pkc_overflow_callback(pkc_handle_t *p_pkc); 940 941 /** @} */ 942 943 /** @addtogroup PKC_Exported_Functions_Group3 Peripheral Control and State functions 944 * @brief PKC Peripheral State functions 945 * 946 @verbatim 947 ============================================================================== 948 ##### Peripheral Control and State functions ##### 949 ============================================================================== 950 [..] 951 This subsection provides functions allowing to : 952 (+) Return the PKC handle state. 953 (+) Return the PKC handle error code. 954 (+) Set the timeout during internal process. 955 956 @endverbatim 957 * @{ 958 */ 959 960 /** 961 **************************************************************************************** 962 * @brief Return the PKC handle state. 963 * @param[in] p_pkc: Pointer to a pkc_handle_t structure that contains 964 * the configuration information for the specified PKC. 965 * @retval ::HAL_PKC_STATE_RESET: Peripheral not initialized. 966 * @retval ::HAL_PKC_STATE_READY: Peripheral initialized and ready for use. 967 * @retval ::HAL_PKC_STATE_BUSY: Peripheral in indirect mode and busy. 968 * @retval ::HAL_PKC_STATE_ERROR: Peripheral in error. 969 * @retval ::HAL_PKC_STATE_TIMEOUT: Peripheral in timeout. 970 **************************************************************************************** 971 */ 972 hal_pkc_state_t hal_pkc_get_state(pkc_handle_t *p_pkc); 973 974 /** 975 **************************************************************************************** 976 * @brief Return the PKC error code. 977 * @param[in] p_pkc: Pointer to a PKC handle which contains the configuration 978 * information for the specified PKC module. 979 * @return PKC error code in bitmap format 980 **************************************************************************************** 981 */ 982 uint32_t hal_pkc_get_error(pkc_handle_t *p_pkc); 983 984 /** 985 **************************************************************************************** 986 * @brief Set the PKC internal process timeout value. 987 * @param[in] p_pkc: Pointer to a PKC handle which contains the configuration 988 * information for the specified PKC module. 989 * @param[in] timeout: Internal process timeout value. 990 **************************************************************************************** 991 */ 992 void hal_pkc_set_timeout(pkc_handle_t *p_pkc, uint32_t timeout); 993 994 /** 995 **************************************************************************************** 996 * @brief Suspend some registers related to PKC configuration before sleep. 997 * @param[in] p_pkc: Pointer to a PKC handle which contains the configuration 998 * information for the specified PKC module. 999 * @retval ::HAL_OK: Operation is OK. 1000 * @retval ::HAL_ERROR: Parameter error or operation not supported. 1001 * @retval ::HAL_BUSY: Driver is busy. 1002 * @retval ::HAL_TIMEOUT: Timeout occurred. 1003 **************************************************************************************** 1004 */ 1005 1006 hal_status_t hal_pkc_suspend_reg(pkc_handle_t *p_pkc); 1007 /** 1008 **************************************************************************************** 1009 * @brief Restore some registers related to PKC configuration after sleep. 1010 * This function must be used in conjunction with the hal_hmac_suspend_reg(). 1011 * @param[in] p_pkc: Pointer to a PKC handle which contains the configuration 1012 * information for the specified PKC module. 1013 * @retval ::HAL_OK: Operation is OK. 1014 * @retval ::HAL_ERROR: Parameter error or operation not supported. 1015 * @retval ::HAL_BUSY: Driver is busy. 1016 * @retval ::HAL_TIMEOUT: Timeout occurred. 1017 **************************************************************************************** 1018 */ 1019 1020 hal_status_t hal_pkc_resume_reg(pkc_handle_t *p_pkc); 1021 1022 /** @} */ 1023 1024 /** @} */ 1025 1026 #ifdef __cplusplus 1027 } 1028 #endif 1029 1030 #endif /* __GR55xx_HAL_PKC_H__ */ 1031 1032 /** @} */ 1033 1034 /** @} */ 1035 1036 /** @} */ 1037