PageRenderTime 26ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/crypto/hisilicon/sec2/sec_crypto.h

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