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,
36 SEC_CKEY_128BIT
= 0x0,
37 SEC_CKEY_192BIT
= 0x1,
38 SEC_CKEY_256BIT
= 0x2,
39 SEC_CKEY_3DES_3KEY
= 0x1,
40 SEC_CKEY_3DES_2KEY
= 0x3,
84 struct sec_sqe_type2
{
87 * a_key_len: 5~10 bits
95 * c_key_len: 9~11 bits
100 /* c_alg: 0~3 bits */
106 * iv_offset_l: 24~31 bits
112 * iv_offset_h: 24~31 bits
116 __le16 auth_src_offset
;
117 __le16 cipher_src_offset
;
118 __le16 cs_ip_header_offset
;
119 __le16 cs_udp_header_offset
;
120 __le16 pass_word_len
;
131 * c_pad_type: 0~3 bits
132 * c_pad_len: 4~11 bits
133 * c_pad_data_type: 12~15 bits
137 /* c_pad_len_field: 0~1 bits */
138 __le16 c_pad_len_field
;
140 __le64 long_a_data_len
;
147 __le64 data_src_addr
;
148 __le64 data_dst_addr
;
155 * dif_check: 11~13 bits
177 __u8 type_cipher_auth
;
183 * src_addr_type: ~7 bit, with sdm_addr_type 0-1 bits
188 * src_addr_type: 0~1 bits, not used now,
189 * if support PRP, set this field, or set zero.
190 * dst_addr_type: 2~4 bits
191 * mac_addr_type: 5~7 bits
197 * nonce_len(type2): 0~3 bits
199 * key_s(type2): 5 bit
206 * a_pad(type2): 2~3 bits
207 * c_s(type2): 4~5 bits
213 * c_key_type: 1~2 bits
214 * a_key_type: 3~4 bits
215 * write_frame_len(type2): 5~7 bits
220 * cal_iv_addr_en(type2): 0 bit
221 * tls_up(type2): 1 bit
226 /* Just using type2 BD now */
227 struct sec_sqe_type2 type2
;
230 struct bd3_auth_ivin
{
234 } __packed
__aligned(4);
236 struct bd3_skip_data
{
240 * gran_num: 0~15 bits
241 * reserved: 16~31 bits
246 * src_skip_data_len: 0~24 bits
247 * reserved: 25~31 bits
249 __le32 src_skip_data_len
;
252 * dst_skip_data_len: 0~24 bits
253 * reserved: 25~31 bits
255 __le32 dst_skip_data_len
;
258 struct bd3_stream_scene
{
260 __le64 long_a_data_len
;
264 * stream_protocol: 2~4 bits
267 __u8 stream_auth_pad
;
270 } __packed
__aligned(4);
272 struct bd3_no_scene
{
277 } __packed
__aligned(4);
279 struct bd3_check_sum
{
285 struct bd3_tls_type_back
{
286 __u8 tls_1p3_type_back
;
288 __le16 pad_len_1p3_back
;
297 * src_addr_type: 11~13 bit
298 * dst_addr_type: 14~16 bit
299 * mac_addr_type: 17~19 bit
300 * reserved: 20~31 bits
308 * c_width: 10~12 bits
309 * c_key_len: 13~15 bits
320 * nonce_len : 0~3 bits
322 * cal_iv_addr_en : 5 bits
329 __le64 data_src_addr
;
332 struct bd3_auth_ivin auth_ivin
;
333 struct bd3_skip_data skip_data
;
342 * akey_len: 9~14 bits
344 * key_sel: 21~24 bits
345 * ctr_count_mode/sm4_xts: 25~26 bits
346 * sva_prefetch: 27 bits
347 * key_wrap_num: 28~30 bits
348 * update_key: 31 bits
352 __le16 auth_src_offset
;
353 __le16 cipher_src_offset
;
357 * auth_key_offset: 24~31 bits
362 * cipher_len: 0~23 bit
363 * auth_ivin_offset: 24~31 bits
366 __le64 data_dst_addr
;
369 struct bd3_stream_scene stream_scene
;
370 struct bd3_no_scene no_scene
;
378 * reserved: 11~15 bit
385 __le32 kek_key_addr_l
;
388 __le32 kek_key_addr_h
;
389 struct bd3_check_sum check_sum
;
390 struct bd3_tls_type_back tls_type_back
;
393 } __packed
__aligned(4);
395 int sec_register_to_crypto(struct hisi_qm
*qm
);
396 void sec_unregister_from_crypto(struct hisi_qm
*qm
);