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,
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,
95 struct sec_sqe_type2
{
98 * a_key_len: 5~10 bits
104 * c_icv_len: 0~5 bits
106 * c_key_len: 9~11 bits
111 /* c_alg: 0~3 bits */
117 * iv_offset_l: 24~31 bits
123 * iv_offset_h: 24~31 bits
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
;
142 * c_pad_type: 0~3 bits
143 * c_pad_len: 4~11 bits
144 * c_pad_data_type: 12~15 bits
148 /* c_pad_len_field: 0~1 bits */
149 __le16 c_pad_len_field
;
151 __le64 long_a_data_len
;
158 __le64 data_src_addr
;
159 __le64 data_dst_addr
;
166 * dif_check: 11~13 bits
188 __u8 type_cipher_auth
;
194 * src_addr_type: ~7 bit, with sdm_addr_type 0-1 bits
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 bits
202 * mac_addr_type: 5~7 bits
208 * nonce_len(type2): 0~3 bits
210 * key_s(type2): 5 bit
217 * a_pad(type2): 2~3 bits
218 * c_s(type2): 4~5 bits
224 * c_key_type: 1~2 bits
225 * a_key_type: 3~4 bits
226 * write_frame_len(type2): 5~7 bits
231 * cal_iv_addr_en(type2): 0 bit
232 * tls_up(type2): 1 bit
237 /* Just using type2 BD now */
238 struct sec_sqe_type2 type2
;
241 struct bd3_auth_ivin
{
245 } __packed
__aligned(4);
247 struct bd3_skip_data
{
251 * gran_num: 0~15 bits
252 * reserved: 16~31 bits
257 * src_skip_data_len: 0~24 bits
258 * reserved: 25~31 bits
260 __le32 src_skip_data_len
;
263 * dst_skip_data_len: 0~24 bits
264 * reserved: 25~31 bits
266 __le32 dst_skip_data_len
;
269 struct bd3_stream_scene
{
271 __le64 long_a_data_len
;
275 * stream_protocol: 2~4 bits
278 __u8 stream_auth_pad
;
281 } __packed
__aligned(4);
283 struct bd3_no_scene
{
288 } __packed
__aligned(4);
290 struct bd3_check_sum
{
296 struct bd3_tls_type_back
{
297 __u8 tls_1p3_type_back
;
299 __le16 pad_len_1p3_back
;
308 * src_addr_type: 11~13 bit
309 * dst_addr_type: 14~16 bit
310 * mac_addr_type: 17~19 bit
311 * reserved: 20~31 bits
319 * c_width: 10~12 bits
320 * c_key_len: 13~15 bits
331 * nonce_len : 0~3 bits
333 * cal_iv_addr_en : 5 bits
340 __le64 data_src_addr
;
343 struct bd3_auth_ivin auth_ivin
;
344 struct bd3_skip_data skip_data
;
353 * akey_len: 9~14 bits
355 * key_sel: 21~24 bits
356 * ctr_count_mode/sm4_xts: 25~26 bits
357 * sva_prefetch: 27 bits
358 * key_wrap_num: 28~30 bits
359 * update_key: 31 bits
363 __le16 auth_src_offset
;
364 __le16 cipher_src_offset
;
368 * auth_key_offset: 24~31 bits
373 * cipher_len: 0~23 bit
374 * auth_ivin_offset: 24~31 bits
377 __le64 data_dst_addr
;
380 struct bd3_stream_scene stream_scene
;
381 struct bd3_no_scene no_scene
;
389 * reserved: 11~15 bit
396 __le32 kek_key_addr_l
;
399 __le32 kek_key_addr_h
;
400 struct bd3_check_sum check_sum
;
401 struct bd3_tls_type_back tls_type_back
;
404 } __packed
__aligned(4);
406 int sec_register_to_crypto(struct hisi_qm
*qm
);
407 void sec_unregister_from_crypto(struct hisi_qm
*qm
);