From patchwork Mon Sep 19 08:16:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gonglei (Arei)" X-Patchwork-Id: 9338763 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A7F486022E for ; Mon, 19 Sep 2016 08:22:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 98B9828F23 for ; Mon, 19 Sep 2016 08:22:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8D9722905F; Mon, 19 Sep 2016 08:22:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id ACE4928F23 for ; Mon, 19 Sep 2016 08:22:05 +0000 (UTC) Received: from localhost ([::1]:53591 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bltq0-0001Ae-Ei for patchwork-qemu-devel@patchwork.kernel.org; Mon, 19 Sep 2016 04:22:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51844) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bltlU-0006Lw-4z for qemu-devel@nongnu.org; Mon, 19 Sep 2016 04:17:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bltlO-0000hc-TL for qemu-devel@nongnu.org; Mon, 19 Sep 2016 04:17:22 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:59734) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bltlN-0000f9-J1 for qemu-devel@nongnu.org; Mon, 19 Sep 2016 04:17:18 -0400 Received: from 172.24.1.47 (EHLO szxeml427-hub.china.huawei.com) ([172.24.1.47]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DRF40194; Mon, 19 Sep 2016 16:16:43 +0800 (CST) Received: from localhost (10.177.18.62) by szxeml427-hub.china.huawei.com (10.82.67.182) with Microsoft SMTP Server id 14.3.235.1; Mon, 19 Sep 2016 16:16:31 +0800 From: Gonglei To: , Date: Mon, 19 Sep 2016 16:16:14 +0800 Message-ID: <1474272982-275836-3-git-send-email-arei.gonglei@huawei.com> X-Mailer: git-send-email 2.6.3.windows.1 In-Reply-To: <1474272982-275836-1-git-send-email-arei.gonglei@huawei.com> References: <1474272982-275836-1-git-send-email-arei.gonglei@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.18.62] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020205.57DF9EED.002F, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: eb74d8cadafef43298bae34a515dc2e1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 58.251.152.64 Subject: [Qemu-devel] [PATCH v3 02/10] cryptodev: add symmetric algorithm operation stuff X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: weidong.huang@huawei.com, claudio.fontana@huawei.com, mst@redhat.com, xin.zeng@intel.com, hanweidong@huawei.com, luonengjun@huawei.com, agraf@suse.de, nmorey@kalray.eu, mike.caraman@nxp.com, Gonglei , stefanha@redhat.com, jianjay.zhou@huawei.com, pbonzini@redhat.com, vincent.jardin@6wind.com, wu.wubin@huawei.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This patch add session operation and crypto operation stuff in the cryptodev backend, including function pointers and correpsonding structures. Signed-off-by: Gonglei --- crypto/cryptodev.c | 44 +++++++++++++++ include/crypto/cryptodev.h | 132 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 175 insertions(+), 1 deletion(-) diff --git a/crypto/cryptodev.c b/crypto/cryptodev.c index 658a018..0b3d55e 100644 --- a/crypto/cryptodev.c +++ b/crypto/cryptodev.c @@ -74,6 +74,50 @@ void qcrypto_cryptodev_backend_cleanup( backend->ready = 0; } +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, Error **errp) +{ + QCryptoCryptoDevBackendClass *bc = + QCRYPTO_CRYPTODEV_BACKEND_GET_CLASS(backend); + + if (bc->close_session) { + return bc->close_session(backend, session_id, 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/crypto/cryptodev.h b/include/crypto/cryptodev.h index 344dc91..7fcdc2f 100644 --- a/include/crypto/cryptodev.h +++ b/include/crypto/cryptodev.h @@ -56,12 +56,94 @@ 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: pointer to a key of CIPHER + * @auth_key: pointer 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 + * @src_len: byte length of source data + * @dst_len: byte length of destination data, which is equal to + * src_len + hash_result_len if HASH alg configured + * @op_type: operation type (refer to virtio_crypto.h) + * @iv: pointer to the initialization vector of CIPHER + * @src: pointer to the source data + * @dst: pointer to the destination data + * @dst: pointer to the additional authenticated data + * @data[0]: pointer 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; + /* dst_len is equal to src_len + hash_result_len if hash alg configured */ + uint32_t dst_len; + uint8_t op_type; /* cipher or algo chainning */ + uint8_t *iv; + uint8_t *src; + uint8_t *dst; + uint8_t *aad_data; /* additional auth data */ + 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, Error **errp); + int (*do_sym_op)(QCryptoCryptoDevBackend *backend, + QCryptoCryptoDevBackendSymOpInfo *op_info, + uint32_t queue_index, Error **errp); } QCryptoCryptoDevBackendClass; @@ -137,9 +219,57 @@ void qcrypto_cryptodev_backend_free_client( * * Clean the resouce associated with @backend that realizaed * by the specific backend's init() callback - */ + */ 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 that + * @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, 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 */