From f12f7836b240c868031c5e6a0b9cff377dc3c966 Mon Sep 17 00:00:00 2001 From: Gonglei Date: Fri, 20 Jan 2017 16:22:54 +0800 Subject: [PATCH] virtio-crypto: update header file Update the header based on the newset virtio crypto spec, so that the virtio crypto can support both session and non-session based crypto services and keep compatibility with the pre-existing code. Signed-off-by: Gonglei --- include/uapi/linux/virtio_crypto.h | 196 ++++++++++++++++++++++++++++++++++++- 1 file changed, 194 insertions(+), 2 deletions(-) diff --git a/include/uapi/linux/virtio_crypto.h b/include/uapi/linux/virtio_crypto.h index 50cdc8a..f30389c 100644 --- a/include/uapi/linux/virtio_crypto.h +++ b/include/uapi/linux/virtio_crypto.h @@ -166,8 +166,8 @@ struct virtio_crypto_aead_session_para { __le32 algo; /* length of key */ __le32 key_len; - /* hash result length */ - __le32 hash_result_len; + /* Authentication tag length */ + __virtio32 tag_len; /* length of the additional authenticated data (AAD) in bytes */ __le32 aad_len; /* encrypt or decrypt, See above VIRTIO_CRYPTO_OP_* */ @@ -271,6 +271,8 @@ struct virtio_crypto_op_header { __le32 algo; /* session_id should be service-specific algorithms */ __le64 session_id; +#define VIRTIO_CRYPTO_FLAG_SESSION_MODE 1 +#define VIRTIO_CRYPTO_FLAG_NON_SESSION_MODE 2 /* control flag to control the request */ __le32 flag; __le32 padding; @@ -403,6 +405,196 @@ struct virtio_crypto_op_data_req { } u; }; +struct virtio_crypto_cipher_para_non_sess { + struct { + /* See VIRTIO_CRYPTO_CIPHER* above */ + __virtio32 algo; + /* length of key */ + __virtio32 keylen; + + /* See VIRTIO_CRYPTO_OP_* above */ + __virtio32 op; + } sess_para; + + /* + * Byte Length of valid IV/Counter + */ + __virtio32 iv_len; + /* length of source data */ + __virtio32 src_data_len; + /* length of dst data */ + __virtio32 dst_data_len; +}; + +struct virtio_crypto_alg_chain_data_para_non_sess { + struct { + /* See VIRTIO_CRYPTO_SYM_ALG_CHAIN_ORDER_* above */ + __virtio32 alg_chain_order; + /* length of the additional authenticated data in bytes */ + __virtio32 aad_len; + + struct { + /* See VIRTIO_CRYPTO_CIPHER* above */ + __virtio32 algo; + /* length of key */ + __virtio32 keylen; + /* See VIRTIO_CRYPTO_OP_* above */ + __virtio32 op; + } cipher; + + struct { + /* See VIRTIO_CRYPTO_HASH_* or _MAC_* above */ + __virtio32 algo; + /* length of authenticated key */ + __virtio32 auth_key_len; + /* See VIRTIO_CRYPTO_SYM_HASH_MODE_* above */ + __virtio32 hash_mode; + } hash; + } sess_para; + + __virtio32 iv_len; + /* Length of source data */ + __virtio32 src_data_len; + /* Length of destination data */ + __virtio32 dst_data_len; + /* Starting point for cipher processing in source data */ + __virtio32 cipher_start_src_offset; + /* Length of the source data that the cipher will be computed on */ + __virtio32 len_to_cipher; + /* Starting point for hash processing in source data */ + __virtio32 hash_start_src_offset; + /* Length of the source data that the hash will be computed on */ + __virtio32 len_to_hash; + /* Length of the additional auth data */ + __virtio32 aad_len; + /* Length of the hash result */ + __virtio32 hash_result_len; + __virtio32 reserved; +}; + +struct virtio_crypto_hash_para_non_sess { + struct { + /* See VIRTIO_CRYPTO_HASH_* above */ + __virtio32 algo; + } sess_para; + + /* length of source data */ + __virtio32 src_data_len; + /* hash result length */ + __virtio32 hash_result_len; + __virtio32 reserved; +}; + +struct virtio_crypto_mac_para_non_sess { + struct { + /* See VIRTIO_CRYPTO_MAC_* above */ + __virtio32 algo; + /* length of authenticated key */ + __virtio32 auth_key_len; + } sess_para; + + /* length of source data */ + __virtio32 src_data_len; + /* hash result length */ + __virtio32 hash_result_len; +}; + +struct virtio_crypto_aead_para_non_sess { + struct { + /* See VIRTIO_CRYPTO_AEAD_* above */ + __virtio32 algo; + /* length of key */ + __virtio32 key_len; + /* encrypt or decrypt, See above VIRTIO_CRYPTO_OP_* */ + __virtio32 op; + } sess_para; + + /* + * Byte Length of valid IV data pointed to by the below iv_addr + * parameter. + */ + __virtio32 iv_len; + /* Authentication tag length */ + __virtio32 tag_len; + /* length of the additional authenticated data (AAD) in bytes */ + __virtio32 aad_len; + /* length of source data */ + __virtio32 src_data_len; + /* length of dst data, it should be at least src_data_len + tag_len */ + __virtio32 dst_data_len; +}; + +struct virtio_crypto_cipher_data_req_non_sess { + /* Device-readable part */ + struct virtio_crypto_cipher_para_non_sess para; + __u8 padding[48]; +}; + +struct virtio_crypto_hash_data_req_non_sess { + /* Device-readable part */ + struct virtio_crypto_hash_para_non_sess para; + __u8 padding[64]; +}; + +struct virtio_crypto_mac_data_req_non_sess { + /* Device-readable part */ + struct virtio_crypto_mac_para_non_sess para; + __u8 padding[64]; +}; + +struct virtio_crypto_alg_chain_data_req_non_sess { + /* Device-readable part */ + struct virtio_crypto_alg_chain_data_para_non_sess para; +}; + +struct virtio_crypto_sym_data_req_non_sess { + union { + struct virtio_crypto_cipher_data_req_non_sess cipher; + struct virtio_crypto_alg_chain_data_req_non_sess chain; + __u8 padding[72]; + } u; + + /* See above VIRTIO_CRYPTO_SYM_OP_* */ + __le32 op_type; + __le32 padding; +}; + +struct virtio_crypto_aead_data_req_non_sess { + /* Device-readable part */ + struct virtio_crypto_aead_para_non_sess para; + __u8 padding[48]; +}; + +/* The request of the data virtqueue's packet */ +struct virtio_crypto_op_data_req_mux { + struct virtio_crypto_op_header header; + + union { + struct { + struct virtio_crypto_sym_data_req data; + __u8 padding[32]; + } sym_req; + struct { + struct virtio_crypto_hash_data_req data; + __u8 padding[32]; + } hash_req; + struct { + struct virtio_crypto_mac_data_req data; + __u8 padding[32]; + } mac_req; + struct { + struct virtio_crypto_aead_data_req data; + __u8 padding[32]; + } aead_req; + + struct virtio_crypto_sym_data_req_non_sess sym_non_sess_req; + struct virtio_crypto_hash_data_req_non_sess hash_non_sess_req; + struct virtio_crypto_mac_data_req_non_sess mac_non_sess_req; + struct virtio_crypto_aead_data_req_non_sess aead_non_sess_req; + __u8 padding[80]; + } u; +}; + #define VIRTIO_CRYPTO_OK 0 #define VIRTIO_CRYPTO_ERR 1 #define VIRTIO_CRYPTO_BADMSG 2 -- 1.8.3.1