sec_crypto.h 6.5 KB

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