ce_reg.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /*
  2. * The register macro of SUNXI SecuritySystem controller.
  3. *
  4. * Copyright (C) 2014 Allwinner.
  5. *
  6. * Mintow <duanmintao@allwinnertech.com>
  7. *
  8. * This file is licensed under the terms of the GNU General Public
  9. * License version 2. This program is licensed "as is" without any
  10. * warranty of any kind, whether express or implied.
  11. */
  12. #ifndef _SUNXI_CRYPTO_ENGINE_REG_H_
  13. #define _SUNXI_CRYPTO_ENGINE_REG_H_
  14. #include "platform_ce.h"
  15. #ifndef BIT
  16. #define BIT(nr) (1UL << (nr))
  17. #endif
  18. #define AES_MIN_KEY_SIZE 16
  19. /* CE: Crypto Engine*/
  20. #define CE_REG_TSK 0x00
  21. #ifdef CE_SUPPORT_CE_V3_1
  22. #define CE_REG_CTL 0x04
  23. #endif
  24. #define CE_REG_ICR 0x08
  25. #define CE_REG_ISR 0x0C
  26. #define CE_REG_TLR 0x10
  27. #define CE_REG_TSR 0x14
  28. #define CE_REG_ERR 0x18
  29. #ifdef CE_SUPPORT_CE_V3_1
  30. #define CE_REG_CSS 0x1C
  31. #define CE_REG_CDS 0x20
  32. #endif
  33. #define CE_REG_CSA 0x24
  34. #define CE_REG_CDA 0x28
  35. #ifdef CE_SUPPORT_CE_V3_1
  36. #define CE_REG_TPR 0x2C
  37. #endif
  38. #ifdef CE_SUPPORT_CE_V3_2
  39. #define CE_REG_HCSA 0x34
  40. #define CE_REG_HCDA 0x38
  41. #define CE_REG_ACSA 0x44
  42. #define CE_REG_ACDA 0x48
  43. #define CE_REG_XCSA 0x54
  44. #define CE_REG_XCDA 0x58
  45. #endif
  46. #define CE_REG_VER 0x90
  47. #define CE_CHAN_INT_ENABLE 1
  48. #define CE_CHAN_PENDING 1
  49. #ifndef CE_SUPPORT_CE_V3_1
  50. #define CE_REG_TLR_METHOD_TYPE_SHIFT 8
  51. #endif
  52. #ifdef CE_SUPPORT_CE_V3_1
  53. #define CE_REG_TSR_BUSY 1
  54. #define CE_REG_TSR_IDLE 0
  55. #define CE_REG_TSR_BUSY_SHIFT 0
  56. #define CE_REG_TSR_BUSY_MASK (0x1 << CE_REG_TSR_BUSY_SHIFT)
  57. #endif
  58. #define CE_REG_ESR_ERR_UNSUPPORT 0
  59. #define CE_REG_ESR_ERR_LEN 1
  60. #define CE_REG_ESR_ERR_KEYSRAM 2
  61. #ifdef CE_SUPPORT_CE_V3_1
  62. #define CE_REG_ESR_ERR_ADDR 3
  63. #else
  64. #define CE_REG_ESR_ERR_ADDR 5
  65. #endif
  66. #ifdef CE_SUPPORT_CE_V3_2
  67. #define CE_REG_ESR_ERR_KEYLADDER 6
  68. #endif
  69. #ifdef CE_SUPPORT_CE_V3_1
  70. #define CE_REG_ESR_CHAN_SHIFT 4
  71. #define CE_REG_ESR_CHAN_MASK(flow) (0xF << (CE_REG_ESR_CHAN_SHIFT*flow))
  72. #else
  73. #define CE_REG_ESR_CHAN_SHIFT 8
  74. #define CE_REG_ESR_CHAN_MASK(flow) (0xFF << (CE_REG_ESR_CHAN_SHIFT*flow))
  75. #endif
  76. #ifdef CE_SUPPORT_CE_V3_1
  77. #define CE_REG_CSS_OFFSET_SHIFT 16
  78. #define CE_REG_CDS_OFFSET_SHIFT 16
  79. #endif
  80. /* About the common control word */
  81. #ifdef CE_SUPPORT_CE_V3_1
  82. #define CE_TASK_INT_ENABLE 1
  83. #endif
  84. #define CE_COMM_CTL_TASK_INT_SHIFT 31
  85. #define CE_COMM_CTL_TASK_INT_MASK (0x1 << CE_COMM_CTL_TASK_INT_SHIFT)
  86. #define CE_CBC_MAC_LEN_SHIFT 17
  87. #define CE_HASH_IV_DEFAULT 0
  88. #define CE_HASH_IV_INPUT 1
  89. #define CE_COMM_CTL_IV_MODE_SHIFT 16
  90. #define CE_HMAC_SHA1_LAST BIT(15)
  91. #define CE_DIR_ENCRYPT 0
  92. #define CE_DIR_DECRYPT 1
  93. #define CE_COMM_CTL_OP_DIR_SHIFT 8
  94. #define CE_METHOD_AES 0
  95. #define CE_METHOD_DES 1
  96. #define CE_METHOD_3DES 2
  97. #define CE_METHOD_MD5 16
  98. #define CE_METHOD_SHA1 17
  99. #define CE_METHOD_SHA224 18
  100. #define CE_METHOD_SHA256 19
  101. #define CE_METHOD_SHA384 20
  102. #define CE_METHOD_SHA512 21
  103. #define CE_METHOD_HMAC_SHA1 22
  104. #define CE_METHOD_HMAC_SHA256 23
  105. #define CE_METHOD_RSA 32
  106. #define CE_METHOD_DH CE_METHOD_RSA
  107. #ifdef CE_SUPPORT_CE_V3_1
  108. #define CE_METHOD_TRNG 48
  109. #define CE_METHOD_PRNG 49
  110. #define CE_METHOD_ECC 64
  111. #else
  112. #define CE_METHOD_TRNG 28
  113. #define CE_METHOD_PRNG 29
  114. #define CE_METHOD_ECC 33
  115. #define CE_METHOD_RAES 48
  116. #endif
  117. #define SS_RNG_MAX_LEN (0x2000)
  118. #define CE_COMM_CTL_METHOD_SHIFT 0
  119. #ifdef CE_SUPPORT_CE_V3_1
  120. #define CE_COMM_CTL_METHOD_MASK 0x3F
  121. #else
  122. #define CE_COMM_CTL_METHOD_MASK 0x7F
  123. #endif
  124. #define CE_METHOD_IS_HASH(type) ((type == CE_METHOD_MD5) \
  125. || (type == CE_METHOD_SHA1) \
  126. || (type == CE_METHOD_SHA224) \
  127. || (type == CE_METHOD_SHA256) \
  128. || (type == CE_METHOD_SHA384) \
  129. || (type == CE_METHOD_SHA512))
  130. #define CE_METHOD_IS_AES(type) ((type == CE_METHOD_AES) \
  131. || (type == CE_METHOD_DES) \
  132. || (type == CE_METHOD_3DES))
  133. #define CE_METHOD_IS_HMAC(type) ((type == CE_METHOD_HMAC_SHA1) \
  134. || (type == CE_METHOD_HMAC_SHA256))
  135. /* About the symmetric control word */
  136. #define CE_KEY_SELECT_INPUT 0
  137. #define CE_KEY_SELECT_SSK 1
  138. #define CE_KEY_SELECT_HUK 2
  139. #define CE_KEY_SELECT_RSSK 3
  140. #ifdef CE_SUPPORT_CE_V3_2
  141. #define CE_KEY_SELECT_SCK0 4
  142. #define CE_KEY_SELECT_SCK1 5
  143. #endif
  144. #define CE_KEY_SELECT_INTERNAL_0 8
  145. #define CE_KEY_SELECT_INTERNAL_1 9
  146. #define CE_KEY_SELECT_INTERNAL_2 10
  147. #define CE_KEY_SELECT_INTERNAL_3 11
  148. #define CE_KEY_SELECT_INTERNAL_4 12
  149. #define CE_KEY_SELECT_INTERNAL_5 13
  150. #define CE_KEY_SELECT_INTERNAL_6 14
  151. #define CE_KEY_SELECT_INTERNAL_7 15
  152. #define CE_SYM_CTL_KEY_SELECT_SHIFT 20
  153. /* The identification string to indicate the key source. */
  154. #define CE_KS_SSK "KEY_SEL_SSK"
  155. #define CE_KS_HUK "KEY_SEL_HUK"
  156. #define CE_KS_RSSK "KEY_SEL_RSSK"
  157. #ifdef CE_SUPPORT_CE_V3_2
  158. #define CE_KS_SCK0 "KEY_SEL_SCK0"
  159. #define CE_KS_SCK1 "KEY_SEL_SCK1"
  160. #endif
  161. #define CE_KS_INTERNAL_0 "KEY_SEL_INTRA_0"
  162. #define CE_KS_INTERNAL_1 "KEY_SEL_INTRA_1"
  163. #define CE_KS_INTERNAL_2 "KEY_SEL_INTRA_2"
  164. #define CE_KS_INTERNAL_3 "KEY_SEL_INTRA_3"
  165. #define CE_KS_INTERNAL_4 "KEY_SEL_INTRA_4"
  166. #define CE_KS_INTERNAL_5 "KEY_SEL_INTRA_5"
  167. #define CE_KS_INTERNAL_6 "KEY_SEL_INTRA_6"
  168. #define CE_KS_INTERNAL_7 "KEY_SEL_INTRA_7"
  169. #define CE_CFB_WIDTH_1 0
  170. #define CE_CFB_WIDTH_8 1
  171. #define CE_CFB_WIDTH_64 2
  172. #define CE_CFB_WIDTH_128 3
  173. #define CE_SYM_CTL_CFB_WIDTH_SHIFT 18
  174. #define CE_SYM_CTL_AES_CTS_LAST BIT(16)
  175. #ifndef CE_SUPPORT_CE_V3_1
  176. #define CE_SYM_CTL_AES_XTS_LAST BIT(13)
  177. #define CE_SYM_CTL_AES_XTS_FIRST BIT(12)
  178. #endif
  179. #define CE_AES_MODE_ECB 0
  180. #define CE_AES_MODE_CBC 1
  181. #define CE_AES_MODE_CTR 2
  182. #define CE_AES_MODE_CTS 3
  183. #define CE_AES_MODE_OFB 4
  184. #define CE_AES_MODE_CFB 5
  185. #define CE_AES_MODE_CBC_MAC 6
  186. #define CE_AES_MODE_XTS 9
  187. #define CE_SYM_CTL_OP_MODE_SHIFT 8
  188. #define CE_CTR_SIZE_16 0
  189. #define CE_CTR_SIZE_32 1
  190. #define CE_CTR_SIZE_64 2
  191. #define CE_CTR_SIZE_128 3
  192. #define CE_SYM_CTL_CTR_SIZE_SHIFT 2
  193. #define CE_AES_KEY_SIZE_128 0
  194. #define CE_AES_KEY_SIZE_192 1
  195. #define CE_AES_KEY_SIZE_256 2
  196. #define CE_SYM_CTL_KEY_SIZE_SHIFT 0
  197. #define CE_IS_AES_MODE(type, mode, M) (CE_METHOD_IS_AES(type) \
  198. && (mode == CE_AES_MODE_##M))
  199. /* About the asymmetric control word */
  200. #ifdef CE_SUPPORT_CE_V3_1
  201. #define CE_RSA_PUB_MODULUS_WIDTH_512 0
  202. #define CE_RSA_PUB_MODULUS_WIDTH_1024 1
  203. #define CE_RSA_PUB_MODULUS_WIDTH_2048 2
  204. #define CE_RSA_PUB_MODULUS_WIDTH_3072 3
  205. #define CE_RSA_PUB_MODULUS_WIDTH_4096 4
  206. #define CE_ASYM_CTL_RSA_PM_WIDTH_SHIFT 28
  207. #endif
  208. #define CE_RSA_OP_M_EXP 0 /* modular exponentiation */
  209. #ifdef CE_SUPPORT_CE_V3_1
  210. #define CE_RSA_OP_M_MUL 2 /* modular multiplication */
  211. #else
  212. #define CE_RSA_OP_M_ADD 1 /* modular add */
  213. #define CE_RSA_OP_M_MINUS 2 /* modular minus */
  214. #define CE_RSA_OP_M_MUL 3 /* modular multiplication */
  215. #endif
  216. #define CE_ASYM_CTL_RSA_OP_SHIFT 16
  217. #ifdef CE_SUPPORT_CE_V3_1
  218. #define CE_ECC_PARA_WIDTH_160 0
  219. #define CE_ECC_PARA_WIDTH_224 2
  220. #define CE_ECC_PARA_WIDTH_256 3
  221. #define CE_ECC_PARA_WIDTH_521 5
  222. #define CE_ASYM_CTL_ECC_PARA_WIDTH_SHIFT 12
  223. #endif
  224. #ifdef CE_SUPPORT_CE_V3_1
  225. #define CE_ECC_OP_POINT_MUL 0
  226. #define CE_ECC_OP_POINT_ADD 1
  227. #define CE_ECC_OP_POINT_DBL 2
  228. #define CE_ECC_OP_POINT_VER 3
  229. #define CE_ECC_OP_ENC 4
  230. #define CE_ECC_OP_DEC 5
  231. #define CE_ECC_OP_SIGN 6
  232. #define CE_ASYM_CTL_ECC_OP_SHIFT 4
  233. #else
  234. #define CE_ECC_OP_POINT_ADD 0 /* point add */
  235. #define CE_ECC_OP_POINT_DBL 1 /* point double */
  236. #define CE_ECC_OP_POINT_MUL 2 /* point multiplication */
  237. #define CE_ECC_OP_POINT_VER 3 /* point verification */
  238. #define CE_ECC_OP_ENC 4 /* encryption */
  239. #define CE_ECC_OP_DEC 5 /* decryption */
  240. #define CE_ECC_OP_SIGN 6 /* sign */
  241. #define CE_ECC_OP_VERIFY 7 /* verification */
  242. #endif
  243. #define CE_SEED_SIZE 24
  244. /* The descriptor of a CE task. */
  245. #define CE_SCATTERS_PER_TASK 8
  246. #endif /* end of _SUNXI_CRYPTO_ENGINE_REG_H_ */