mpi_hal.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * SPDX-FileCopyrightText: 2023 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 <stdbool.h>
  13. #include <stdint.h>
  14. #include <sys/param.h>
  15. #include "hal/mpi_types.h"
  16. #include "sdkconfig.h"
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. /**
  21. * @brief Calculate the number of words needed to represent the input word in hardware.
  22. *
  23. * @param words The number of words to be represented.
  24. * @return size_t Number of words required.
  25. */
  26. size_t mpi_hal_calc_hardware_words(size_t words);
  27. /**
  28. * @brief Clear the MPI power control bit and intitialise the MPI hardware.
  29. *
  30. */
  31. void mpi_hal_enable_hardware_hw_op(void);
  32. /**
  33. * @brief Set the MPI power control bit to disable the MPI hardware.
  34. *
  35. */
  36. void mpi_hal_disable_hardware_hw_op(void);
  37. /**
  38. * @brief Enable/disables MPI operation complete interrupt.
  39. *
  40. * @param enable true: enable, false: disable.
  41. */
  42. void mpi_hal_interrupt_enable(bool enable);
  43. /**
  44. * @brief Clears the MPI operation complete interrupt status.
  45. *
  46. */
  47. void mpi_hal_clear_interrupt(void);
  48. /**
  49. * @brief Configure RSA length.
  50. *
  51. * @param num_words Number of words representing the RSA length.
  52. */
  53. void mpi_hal_set_mode(size_t num_words);
  54. /**
  55. * @brief Copy the large number (array of words) representation of the parameter 'param' to hardware memory block.
  56. *
  57. * @param param Type of parameter (enum).
  58. * @param offset Offset to copy in the memory from the base address of the parameter.
  59. * @param p Pointer to large number (array of words) representation of the parameter.
  60. * @param n Number of words needed to represent the large number as an array of words.
  61. * @param num_words Maximum hardware words needed.
  62. */
  63. void mpi_hal_write_to_mem_block(mpi_param_t param, size_t offset, const uint32_t* p, size_t n, size_t num_words);
  64. /**
  65. * @brief Write a word-sized value to hardware memory block of a parameter.
  66. *
  67. * @param param Type of parameter (enum).
  68. * @param offset Offset to copy in the memory from the base address of the parameter.
  69. * @param value Value to be written in the memory.
  70. */
  71. void mpi_hal_write_at_offset(mpi_param_t param, int offset, uint32_t value);
  72. /**
  73. * @brief Write the modular multiplicative inverse of M.
  74. *
  75. * @param Mprime Modular multiplicative inverse of M.
  76. */
  77. void mpi_hal_write_m_prime(uint32_t Mprime);
  78. /**
  79. * @brief Write first word of the parametr Rinv.
  80. *
  81. * @param rinv Value of first word of rinv.
  82. */
  83. void mpi_hal_write_rinv(uint32_t rinv);
  84. #if !CONFIG_IDF_TARGET_ESP32
  85. /**
  86. * @brief Enable/Disable constant time acceleration option.
  87. *
  88. * @param enable true: enable, false: disable.
  89. */
  90. void mpi_hal_enable_constant_time(bool enable);
  91. /**
  92. * @brief Enable/Disable search time acceleration option.
  93. *
  94. * @param enable
  95. */
  96. void mpi_hal_enable_search(bool enable);
  97. /**
  98. * @brief Configures the starting address to start search.
  99. *
  100. * @param position Address to start search.
  101. */
  102. void mpi_hal_set_search_position(size_t position);
  103. #endif /* !CONFIG_IDF_TARGET_ESP32 */
  104. /**
  105. * @brief Begin an MPI operation.
  106. *
  107. * @param op Operation type (enum).
  108. */
  109. void mpi_hal_start_op(mpi_op_t op);
  110. /**
  111. * @brief Wait for an MPI operation to complete.
  112. *
  113. */
  114. void mpi_hal_wait_op_complete(void);
  115. /**
  116. * @brief Wait for an MPI operation to complete and Read result from last MPI operation into parameter Z.
  117. *
  118. * @param p Pointer to large number (array of words) representation of the parameter.
  119. * @param n Number of words needed to represent the large number as an array of words.
  120. * @param z_words Calculated number of words of parameter Z.
  121. */
  122. void mpi_hal_read_result_hw_op(uint32_t* p, size_t n, size_t z_words);
  123. #ifdef __cplusplus
  124. }
  125. #endif