1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) 2019 HiSilicon Limited. */
4 #ifndef __HISI_SEC_V2_CRYPTO_H
5 #define __HISI_SEC_V2_CRYPTO_H
7 #define SEC_AIV_SIZE 12
9 #define SEC_MAX_KEY_SIZE 64
10 #define SEC_MAX_AKEY_SIZE 128
11 #define SEC_COMM_SCENE 0
12 #define SEC_MIN_BLOCK_SZ 1
21 SEC_A_HMAC_SHA1 = 0x10,
22 SEC_A_HMAC_SHA256 = 0x11,
23 SEC_A_HMAC_SHA512 = 0x15,
27 SEC_HMAC_CCM_MAC = 16,
28 SEC_HMAC_GCM_MAC = 16,
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,
49 SEC_CKEY_128BIT = 0x0,
50 SEC_CKEY_192BIT = 0x1,
51 SEC_CKEY_256BIT = 0x2,
52 SEC_CKEY_3DES_3KEY = 0x1,
53 SEC_CKEY_3DES_2KEY = 0x3,
97 struct sec_sqe_type2 {
100 * a_key_len: 5~10 bits
106 * c_icv_len: 0~5 bits
108 * c_key_len: 9~11 bits
113 /* c_alg: 0~3 bits */
119 * iv_offset_l: 24~31 bits
125 * iv_offset_h: 24~31 bits
129 __le16 auth_src_offset;
130 __le16 cipher_src_offset;
131 __le16 cs_ip_header_offset;
132 __le16 cs_udp_header_offset;
133 __le16 pass_word_len;
144 * c_pad_type: 0~3 bits
145 * c_pad_len: 4~11 bits
146 * c_pad_data_type: 12~15 bits
150 /* c_pad_len_field: 0~1 bits */
151 __le16 c_pad_len_field;
153 __le64 long_a_data_len;
160 __le64 data_src_addr;
161 __le64 data_dst_addr;
168 * dif_check: 11~13 bits
190 __u8 type_cipher_auth;
196 * src_addr_type: ~7 bit, with sdm_addr_type 0-1 bits
201 * src_addr_type: 0~1 bits, not used now,
202 * if support PRP, set this field, or set zero.
203 * dst_addr_type: 2~4 bits
204 * mac_addr_type: 5~7 bits
210 * nonce_len(type2): 0~3 bits
212 * key_s(type2): 5 bit
219 * a_pad(type2): 2~3 bits
220 * c_s(type2): 4~5 bits
226 * c_key_type: 1~2 bits
227 * a_key_type: 3~4 bits
228 * write_frame_len(type2): 5~7 bits
233 * cal_iv_addr_en(type2): 0 bit
234 * tls_up(type2): 1 bit
239 /* Just using type2 BD now */
240 struct sec_sqe_type2 type2;
243 struct bd3_auth_ivin {
247 } __packed __aligned(4);
249 struct bd3_skip_data {
253 * gran_num: 0~15 bits
254 * reserved: 16~31 bits
259 * src_skip_data_len: 0~24 bits
260 * reserved: 25~31 bits
262 __le32 src_skip_data_len;
265 * dst_skip_data_len: 0~24 bits
266 * reserved: 25~31 bits
268 __le32 dst_skip_data_len;
271 struct bd3_stream_scene {
273 __le64 long_a_data_len;
277 * stream_protocol: 2~4 bits
280 __u8 stream_auth_pad;
283 } __packed __aligned(4);
285 struct bd3_no_scene {
290 } __packed __aligned(4);
292 struct bd3_check_sum {
298 struct bd3_tls_type_back {
299 __u8 tls_1p3_type_back;
301 __le16 pad_len_1p3_back;
310 * src_addr_type: 11~13 bit
311 * dst_addr_type: 14~16 bit
312 * mac_addr_type: 17~19 bit
313 * reserved: 20~31 bits
321 * c_width: 10~12 bits
322 * c_key_len: 13~15 bits
333 * nonce_len : 0~3 bits
335 * cal_iv_addr_en : 5 bits
342 __le64 data_src_addr;
345 struct bd3_auth_ivin auth_ivin;
346 struct bd3_skip_data skip_data;
355 * akey_len: 9~14 bits
357 * key_sel: 21~24 bits
358 * ctr_count_mode/sm4_xts: 25~26 bits
359 * sva_prefetch: 27 bits
360 * key_wrap_num: 28~30 bits
361 * update_key: 31 bits
365 __le16 auth_src_offset;
366 __le16 cipher_src_offset;
370 * auth_key_offset: 24~31 bits
375 * cipher_len: 0~23 bit
376 * auth_ivin_offset: 24~31 bits
379 __le64 data_dst_addr;
382 struct bd3_stream_scene stream_scene;
383 struct bd3_no_scene no_scene;
391 * reserved: 11~15 bit
398 __le32 kek_key_addr_l;
401 __le32 kek_key_addr_h;
402 struct bd3_check_sum check_sum;
403 struct bd3_tls_type_back tls_type_back;
406 } __packed __aligned(4);
408 int sec_register_to_crypto(struct hisi_qm *qm);
409 void sec_unregister_from_crypto(struct hisi_qm *qm);