rambus.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * Copyright (C) 2017-2020 Alibaba Group Holding Limited
  3. */
  4. #ifndef INC_RAMBUS_H
  5. #define INC_RAMBUS_H
  6. #include "device_types.h"
  7. #ifdef SEC_LIB_VERSION
  8. #include "drv/common.h"
  9. #include "device_rw.h"
  10. #include "rambus_log.h"
  11. #include "rambus_errcode.h"
  12. #else
  13. #include "common.h"
  14. #endif
  15. extern uint64_t g_freq_timer;
  16. extern uint64_t g_freq_ip;
  17. extern uint64_t g_start_ctr;
  18. extern uint64_t g_end_ctr;
  19. extern uint64_t g_data_len_in_bits;
  20. extern uint32_t g_type;
  21. enum rambus_cipher_padding_mode {
  22. PADDING_ZERO,
  23. PADDING_FF,
  24. PADDING_RANDOM,
  25. };
  26. uint32_t rb_get_random_byte(uint8_t *buf, uint32_t count);
  27. uint32_t rb_get_random_byte_nozero(uint8_t *buf, uint32_t count);
  28. uint32_t kdf_get_mask(uint8_t *mask, uint32_t len);
  29. /* 1 bpc, 2 tps, 3 bps */
  30. void rb_perf_init(uint32_t data_len_in_bits, uint32_t type);
  31. void rb_perf_start(void);
  32. void rb_perf_end(void);
  33. void rb_perf_get(char *ncase);
  34. #define DEFAULT_TIMEOUT 1000U
  35. #ifdef CONFIG_ALG_PERF_TEST
  36. #define RB_PERF_INIT(bits, type) \
  37. do { \
  38. if (data_len_in_bits != 0) { \
  39. g_data_len_in_bits = data_len_in_bits; \
  40. } \
  41. if (type != 0) { \
  42. g_type = type; \
  43. } \
  44. } while (0)
  45. #define RB_PERF_START_POINT() \
  46. do { \
  47. g_start_ctr = ((((uint64_t)csi_coret_get_valueh() << 32U) | \
  48. csi_coret_get_value())); \
  49. } while (0)
  50. #define RB_PERF_END_POINT() \
  51. do { \
  52. g_end_ctr = ((((uint64_t)csi_coret_get_valueh() << 32U) | \
  53. csi_coret_get_value())); \
  54. } while (0)
  55. #else
  56. #define RB_PERF_INIT(...)
  57. #define RB_PERF_START_POINT(...)
  58. #define RB_PERF_END_POINT(...)
  59. #endif
  60. static inline void rb_xor(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t len) {
  61. for (int i = 0; i < (int)len; i++) {
  62. c[i] = a[i] ^ b[i];
  63. }
  64. }
  65. /**
  66. * @brief Get the aes sca enable config
  67. *
  68. * @param is_en is enable
  69. * @return uint32_t
  70. */
  71. uint32_t rb_get_aes_sca(uint32_t *is_en);
  72. /**
  73. * @brief Get the sm4 sca enable config
  74. *
  75. * @param is_en is enable
  76. * @return uint32_t
  77. */
  78. uint32_t rb_get_sm4_sca(uint32_t *is_en);
  79. /**
  80. * @brief Get the pka sca enable config
  81. *
  82. * @param is_en is enable
  83. * @return uint32_t
  84. */
  85. uint32_t rb_get_pka_sca(uint32_t *is_en);
  86. /**
  87. * @brief rb_cache_en
  88. * @return uint32_t enable: 1
  89. *
  90. */
  91. uint32_t rb_cache_en(void);
  92. /**
  93. * @brief trng init
  94. *
  95. * @return csi_error_t
  96. */
  97. csi_error_t trng_init(void);
  98. /**
  99. * @brief rb wait status
  100. *
  101. * @param dev
  102. * @param offset
  103. * @param mask
  104. * @param status
  105. * @return uint32_t
  106. */
  107. csi_error_t rb_wait_status(Device_Handle_t *dev, const uint32_t offset, uint32_t mask,
  108. uint32_t status);
  109. /**
  110. * \brief rambus crypto init.
  111. * \return 0 if successful, or error code
  112. */
  113. uint32_t rambus_crypto_init(void);
  114. /**
  115. * @brief rambus crypto uninit.
  116. *
  117. */
  118. void rambus_crypto_uninit(void);
  119. /**
  120. * \brief rambus set cipher padding type.
  121. * @param padding_mode cipher padding mode
  122. * \return 0 if successful, or error code
  123. */
  124. uint32_t rambus_enable_cipher_padding_type(enum rambus_cipher_padding_mode padding_mode);
  125. #endif