409 lines · c
1/* SPDX-License-Identifier: GPL-2.0 */2/* Copyright (c) 2019 HiSilicon Limited. */3 4#ifndef __HISI_SEC_V2_CRYPTO_H5#define __HISI_SEC_V2_CRYPTO_H6 7#define SEC_AIV_SIZE 128#define SEC_IV_SIZE 249#define SEC_MAX_KEY_SIZE 6410#define SEC_MAX_AKEY_SIZE 12811#define SEC_COMM_SCENE 012#define SEC_MIN_BLOCK_SZ 113 14enum sec_calg {15 SEC_CALG_3DES = 0x1,16 SEC_CALG_AES = 0x2,17 SEC_CALG_SM4 = 0x3,18};19 20enum sec_hash_alg {21 SEC_A_HMAC_SHA1 = 0x10,22 SEC_A_HMAC_SHA256 = 0x11,23 SEC_A_HMAC_SHA512 = 0x15,24};25 26enum sec_mac_len {27 SEC_HMAC_CCM_MAC = 16,28 SEC_HMAC_GCM_MAC = 16,29 SEC_SM3_MAC = 32,30 SEC_HMAC_SM3_MAC = 32,31 SEC_HMAC_MD5_MAC = 16,32 SEC_HMAC_SHA1_MAC = 20,33 SEC_HMAC_SHA256_MAC = 32,34 SEC_HMAC_SHA512_MAC = 64,35};36 37enum sec_cmode {38 SEC_CMODE_ECB = 0x0,39 SEC_CMODE_CBC = 0x1,40 SEC_CMODE_CTR = 0x4,41 SEC_CMODE_CCM = 0x5,42 SEC_CMODE_GCM = 0x6,43 SEC_CMODE_XTS = 0x7,44};45 46enum sec_ckey_type {47 SEC_CKEY_128BIT = 0x0,48 SEC_CKEY_192BIT = 0x1,49 SEC_CKEY_256BIT = 0x2,50 SEC_CKEY_3DES_3KEY = 0x1,51 SEC_CKEY_3DES_2KEY = 0x3,52};53 54enum sec_bd_type {55 SEC_BD_TYPE1 = 0x1,56 SEC_BD_TYPE2 = 0x2,57 SEC_BD_TYPE3 = 0x3,58};59 60enum sec_auth {61 SEC_NO_AUTH = 0x0,62 SEC_AUTH_TYPE1 = 0x1,63 SEC_AUTH_TYPE2 = 0x2,64};65 66enum sec_cipher_dir {67 SEC_CIPHER_ENC = 0x1,68 SEC_CIPHER_DEC = 0x2,69};70 71enum sec_addr_type {72 SEC_PBUF = 0x0,73 SEC_SGL = 0x1,74 SEC_PRP = 0x2,75};76 77struct bd_status {78 u64 tag;79 u8 done;80 u8 err_type;81 u16 flag;82 u16 icv;83};84 85enum {86 AUTHPAD_PAD,87 AUTHPAD_NOPAD,88};89 90enum {91 AIGEN_GEN,92 AIGEN_NOGEN,93};94 95struct sec_sqe_type2 {96 /*97 * mac_len: 0~4 bits98 * a_key_len: 5~10 bits99 * a_alg: 11~16 bits100 */101 __le32 mac_key_alg;102 103 /*104 * c_icv_len: 0~5 bits105 * c_width: 6~8 bits106 * c_key_len: 9~11 bits107 * c_mode: 12~15 bits108 */109 __le16 icvw_kmode;110 111 /* c_alg: 0~3 bits */112 __u8 c_alg;113 __u8 rsvd4;114 115 /*116 * a_len: 0~23 bits117 * iv_offset_l: 24~31 bits118 */119 __le32 alen_ivllen;120 121 /*122 * c_len: 0~23 bits123 * iv_offset_h: 24~31 bits124 */125 __le32 clen_ivhlen;126 127 __le16 auth_src_offset;128 __le16 cipher_src_offset;129 __le16 cs_ip_header_offset;130 __le16 cs_udp_header_offset;131 __le16 pass_word_len;132 __le16 dk_len;133 __u8 salt3;134 __u8 salt2;135 __u8 salt1;136 __u8 salt0;137 138 __le16 tag;139 __le16 rsvd5;140 141 /*142 * c_pad_type: 0~3 bits143 * c_pad_len: 4~11 bits144 * c_pad_data_type: 12~15 bits145 */146 __le16 cph_pad;147 148 /* c_pad_len_field: 0~1 bits */149 __le16 c_pad_len_field;150 151 __le64 long_a_data_len;152 __le64 a_ivin_addr;153 __le64 a_key_addr;154 __le64 mac_addr;155 __le64 c_ivin_addr;156 __le64 c_key_addr;157 158 __le64 data_src_addr;159 __le64 data_dst_addr;160 161 /*162 * done: 0 bit163 * icv: 1~3 bits164 * csc: 4~6 bits165 * flag: 7-10 bits166 * dif_check: 11~13 bits167 */168 __le16 done_flag;169 170 __u8 error_type;171 __u8 warning_type;172 __u8 mac_i3;173 __u8 mac_i2;174 __u8 mac_i1;175 __u8 mac_i0;176 __le16 check_sum_i;177 __u8 tls_pad_len_i;178 __u8 rsvd12;179 __le32 counter;180};181 182struct sec_sqe {183 /*184 * type: 0~3 bits185 * cipher: 4~5 bits186 * auth: 6~7 bit s187 */188 __u8 type_cipher_auth;189 190 /*191 * seq: 0 bit192 * de: 1~2 bits193 * scene: 3~6 bits194 * src_addr_type: ~7 bit, with sdm_addr_type 0-1 bits195 */196 __u8 sds_sa_type;197 198 /*199 * src_addr_type: 0~1 bits, not used now,200 * if support PRP, set this field, or set zero.201 * dst_addr_type: 2~4 bits202 * mac_addr_type: 5~7 bits203 */204 __u8 sdm_addr_type;205 __u8 rsvd0;206 207 /*208 * nonce_len(type2): 0~3 bits209 * huk(type2): 4 bit210 * key_s(type2): 5 bit211 * ci_gen: 6~7 bits212 */213 __u8 huk_key_ci;214 215 /*216 * ai_gen: 0~1 bits217 * a_pad(type2): 2~3 bits218 * c_s(type2): 4~5 bits219 */220 __u8 ai_apd_cs;221 222 /*223 * rhf(type2): 0 bit224 * c_key_type: 1~2 bits225 * a_key_type: 3~4 bits226 * write_frame_len(type2): 5~7 bits227 */228 __u8 rca_key_frm;229 230 /*231 * cal_iv_addr_en(type2): 0 bit232 * tls_up(type2): 1 bit233 * inveld: 7 bit234 */235 __u8 iv_tls_ld;236 237 /* Just using type2 BD now */238 struct sec_sqe_type2 type2;239};240 241struct bd3_auth_ivin {242 __le64 a_ivin_addr;243 __le32 rsvd0;244 __le32 rsvd1;245} __packed __aligned(4);246 247struct bd3_skip_data {248 __le32 rsvd0;249 250 /*251 * gran_num: 0~15 bits252 * reserved: 16~31 bits253 */254 __le32 gran_num;255 256 /*257 * src_skip_data_len: 0~24 bits258 * reserved: 25~31 bits259 */260 __le32 src_skip_data_len;261 262 /*263 * dst_skip_data_len: 0~24 bits264 * reserved: 25~31 bits265 */266 __le32 dst_skip_data_len;267};268 269struct bd3_stream_scene {270 __le64 c_ivin_addr;271 __le64 long_a_data_len;272 273 /*274 * auth_pad: 0~1 bits275 * stream_protocol: 2~4 bits276 * reserved: 5~7 bits277 */278 __u8 stream_auth_pad;279 __u8 plaintext_type;280 __le16 pad_len_1p3;281} __packed __aligned(4);282 283struct bd3_no_scene {284 __le64 c_ivin_addr;285 __le32 rsvd0;286 __le32 rsvd1;287 __le32 rsvd2;288} __packed __aligned(4);289 290struct bd3_check_sum {291 __u8 rsvd0;292 __u8 hac_sva_status;293 __le16 check_sum_i;294};295 296struct bd3_tls_type_back {297 __u8 tls_1p3_type_back;298 __u8 hac_sva_status;299 __le16 pad_len_1p3_back;300};301 302struct sec_sqe3 {303 /*304 * type: 0~3 bit305 * bd_invalid: 4 bit306 * scene: 5~8 bit307 * de: 9~10 bit308 * src_addr_type: 11~13 bit309 * dst_addr_type: 14~16 bit310 * mac_addr_type: 17~19 bit311 * reserved: 20~31 bits312 */313 __le32 bd_param;314 315 /*316 * cipher: 0~1 bits317 * ci_gen: 2~3 bit318 * c_icv_len: 4~9 bit319 * c_width: 10~12 bits320 * c_key_len: 13~15 bits321 */322 __le16 c_icv_key;323 324 /*325 * c_mode : 0~3 bits326 * c_alg : 4~7 bits327 */328 __u8 c_mode_alg;329 330 /*331 * nonce_len : 0~3 bits332 * huk : 4 bits333 * cal_iv_addr_en : 5 bits334 * seq : 6 bits335 * reserved : 7 bits336 */337 __u8 huk_iv_seq;338 339 __le64 tag;340 __le64 data_src_addr;341 __le64 a_key_addr;342 union {343 struct bd3_auth_ivin auth_ivin;344 struct bd3_skip_data skip_data;345 };346 347 __le64 c_key_addr;348 349 /*350 * auth: 0~1 bits351 * ai_gen: 2~3 bits352 * mac_len: 4~8 bits353 * akey_len: 9~14 bits354 * a_alg: 15~20 bits355 * key_sel: 21~24 bits356 * ctr_count_mode/sm4_xts: 25~26 bits357 * sva_prefetch: 27 bits358 * key_wrap_num: 28~30 bits359 * update_key: 31 bits360 */361 __le32 auth_mac_key;362 __le32 salt;363 __le16 auth_src_offset;364 __le16 cipher_src_offset;365 366 /*367 * auth_len: 0~23 bit368 * auth_key_offset: 24~31 bits369 */370 __le32 a_len_key;371 372 /*373 * cipher_len: 0~23 bit374 * auth_ivin_offset: 24~31 bits375 */376 __le32 c_len_ivin;377 __le64 data_dst_addr;378 __le64 mac_addr;379 union {380 struct bd3_stream_scene stream_scene;381 struct bd3_no_scene no_scene;382 };383 384 /*385 * done: 0 bit386 * icv: 1~3 bit387 * csc: 4~6 bit388 * flag: 7~10 bit389 * reserved: 11~15 bit390 */391 __le16 done_flag;392 __u8 error_type;393 __u8 warning_type;394 union {395 __le32 mac_i;396 __le32 kek_key_addr_l;397 };398 union {399 __le32 kek_key_addr_h;400 struct bd3_check_sum check_sum;401 struct bd3_tls_type_back tls_type_back;402 };403 __le32 counter;404} __packed __aligned(4);405 406int sec_register_to_crypto(struct hisi_qm *qm);407void sec_unregister_from_crypto(struct hisi_qm *qm);408#endif409