ecc_hal.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /*******************************************************************************
  7. * NOTICE
  8. * The HAL is not public api, don't use in application code.
  9. * See readme.md in soc/README.md
  10. ******************************************************************************/
  11. #pragma once
  12. #include "stdint.h"
  13. #include "hal/ecc_types.h"
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. /**
  18. * @brief Set the work mode of the operation
  19. *
  20. * @param mode Mode of operation
  21. */
  22. void ecc_hal_set_mode(ecc_mode_t mode);
  23. /**
  24. * @brief Set the ECC curve of operation
  25. *
  26. * @param curve Curve to use for operation
  27. */
  28. void ecc_hal_set_curve(ecc_curve_t curve);
  29. /**
  30. * @brief Start calculation
  31. *
  32. */
  33. void ecc_hal_start_calc(void);
  34. /**
  35. * @brief Check whether the calculation has finished
  36. *
  37. * @return - 1 if the hardware has finished calculating
  38. * - 0 otherwise
  39. */
  40. int ecc_hal_is_calc_finished(void);
  41. /**
  42. * @brief Write parameters for point multiplication (K * (Px, Py))
  43. *
  44. * @param k Scalar value
  45. * @param px X coordinate of the ECC point
  46. * @param py Y coordinate of the ECC point
  47. * @param len Length (in bytes) of the ECC point
  48. * - 32 bytes for SECP256R1
  49. * - 24 bytes for SECP192R1
  50. */
  51. void ecc_hal_write_mul_param(const uint8_t *k, const uint8_t *px, const uint8_t *py, uint16_t len);
  52. /**
  53. * @brief Write parameters for point verification,
  54. * i.e to check if the point lies on the curve
  55. *
  56. * @param px X coordinate of the ECC point
  57. * @param py Y coordinate of the ECC point
  58. * @param len Length (in bytes) of the ECC point
  59. * - 32 for SECP256R1
  60. * - 24 for SECP192R1
  61. */
  62. void ecc_hal_write_verify_param(const uint8_t *px, const uint8_t *py, uint16_t len);
  63. /**
  64. * @brief Read point multiplication result
  65. *
  66. * @param rx X coordinate of the multiplication result
  67. * @param ry Y coordinate of the multiplication result
  68. * @param len Length (in bytes) of the ECC point
  69. * - 32 for SECP256R1
  70. * - 24 for SECP192R1
  71. *
  72. * @return - 0 if the operation was successful
  73. * - -1 if the operation was not successful
  74. *
  75. * In case the operation is not successful, rx and ry will contain
  76. * all zeros
  77. */
  78. int ecc_hal_read_mul_result(uint8_t *rx, uint8_t *ry, uint16_t len);
  79. /**
  80. * @brief Read point verification result
  81. *
  82. * @return - 1 if point lies on curve
  83. * - 0 otherwise
  84. */
  85. int ecc_hal_read_verify_result(void);
  86. #ifdef __cplusplus
  87. }
  88. #endif