From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41045) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bs70j-0007tQ-Bi for qemu-devel@nongnu.org; Thu, 06 Oct 2016 07:38:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bs70g-0000xg-4n for qemu-devel@nongnu.org; Thu, 06 Oct 2016 07:38:49 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:20833) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bs70E-0000pg-MV for qemu-devel@nongnu.org; Thu, 06 Oct 2016 07:38:46 -0400 From: Gonglei Date: Thu, 6 Oct 2016 19:36:35 +0800 Message-ID: <1475753807-37624-3-git-send-email-arei.gonglei@huawei.com> In-Reply-To: <1475753807-37624-1-git-send-email-arei.gonglei@huawei.com> References: <1475753807-37624-1-git-send-email-arei.gonglei@huawei.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH v5 02/14] cryptodev: add symmetric algorithm operation stuff List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, virtio-dev@lists.oasis-open.org Cc: luonengjun@huawei.com, mst@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, berrange@redhat.com, weidong.huang@huawei.com, wu.wubin@huawei.com, mike.caraman@nxp.com, agraf@suse.de, xin.zeng@intel.com, claudio.fontana@huawei.com, nmorey@kalray.eu, vincent.jardin@6wind.com, jianjay.zhou@huawei.com, hanweidong@huawei.com, peter.huangpeng@huawei.com, arei.gonglei@hotmail.com, Gonglei This patch adds session operation and crypto operation stuff in the cryptodev backend, including function pointers and corresponding structures. Signed-off-by: Gonglei --- backends/cryptodev.c | 45 +++++++++++++++ include/sysemu/cryptodev.h | 138 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 183 insertions(+) diff --git a/backends/cryptodev.c b/backends/cryptodev.c index 20ab456..e4c066a 100644 --- a/backends/cryptodev.c +++ b/backends/cryptodev.c @@ -75,6 +75,51 @@ void qcrypto_cryptodev_backend_cleanup( backend->ready = false; } +int64_t qcrypto_cryptodev_backend_sym_create_session( + QCryptoCryptoDevBackend *backend, + QCryptoCryptoDevBackendSymSessionInfo *sess_info, + uint32_t queue_index, Error **errp) +{ + QCryptoCryptoDevBackendClass *bc = + QCRYPTO_CRYPTODEV_BACKEND_GET_CLASS(backend); + + if (bc->create_session) { + return bc->create_session(backend, sess_info, queue_index, errp); + } + + return -1; +} + +int qcrypto_cryptodev_backend_sym_close_session( + QCryptoCryptoDevBackend *backend, + uint64_t session_id, + uint32_t queue_index, Error **errp) +{ + QCryptoCryptoDevBackendClass *bc = + QCRYPTO_CRYPTODEV_BACKEND_GET_CLASS(backend); + + if (bc->close_session) { + return bc->close_session(backend, session_id, queue_index, errp); + } + + return -1; +} + +int qcrypto_cryptodev_backend_sym_operation( + QCryptoCryptoDevBackend *backend, + QCryptoCryptoDevBackendSymOpInfo *op_info, + uint32_t queue_index, Error **errp) +{ + QCryptoCryptoDevBackendClass *bc = + QCRYPTO_CRYPTODEV_BACKEND_GET_CLASS(backend); + + if (bc->do_sym_op) { + return bc->do_sym_op(backend, op_info, queue_index, errp); + } + + return -1; +} + static void qcrypto_cryptodev_backend_get_queues(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) diff --git a/include/sysemu/cryptodev.h b/include/sysemu/cryptodev.h index d43cbb4..70565b5 100644 --- a/include/sysemu/cryptodev.h +++ b/include/sysemu/cryptodev.h @@ -56,12 +56,100 @@ typedef struct QCryptoCryptoDevBackendClientState QCryptoCryptoDevBackendClientState; typedef struct QCryptoCryptoDevBackend QCryptoCryptoDevBackend; +enum QCryptoCryptoDevBackendAlgType { + QCRYPTO_CRYPTODEV_BACKEND_ALG_SYM, + QCRYPTO_CRYPTODEV_BACKEND_ALG__MAX, +}; + +/** + * QCryptoCryptoDevBackendSymSessionInfo: + * + * @op_code: operation code (refer to virtio_crypto.h) + * @cipher_alg: algorithm type of CIPHER + * @key_len: byte length of cipher key + * @hash_alg: algorithm type of HASH/MAC + * @hash_result_len: byte length of HASH operation result + * @auth_key_len: byte length of authenticated key + * @add_len: byte length of additional authenticated data + * @op_type: operation type (refer to virtio_crypto.h) + * @direction: encryption or direction for CIPHER + * @hash_mode: HASH mode for HASH operation (refer to virtio_crypto.h) + * @alg_chain_order: order of algorithm chaining (CIPHER then HASH, + * or HASH then CIPHER) + * @cipher_key: point to a key of CIPHER + * @auth_key: point to an authenticated key of MAC + * + */ +typedef struct QCryptoCryptoDevBackendSymSessionInfo { + /* corresponding with virtio crypto spec */ + uint32_t op_code; + uint32_t cipher_alg; + uint32_t key_len; + uint32_t hash_alg; + uint32_t hash_result_len; + uint32_t auth_key_len; + uint32_t add_len; + uint8_t op_type; + uint8_t direction; + uint8_t hash_mode; + uint8_t alg_chain_order; + uint8_t *cipher_key; + uint8_t *auth_key; +} QCryptoCryptoDevBackendSymSessionInfo; + +/** + * QCryptoCryptoDevBackendSymOpInfo: + * + * @session_id: session index which was previously + * created by qcrypto_cryptodev_backend_sym_create_session() + * @aad_len: byte length of additional authenticated data + * @iv_len: byte length of initialization vector or counter + * @src_len: byte length of source data + * @dst_len: byte length of destination data + * @digest_result_len: byte length of hash digest result + * @hash_start_src_offset: Starting point for hash processing, specified + * as number of bytes from start of packet in source data + * @op_type: operation type (refer to virtio_crypto.h) + * @iv: point to the initialization vector or counter + * @src: point to the source data + * @dst: point to the destination data + * @aad_data: point to the additional authenticated data + * @digest_result: point to the digest result data + * @data[0]: point to the extensional memory by one memory allocation + * + */ +typedef struct QCryptoCryptoDevBackendSymOpInfo { + uint64_t session_id; + uint32_t aad_len; + uint32_t iv_len; + uint32_t src_len; + uint32_t dst_len; + uint32_t digest_result_len; + uint32_t hash_start_src_offset; + uint8_t op_type; + uint8_t *iv; + uint8_t *src; + uint8_t *dst; + uint8_t *aad_data; + uint8_t *digest_result; + uint8_t data[0]; +} QCryptoCryptoDevBackendSymOpInfo; typedef struct QCryptoCryptoDevBackendClass { ObjectClass parent_class; void (*init)(QCryptoCryptoDevBackend *backend, Error **errp); void (*cleanup)(QCryptoCryptoDevBackend *backend, Error **errp); + + int64_t (*create_session)(QCryptoCryptoDevBackend *backend, + QCryptoCryptoDevBackendSymSessionInfo *sess_info, + uint32_t queue_index, Error **errp); + int (*close_session)(QCryptoCryptoDevBackend *backend, + uint64_t session_id, + uint32_t queue_index, Error **errp); + int (*do_sym_op)(QCryptoCryptoDevBackend *backend, + QCryptoCryptoDevBackendSymOpInfo *op_info, + uint32_t queue_index, Error **errp); } QCryptoCryptoDevBackendClass; @@ -142,4 +230,54 @@ void qcrypto_cryptodev_backend_cleanup( QCryptoCryptoDevBackend *backend, Error **errp); +/** + * qcrypto_cryptodev_backend_sym_create_session: + * @backend: the cryptodev backend object + * @sess_info: parameters needed by session creating + * @queue_index: queue index of cryptodev backend client + * @errp: pointer to a NULL-initialized error object + * + * Create a session for symmetric algorithms + * + * Returns: session id on success, or -1 on error + */ +int64_t qcrypto_cryptodev_backend_sym_create_session( + QCryptoCryptoDevBackend *backend, + QCryptoCryptoDevBackendSymSessionInfo *sess_info, + uint32_t queue_index, Error **errp); + +/** + * qcrypto_cryptodev_backend_sym_close_session: + * @backend: the cryptodev backend object + * @session_id: the session id + * @queue_index: queue index of cryptodev backend client + * @errp: pointer to a NULL-initialized error object + * + * Close a session for symmetric algorithms which was previously + * created by qcrypto_cryptodev_backend_sym_create_session() + * + * Returns: 0 on success, or Negative on error + */ +int qcrypto_cryptodev_backend_sym_close_session( + QCryptoCryptoDevBackend *backend, + uint64_t session_id, + uint32_t queue_index, Error **errp); + +/** + * qcrypto_cryptodev_backend_sym_operation: + * @backend: the cryptodev backend object + * @op_info: parameters needed by symmetric crypto operation + * @queue_index: queue index of cryptodev backend client + * @errp: pointer to a NULL-initialized error object + * + * Do symmetric crypto operation, such as encryption and + * decryption + * + * Returns: 0 on success, or Negative on error + */ +int qcrypto_cryptodev_backend_sym_operation( + QCryptoCryptoDevBackend *backend, + QCryptoCryptoDevBackendSymOpInfo *op_info, + uint32_t queue_index, Error **errp); + #endif /* QCRYPTO_CRYPTODEV_H */ -- 1.7.12.4