sec_crypto.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright (c) 2019 HiSilicon Limited. */
  3. #ifndef __HISI_SEC_V2_CRYPTO_H
  4. #define __HISI_SEC_V2_CRYPTO_H
  5. #define SEC_AIV_SIZE 12
  6. #define SEC_IV_SIZE 24
  7. #define SEC_MAX_KEY_SIZE 64
  8. #define SEC_MAX_AKEY_SIZE 128
  9. #define SEC_COMM_SCENE 0
  10. #define SEC_MIN_BLOCK_SZ 1
  11. enum sec_calg {
  12. SEC_CALG_3DES = 0x1,
  13. SEC_CALG_AES = 0x2,
  14. SEC_CALG_SM4 = 0x3,
  15. };
  16. enum sec_hash_alg {
  17. SEC_A_HMAC_SHA1 = 0x10,
  18. SEC_A_HMAC_SHA256 = 0x11,
  19. SEC_A_HMAC_SHA512 = 0x15,
  20. };
  21. enum sec_cmode {
  22. SEC_CMODE_ECB = 0x0,
  23. SEC_CMODE_CBC = 0x1,
  24. SEC_CMODE_CTR = 0x4,
  25. SEC_CMODE_CCM = 0x5,
  26. SEC_CMODE_GCM = 0x6,
  27. SEC_CMODE_XTS = 0x7,
  28. };
  29. enum sec_ckey_type {
  30. SEC_CKEY_128BIT = 0x0,
  31. SEC_CKEY_192BIT = 0x1,
  32. SEC_CKEY_256BIT = 0x2,
  33. SEC_CKEY_3DES_3KEY = 0x1,
  34. SEC_CKEY_3DES_2KEY = 0x3,
  35. };
  36. enum sec_bd_type {
  37. SEC_BD_TYPE1 = 0x1,
  38. SEC_BD_TYPE2 = 0x2,
  39. SEC_BD_TYPE3 = 0x3,
  40. };
  41. enum sec_auth {
  42. SEC_NO_AUTH = 0x0,
  43. SEC_AUTH_TYPE1 = 0x1,
  44. SEC_AUTH_TYPE2 = 0x2,
  45. };
  46. enum sec_cipher_dir {
  47. SEC_CIPHER_ENC = 0x1,
  48. SEC_CIPHER_DEC = 0x2,
  49. };
  50. enum sec_addr_type {
  51. SEC_PBUF = 0x0,
  52. SEC_SGL = 0x1,
  53. SEC_PRP = 0x2,
  54. };
  55. struct bd_status {
  56. u64 tag;
  57. u8 done;
  58. u8 err_type;
  59. u16 flag;
  60. u16 icv;
  61. };
  62. enum {
  63. AUTHPAD_PAD,
  64. AUTHPAD_NOPAD,
  65. };
  66. enum {
  67. AIGEN_GEN,
  68. AIGEN_NOGEN,
  69. };
  70. struct sec_sqe_type2 {
  71. /*
  72. * mac_len: 0~4 bits
  73. * a_key_len: 5~10 bits
  74. * a_alg: 11~16 bits
  75. */
  76. __le32 mac_key_alg;
  77. /*
  78. * c_icv_len: 0~5 bits
  79. * c_width: 6~8 bits
  80. * c_key_len: 9~11 bits
  81. * c_mode: 12~15 bits
  82. */
  83. __le16 icvw_kmode;
  84. /* c_alg: 0~3 bits */
  85. __u8 c_alg;
  86. __u8 rsvd4;
  87. /*
  88. * a_len: 0~23 bits
  89. * iv_offset_l: 24~31 bits
  90. */
  91. __le32 alen_ivllen;
  92. /*
  93. * c_len: 0~23 bits
  94. * iv_offset_h: 24~31 bits
  95. */
  96. __le32 clen_ivhlen;
  97. __le16 auth_src_offset;
  98. __le16 cipher_src_offset;
  99. __le16 cs_ip_header_offset;
  100. __le16 cs_udp_header_offset;
  101. __le16 pass_word_len;
  102. __le16 dk_len;
  103. __u8 salt3;
  104. __u8 salt2;
  105. __u8 salt1;
  106. __u8 salt0;
  107. __le16 tag;
  108. __le16 rsvd5;
  109. /*
  110. * c_pad_type: 0~3 bits
  111. * c_pad_len: 4~11 bits
  112. * c_pad_data_type: 12~15 bits
  113. */
  114. __le16 cph_pad;
  115. /* c_pad_len_field: 0~1 bits */
  116. __le16 c_pad_len_field;
  117. __le64 long_a_data_len;
  118. __le64 a_ivin_addr;
  119. __le64 a_key_addr;
  120. __le64 mac_addr;
  121. __le64 c_ivin_addr;
  122. __le64 c_key_addr;
  123. __le64 data_src_addr;
  124. __le64 data_dst_addr;
  125. /*
  126. * done: 0 bit
  127. * icv: 1~3 bits
  128. * csc: 4~6 bits
  129. * flag: 7-10 bits
  130. * dif_check: 11~13 bits
  131. */
  132. __le16 done_flag;
  133. __u8 error_type;
  134. __u8 warning_type;
  135. __u8 mac_i3;
  136. __u8 mac_i2;
  137. __u8 mac_i1;
  138. __u8 mac_i0;
  139. __le16 check_sum_i;
  140. __u8 tls_pad_len_i;
  141. __u8 rsvd12;
  142. __le32 counter;
  143. };
  144. struct sec_sqe {
  145. /*
  146. * type: 0~3 bits
  147. * cipher: 4~5 bits
  148. * auth: 6~7 bit s
  149. */
  150. __u8 type_cipher_auth;
  151. /*
  152. * seq: 0 bit
  153. * de: 1~2 bits
  154. * scene: 3~6 bits
  155. * src_addr_type: ~7 bit, with sdm_addr_type 0-1 bits
  156. */
  157. __u8 sds_sa_type;
  158. /*
  159. * src_addr_type: 0~1 bits, not used now,
  160. * if support PRP, set this field, or set zero.
  161. * dst_addr_type: 2~4 bits
  162. * mac_addr_type: 5~7 bits
  163. */
  164. __u8 sdm_addr_type;
  165. __u8 rsvd0;
  166. /*
  167. * nonce_len(type2): 0~3 bits
  168. * huk(type2): 4 bit
  169. * key_s(type2): 5 bit
  170. * ci_gen: 6~7 bits
  171. */
  172. __u8 huk_key_ci;
  173. /*
  174. * ai_gen: 0~1 bits
  175. * a_pad(type2): 2~3 bits
  176. * c_s(type2): 4~5 bits
  177. */
  178. __u8 ai_apd_cs;
  179. /*
  180. * rhf(type2): 0 bit
  181. * c_key_type: 1~2 bits
  182. * a_key_type: 3~4 bits
  183. * write_frame_len(type2): 5~7 bits
  184. */
  185. __u8 rca_key_frm;
  186. /*
  187. * cal_iv_addr_en(type2): 0 bit
  188. * tls_up(type2): 1 bit
  189. * inveld: 7 bit
  190. */
  191. __u8 iv_tls_ld;
  192. /* Just using type2 BD now */
  193. struct sec_sqe_type2 type2;
  194. };
  195. struct bd3_auth_ivin {
  196. __le64 a_ivin_addr;
  197. __le32 rsvd0;
  198. __le32 rsvd1;
  199. } __packed __aligned(4);
  200. struct bd3_skip_data {
  201. __le32 rsvd0;
  202. /*
  203. * gran_num: 0~15 bits
  204. * reserved: 16~31 bits
  205. */
  206. __le32 gran_num;
  207. /*
  208. * src_skip_data_len: 0~24 bits
  209. * reserved: 25~31 bits
  210. */
  211. __le32 src_skip_data_len;
  212. /*
  213. * dst_skip_data_len: 0~24 bits
  214. * reserved: 25~31 bits
  215. */
  216. __le32 dst_skip_data_len;
  217. };
  218. struct bd3_stream_scene {
  219. __le64 c_ivin_addr;
  220. __le64 long_a_data_len;
  221. /*
  222. * auth_pad: 0~1 bits
  223. * stream_protocol: 2~4 bits
  224. * reserved: 5~7 bits
  225. */
  226. __u8 stream_auth_pad;
  227. __u8 plaintext_type;
  228. __le16 pad_len_1p3;
  229. } __packed __aligned(4);
  230. struct bd3_no_scene {
  231. __le64 c_ivin_addr;
  232. __le32 rsvd0;
  233. __le32 rsvd1;
  234. __le32 rsvd2;
  235. } __packed __aligned(4);
  236. struct bd3_check_sum {
  237. __u8 rsvd0;
  238. __u8 hac_sva_status;
  239. __le16 check_sum_i;
  240. };
  241. struct bd3_tls_type_back {
  242. __u8 tls_1p3_type_back;
  243. __u8 hac_sva_status;
  244. __le16 pad_len_1p3_back;
  245. };
  246. struct sec_sqe3 {
  247. /*
  248. * type: 0~3 bit
  249. * bd_invalid: 4 bit
  250. * scene: 5~8 bit
  251. * de: 9~10 bit
  252. * src_addr_type: 11~13 bit
  253. * dst_addr_type: 14~16 bit
  254. * mac_addr_type: 17~19 bit
  255. * reserved: 20~31 bits
  256. */
  257. __le32 bd_param;
  258. /*
  259. * cipher: 0~1 bits
  260. * ci_gen: 2~3 bit
  261. * c_icv_len: 4~9 bit
  262. * c_width: 10~12 bits
  263. * c_key_len: 13~15 bits
  264. */
  265. __le16 c_icv_key;
  266. /*
  267. * c_mode : 0~3 bits
  268. * c_alg : 4~7 bits
  269. */
  270. __u8 c_mode_alg;
  271. /*
  272. * nonce_len : 0~3 bits
  273. * huk : 4 bits
  274. * cal_iv_addr_en : 5 bits
  275. * seq : 6 bits
  276. * reserved : 7 bits
  277. */
  278. __u8 huk_iv_seq;
  279. __le64 tag;
  280. __le64 data_src_addr;
  281. __le64 a_key_addr;
  282. union {
  283. struct bd3_auth_ivin auth_ivin;
  284. struct bd3_skip_data skip_data;
  285. };
  286. __le64 c_key_addr;
  287. /*
  288. * auth: 0~1 bits
  289. * ai_gen: 2~3 bits
  290. * mac_len: 4~8 bits
  291. * akey_len: 9~14 bits
  292. * a_alg: 15~20 bits
  293. * key_sel: 21~24 bits
  294. * ctr_count_mode/sm4_xts: 25~26 bits
  295. * sva_prefetch: 27 bits
  296. * key_wrap_num: 28~30 bits
  297. * update_key: 31 bits
  298. */
  299. __le32 auth_mac_key;
  300. __le32 salt;
  301. __le16 auth_src_offset;
  302. __le16 cipher_src_offset;
  303. /*
  304. * auth_len: 0~23 bit
  305. * auth_key_offset: 24~31 bits
  306. */
  307. __le32 a_len_key;
  308. /*
  309. * cipher_len: 0~23 bit
  310. * auth_ivin_offset: 24~31 bits
  311. */
  312. __le32 c_len_ivin;
  313. __le64 data_dst_addr;
  314. __le64 mac_addr;
  315. union {
  316. struct bd3_stream_scene stream_scene;
  317. struct bd3_no_scene no_scene;
  318. };
  319. /*
  320. * done: 0 bit
  321. * icv: 1~3 bit
  322. * csc: 4~6 bit
  323. * flag: 7~10 bit
  324. * reserved: 11~15 bit
  325. */
  326. __le16 done_flag;
  327. __u8 error_type;
  328. __u8 warning_type;
  329. union {
  330. __le32 mac_i;
  331. __le32 kek_key_addr_l;
  332. };
  333. union {
  334. __le32 kek_key_addr_h;
  335. struct bd3_check_sum check_sum;
  336. struct bd3_tls_type_back tls_type_back;
  337. };
  338. __le32 counter;
  339. } __packed __aligned(4);
  340. int sec_register_to_crypto(struct hisi_qm *qm);
  341. void sec_unregister_from_crypto(struct hisi_qm *qm);
  342. #endif