sunxi_hal_ce.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #ifndef SUNXI_HAL_TWI_H
  2. #define SUNXI_HAL_TWI_H
  3. #include "hal_sem.h"
  4. #include "hal_clk.h"
  5. #include "sunxi_hal_common.h"
  6. #include "hal_gpio.h"
  7. #include "sunxi_hal_regulator.h"
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. #define CE_ALIGN_SIZE (0x4)
  12. #define CE_ROUND_UP(x,y) ((((x) + ((y) - 1)) / (y)) * (y))
  13. #define AES_KEYSIZE_128 128
  14. #define AES_KEYSIZE_192 192
  15. #define AES_KEYSIZE_256 256
  16. #define AES_BLOCK_SIZE (16)
  17. /*define the ctx for aes requtest*/
  18. typedef struct {
  19. uint8_t *src_buffer;
  20. uint32_t src_length;
  21. uint8_t *dst_buffer;
  22. uint32_t dst_length;
  23. uint8_t *iv;
  24. uint8_t *iv_next;
  25. uint8_t *key;
  26. uint32_t key_length;
  27. uint8_t padding[AES_BLOCK_SIZE];
  28. uint32_t padding_len;
  29. uint32_t dir;
  30. uint32_t mode;
  31. uint32_t bitwidth;
  32. } crypto_aes_req_ctx_t;
  33. /*define the ctx for hash requtest*/
  34. #define SHA_MAX_DIGEST_SIZE (64)
  35. #define MD5_DIGEST_SIZE (16)
  36. #define SHA1_DIGEST_SIZE (20)
  37. #define SHA224_DIGEST_SIZE (28)
  38. #define SHA256_DIGEST_SIZE (32)
  39. #define SHA384_DIGEST_SIZE (48)
  40. #define SHA512_DIGEST_SIZE (64)
  41. #define MD5_BLOCK_SIZE (64)
  42. #define SHA1_BLOCK_SIZE (64)
  43. #define SHA224_BLOCK_SIZE (64)
  44. #define SHA256_BLOCK_SIZE (64)
  45. #define SHA384_BLOCK_SIZE (128)
  46. #define SHA512_BLOCK_SIZE (128)
  47. typedef struct {
  48. uint8_t *src_buffer;
  49. uint32_t src_length;
  50. uint8_t *dst_buffer;
  51. uint32_t dst_length;
  52. uint8_t md[SHA_MAX_DIGEST_SIZE];
  53. uint32_t md_size;
  54. uint8_t padding[SHA512_BLOCK_SIZE * 2];
  55. uint32_t padding_len;
  56. uint32_t type;
  57. uint32_t dir;
  58. uint32_t padding_mode;
  59. } crypto_hash_req_ctx_t;
  60. typedef struct {
  61. uint8_t *rng_buf;
  62. uint32_t rng_len;
  63. uint32_t mode;
  64. uint8_t *key;
  65. uint32_t key_len;
  66. } crypto_rng_req_ctx_t;
  67. /*define the ctx for rsa requtest*/
  68. typedef struct {
  69. uint8_t *key_n;
  70. uint32_t n_len;
  71. uint8_t *key_e;
  72. uint32_t e_len;
  73. uint8_t *key_d;
  74. uint32_t d_len;
  75. uint8_t *src_buffer;
  76. uint32_t src_length;
  77. uint8_t *dst_buffer;
  78. uint32_t dst_length;
  79. uint32_t dir;
  80. uint32_t type;
  81. uint32_t bitwidth;
  82. } crypto_rsa_req_ctx_t;
  83. int do_aes_crypto(crypto_aes_req_ctx_t *req_ctx);
  84. int sunxi_ce_init(void);
  85. int sunxi_ce_uninit(void);
  86. int do_hash_crypto(crypto_hash_req_ctx_t *req_ctx);
  87. int do_rsa_crypto(crypto_rsa_req_ctx_t *req_ctx);
  88. int do_rsa_crypto_new(crypto_rsa_req_ctx_t *req_ctx);
  89. int do_rng_gen(crypto_rng_req_ctx_t *req_ctx);
  90. #ifdef __cplusplus
  91. }
  92. #endif
  93. #endif