Path: blob/master/drivers/crypto/hisilicon/sec2/sec_crypto.h
26289 views
/* SPDX-License-Identifier: GPL-2.0 */1/* Copyright (c) 2019 HiSilicon Limited. */23#ifndef __HISI_SEC_V2_CRYPTO_H4#define __HISI_SEC_V2_CRYPTO_H56#define SEC_AIV_SIZE 127#define SEC_IV_SIZE 248#define SEC_MAX_KEY_SIZE 649#define SEC_MAX_AKEY_SIZE 12810#define SEC_COMM_SCENE 011#define SEC_MIN_BLOCK_SZ 11213enum sec_calg {14SEC_CALG_3DES = 0x1,15SEC_CALG_AES = 0x2,16SEC_CALG_SM4 = 0x3,17};1819enum sec_hash_alg {20SEC_A_HMAC_SHA1 = 0x10,21SEC_A_HMAC_SHA256 = 0x11,22SEC_A_HMAC_SHA512 = 0x15,23};2425enum sec_cmode {26SEC_CMODE_ECB = 0x0,27SEC_CMODE_CBC = 0x1,28SEC_CMODE_CTR = 0x4,29SEC_CMODE_CCM = 0x5,30SEC_CMODE_GCM = 0x6,31SEC_CMODE_XTS = 0x7,32};3334enum sec_ckey_type {35SEC_CKEY_128BIT = 0x0,36SEC_CKEY_192BIT = 0x1,37SEC_CKEY_256BIT = 0x2,38SEC_CKEY_3DES_3KEY = 0x1,39SEC_CKEY_3DES_2KEY = 0x3,40};4142enum sec_bd_type {43SEC_BD_TYPE1 = 0x1,44SEC_BD_TYPE2 = 0x2,45SEC_BD_TYPE3 = 0x3,46};4748enum sec_auth {49SEC_NO_AUTH = 0x0,50SEC_AUTH_TYPE1 = 0x1,51SEC_AUTH_TYPE2 = 0x2,52};5354enum sec_cipher_dir {55SEC_CIPHER_ENC = 0x1,56SEC_CIPHER_DEC = 0x2,57};5859enum sec_addr_type {60SEC_PBUF = 0x0,61SEC_SGL = 0x1,62SEC_PRP = 0x2,63};6465struct bd_status {66u64 tag;67u8 done;68u8 err_type;69u16 flag;70u16 icv;71};7273enum {74AUTHPAD_PAD,75AUTHPAD_NOPAD,76};7778enum {79AIGEN_GEN,80AIGEN_NOGEN,81};8283struct sec_sqe_type2 {84/*85* mac_len: 0~4 bits86* a_key_len: 5~10 bits87* a_alg: 11~16 bits88*/89__le32 mac_key_alg;9091/*92* c_icv_len: 0~5 bits93* c_width: 6~8 bits94* c_key_len: 9~11 bits95* c_mode: 12~15 bits96*/97__le16 icvw_kmode;9899/* c_alg: 0~3 bits */100__u8 c_alg;101__u8 rsvd4;102103/*104* a_len: 0~23 bits105* iv_offset_l: 24~31 bits106*/107__le32 alen_ivllen;108109/*110* c_len: 0~23 bits111* iv_offset_h: 24~31 bits112*/113__le32 clen_ivhlen;114115__le16 auth_src_offset;116__le16 cipher_src_offset;117__le16 cs_ip_header_offset;118__le16 cs_udp_header_offset;119__le16 pass_word_len;120__le16 dk_len;121__u8 salt3;122__u8 salt2;123__u8 salt1;124__u8 salt0;125126__le16 tag;127__le16 rsvd5;128129/*130* c_pad_type: 0~3 bits131* c_pad_len: 4~11 bits132* c_pad_data_type: 12~15 bits133*/134__le16 cph_pad;135136/* c_pad_len_field: 0~1 bits */137__le16 c_pad_len_field;138139__le64 long_a_data_len;140__le64 a_ivin_addr;141__le64 a_key_addr;142__le64 mac_addr;143__le64 c_ivin_addr;144__le64 c_key_addr;145146__le64 data_src_addr;147__le64 data_dst_addr;148149/*150* done: 0 bit151* icv: 1~3 bits152* csc: 4~6 bits153* flag: 7-10 bits154* dif_check: 11~13 bits155*/156__le16 done_flag;157158__u8 error_type;159__u8 warning_type;160__u8 mac_i3;161__u8 mac_i2;162__u8 mac_i1;163__u8 mac_i0;164__le16 check_sum_i;165__u8 tls_pad_len_i;166__u8 rsvd12;167__le32 counter;168};169170struct sec_sqe {171/*172* type: 0~3 bits173* cipher: 4~5 bits174* auth: 6~7 bit s175*/176__u8 type_cipher_auth;177178/*179* seq: 0 bit180* de: 1~2 bits181* scene: 3~6 bits182* src_addr_type: ~7 bit, with sdm_addr_type 0-1 bits183*/184__u8 sds_sa_type;185186/*187* src_addr_type: 0~1 bits, not used now,188* if support PRP, set this field, or set zero.189* dst_addr_type: 2~4 bits190* mac_addr_type: 5~7 bits191*/192__u8 sdm_addr_type;193__u8 rsvd0;194195/*196* nonce_len(type2): 0~3 bits197* huk(type2): 4 bit198* key_s(type2): 5 bit199* ci_gen: 6~7 bits200*/201__u8 huk_key_ci;202203/*204* ai_gen: 0~1 bits205* a_pad(type2): 2~3 bits206* c_s(type2): 4~5 bits207*/208__u8 ai_apd_cs;209210/*211* rhf(type2): 0 bit212* c_key_type: 1~2 bits213* a_key_type: 3~4 bits214* write_frame_len(type2): 5~7 bits215*/216__u8 rca_key_frm;217218/*219* cal_iv_addr_en(type2): 0 bit220* tls_up(type2): 1 bit221* inveld: 7 bit222*/223__u8 iv_tls_ld;224225/* Just using type2 BD now */226struct sec_sqe_type2 type2;227};228229struct bd3_auth_ivin {230__le64 a_ivin_addr;231__le32 rsvd0;232__le32 rsvd1;233} __packed __aligned(4);234235struct bd3_skip_data {236__le32 rsvd0;237238/*239* gran_num: 0~15 bits240* reserved: 16~31 bits241*/242__le32 gran_num;243244/*245* src_skip_data_len: 0~24 bits246* reserved: 25~31 bits247*/248__le32 src_skip_data_len;249250/*251* dst_skip_data_len: 0~24 bits252* reserved: 25~31 bits253*/254__le32 dst_skip_data_len;255};256257struct bd3_stream_scene {258__le64 c_ivin_addr;259__le64 long_a_data_len;260261/*262* auth_pad: 0~1 bits263* stream_protocol: 2~4 bits264* reserved: 5~7 bits265*/266__u8 stream_auth_pad;267__u8 plaintext_type;268__le16 pad_len_1p3;269} __packed __aligned(4);270271struct bd3_no_scene {272__le64 c_ivin_addr;273__le32 rsvd0;274__le32 rsvd1;275__le32 rsvd2;276} __packed __aligned(4);277278struct bd3_check_sum {279__u8 rsvd0;280__u8 hac_sva_status;281__le16 check_sum_i;282};283284struct bd3_tls_type_back {285__u8 tls_1p3_type_back;286__u8 hac_sva_status;287__le16 pad_len_1p3_back;288};289290struct sec_sqe3 {291/*292* type: 0~3 bit293* bd_invalid: 4 bit294* scene: 5~8 bit295* de: 9~10 bit296* src_addr_type: 11~13 bit297* dst_addr_type: 14~16 bit298* mac_addr_type: 17~19 bit299* reserved: 20~31 bits300*/301__le32 bd_param;302303/*304* cipher: 0~1 bits305* ci_gen: 2~3 bit306* c_icv_len: 4~9 bit307* c_width: 10~12 bits308* c_key_len: 13~15 bits309*/310__le16 c_icv_key;311312/*313* c_mode : 0~3 bits314* c_alg : 4~7 bits315*/316__u8 c_mode_alg;317318/*319* nonce_len : 0~3 bits320* huk : 4 bits321* cal_iv_addr_en : 5 bits322* seq : 6 bits323* reserved : 7 bits324*/325__u8 huk_iv_seq;326327__le64 tag;328__le64 data_src_addr;329__le64 a_key_addr;330union {331struct bd3_auth_ivin auth_ivin;332struct bd3_skip_data skip_data;333};334335__le64 c_key_addr;336337/*338* auth: 0~1 bits339* ai_gen: 2~3 bits340* mac_len: 4~8 bits341* akey_len: 9~14 bits342* a_alg: 15~20 bits343* key_sel: 21~24 bits344* ctr_count_mode/sm4_xts: 25~26 bits345* sva_prefetch: 27 bits346* key_wrap_num: 28~30 bits347* update_key: 31 bits348*/349__le32 auth_mac_key;350__le32 salt;351__le16 auth_src_offset;352__le16 cipher_src_offset;353354/*355* auth_len: 0~23 bit356* auth_key_offset: 24~31 bits357*/358__le32 a_len_key;359360/*361* cipher_len: 0~23 bit362* auth_ivin_offset: 24~31 bits363*/364__le32 c_len_ivin;365__le64 data_dst_addr;366__le64 mac_addr;367union {368struct bd3_stream_scene stream_scene;369struct bd3_no_scene no_scene;370};371372/*373* done: 0 bit374* icv: 1~3 bit375* csc: 4~6 bit376* flag: 7~10 bit377* reserved: 11~15 bit378*/379__le16 done_flag;380__u8 error_type;381__u8 warning_type;382union {383__le32 mac_i;384__le32 kek_key_addr_l;385};386union {387__le32 kek_key_addr_h;388struct bd3_check_sum check_sum;389struct bd3_tls_type_back tls_type_back;390};391__le32 counter;392} __packed __aligned(4);393394int sec_register_to_crypto(struct hisi_qm *qm);395void sec_unregister_from_crypto(struct hisi_qm *qm);396#endif397398399