123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
#ifndef __HISI_SEC_V2_CRYPTO_H
#define __HISI_SEC_V2_CRYPTO_H
#define SEC_AIV_SIZE 12
#define SEC_IV_SIZE 24
#define SEC_MAX_KEY_SIZE 64
#define SEC_MAX_AKEY_SIZE 128
#define SEC_COMM_SCENE 0
#define SEC_MIN_BLOCK_SZ 1
enum sec_calg {
SEC_CALG_3DES = 0x1,
SEC_CALG_AES = 0x2,
SEC_CALG_SM4 = 0x3,
};
enum sec_hash_alg {
SEC_A_HMAC_SHA1 = 0x10,
SEC_A_HMAC_SHA256 = 0x11,
SEC_A_HMAC_SHA512 = 0x15,
};
enum sec_cmode {
SEC_CMODE_ECB = 0x0,
SEC_CMODE_CBC = 0x1,
SEC_CMODE_CTR = 0x4,
SEC_CMODE_CCM = 0x5,
SEC_CMODE_GCM = 0x6,
SEC_CMODE_XTS = 0x7,
};
enum sec_ckey_type {
SEC_CKEY_128BIT = 0x0,
SEC_CKEY_192BIT = 0x1,
SEC_CKEY_256BIT = 0x2,
SEC_CKEY_3DES_3KEY = 0x1,
SEC_CKEY_3DES_2KEY = 0x3,
};
enum sec_bd_type {
SEC_BD_TYPE1 = 0x1,
SEC_BD_TYPE2 = 0x2,
SEC_BD_TYPE3 = 0x3,
};
enum sec_auth {
SEC_NO_AUTH = 0x0,
SEC_AUTH_TYPE1 = 0x1,
SEC_AUTH_TYPE2 = 0x2,
};
enum sec_cipher_dir {
SEC_CIPHER_ENC = 0x1,
SEC_CIPHER_DEC = 0x2,
};
enum sec_addr_type {
SEC_PBUF = 0x0,
SEC_SGL = 0x1,
SEC_PRP = 0x2,
};
struct bd_status {
u64 tag;
u8 done;
u8 err_type;
u16 flag;
u16 icv;
};
enum {
AUTHPAD_PAD,
AUTHPAD_NOPAD,
};
enum {
AIGEN_GEN,
AIGEN_NOGEN,
};
struct sec_sqe_type2 {
__le32 mac_key_alg;
__le16 icvw_kmode;
__u8 c_alg;
__u8 rsvd4;
__le32 alen_ivllen;
__le32 clen_ivhlen;
__le16 auth_src_offset;
__le16 cipher_src_offset;
__le16 cs_ip_header_offset;
__le16 cs_udp_header_offset;
__le16 pass_word_len;
__le16 dk_len;
__u8 salt3;
__u8 salt2;
__u8 salt1;
__u8 salt0;
__le16 tag;
__le16 rsvd5;
__le16 cph_pad;
__le16 c_pad_len_field;
__le64 long_a_data_len;
__le64 a_ivin_addr;
__le64 a_key_addr;
__le64 mac_addr;
__le64 c_ivin_addr;
__le64 c_key_addr;
__le64 data_src_addr;
__le64 data_dst_addr;
__le16 done_flag;
__u8 error_type;
__u8 warning_type;
__u8 mac_i3;
__u8 mac_i2;
__u8 mac_i1;
__u8 mac_i0;
__le16 check_sum_i;
__u8 tls_pad_len_i;
__u8 rsvd12;
__le32 counter;
};
struct sec_sqe {
__u8 type_cipher_auth;
__u8 sds_sa_type;
__u8 sdm_addr_type;
__u8 rsvd0;
__u8 huk_key_ci;
__u8 ai_apd_cs;
__u8 rca_key_frm;
__u8 iv_tls_ld;
struct sec_sqe_type2 type2;
};
struct bd3_auth_ivin {
__le64 a_ivin_addr;
__le32 rsvd0;
__le32 rsvd1;
} __packed __aligned(4);
struct bd3_skip_data {
__le32 rsvd0;
__le32 gran_num;
__le32 src_skip_data_len;
__le32 dst_skip_data_len;
};
struct bd3_stream_scene {
__le64 c_ivin_addr;
__le64 long_a_data_len;
__u8 stream_auth_pad;
__u8 plaintext_type;
__le16 pad_len_1p3;
} __packed __aligned(4);
struct bd3_no_scene {
__le64 c_ivin_addr;
__le32 rsvd0;
__le32 rsvd1;
__le32 rsvd2;
} __packed __aligned(4);
struct bd3_check_sum {
__u8 rsvd0;
__u8 hac_sva_status;
__le16 check_sum_i;
};
struct bd3_tls_type_back {
__u8 tls_1p3_type_back;
__u8 hac_sva_status;
__le16 pad_len_1p3_back;
};
struct sec_sqe3 {
__le32 bd_param;
__le16 c_icv_key;
__u8 c_mode_alg;
__u8 huk_iv_seq;
__le64 tag;
__le64 data_src_addr;
__le64 a_key_addr;
union {
struct bd3_auth_ivin auth_ivin;
struct bd3_skip_data skip_data;
};
__le64 c_key_addr;
__le32 auth_mac_key;
__le32 salt;
__le16 auth_src_offset;
__le16 cipher_src_offset;
__le32 a_len_key;
__le32 c_len_ivin;
__le64 data_dst_addr;
__le64 mac_addr;
union {
struct bd3_stream_scene stream_scene;
struct bd3_no_scene no_scene;
};
__le16 done_flag;
__u8 error_type;
__u8 warning_type;
union {
__le32 mac_i;
__le32 kek_key_addr_l;
};
union {
__le32 kek_key_addr_h;
struct bd3_check_sum check_sum;
struct bd3_tls_type_back tls_type_back;
};
__le32 counter;
} __packed __aligned(4);
int sec_register_to_crypto(struct hisi_qm *qm);
void sec_unregister_from_crypto(struct hisi_qm *qm);
#endif