From patchwork Mon Sep 11 01:10:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Longpeng(Mike)" X-Patchwork-Id: 9946445 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 5E30E602C9 for ; Mon, 11 Sep 2017 01:13:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 52650289D8 for ; Mon, 11 Sep 2017 01:13:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 471E628A9B; Mon, 11 Sep 2017 01:13:05 +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 AB78D289D8 for ; Mon, 11 Sep 2017 01:13:04 +0000 (UTC) Received: from localhost ([::1]:54826 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drDHb-0004JK-Pm for patchwork-qemu-devel@patchwork.kernel.org; Sun, 10 Sep 2017 21:13:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35254) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drDG5-0004HK-Sp for qemu-devel@nongnu.org; Sun, 10 Sep 2017 21:11:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1drDG1-00045o-2i for qemu-devel@nongnu.org; Sun, 10 Sep 2017 21:11:29 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:2257) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1drDG0-00041D-2a for qemu-devel@nongnu.org; Sun, 10 Sep 2017 21:11:25 -0400 Received: from 172.30.72.59 (EHLO DGGEMS404-HUB.china.huawei.com) ([172.30.72.59]) by dggrg05-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id DHB06012; Mon, 11 Sep 2017 09:11:00 +0800 (CST) Received: from localhost (10.177.246.209) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.301.0; Mon, 11 Sep 2017 09:10:53 +0800 From: "Longpeng(Mike)" To: , Date: Mon, 11 Sep 2017 09:10:38 +0800 Message-ID: <1505092240-10864-7-git-send-email-longpeng2@huawei.com> X-Mailer: git-send-email 1.8.4.msysgit.0 In-Reply-To: <1505092240-10864-1-git-send-email-longpeng2@huawei.com> References: <1505092240-10864-1-git-send-email-longpeng2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.246.209] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A0B0205.59B5E2A5.001B, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 1cd8c6a770e990a286b0f3307a590b81 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] [fuzzy] X-Received-From: 45.249.212.191 Subject: [Qemu-devel] [RFC 6/8] cryptodev: extract one util function 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, mst@redhat.com, jasowang@redhat.com, john.griffin@intel.com, Varun.Sethi@freescale.com, denglingli@chinamobile.com, arei.gonglei@hotmail.com, agraf@suse.de, arei.gonglei@huawei.com, "Longpeng\(Mike\)" , vincent.jardin@6wind.com, Ola.Liljedahl@arm.com, luonengjun@huawei.com, xin.zeng@intel.com, liang.j.ma@intel.com, stefanha@redhat.com, Jani.Kokkonen@huawei.com, pasic@linux.vnet.ibm.com, brian.a.keating@intel.com, wangxinxin.wang@huawei.com, cohuck@redhat.com, mike.caraman@nxp.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Gonglei So that the new function can be used by both seesion creation and the following stateless crypto operation. Signed-off-by: Gonglei Signed-off-by: Longpeng(Mike) --- backends/cryptodev-builtin.c | 100 +++++++++++++++++++++++++------------------ 1 file changed, 58 insertions(+), 42 deletions(-) diff --git a/backends/cryptodev-builtin.c b/backends/cryptodev-builtin.c index 6e10feb..ab3d88d 100755 --- a/backends/cryptodev-builtin.c +++ b/backends/cryptodev-builtin.c @@ -152,73 +152,56 @@ err: return -1; } -static int cryptodev_builtin_create_cipher_session( - CryptoDevBackendBuiltin *builtin, +static int +cryptodev_builtin_get_cipher_alg_mode( CryptoDevBackendSymSessionInfo *sess_info, + int *algo, int *mode, Error **errp) { - int algo; - int mode; - QCryptoCipher *cipher; - int index; - CryptoDevBackendBuiltinSession *sess; - - if (sess_info->op_type != VIRTIO_CRYPTO_SYM_OP_CIPHER) { - error_setg(errp, "Unsupported optype :%u", sess_info->op_type); - return -1; - } - - index = cryptodev_builtin_get_unused_session_index(builtin); - if (index < 0) { - error_setg(errp, "Total number of sessions created exceeds %u", - MAX_NUM_SESSIONS); - return -1; - } - switch (sess_info->cipher_alg) { case VIRTIO_CRYPTO_CIPHER_AES_ECB: - mode = QCRYPTO_CIPHER_MODE_ECB; - algo = cryptodev_builtin_get_aes_algo(sess_info->key_len, - mode, errp); - if (algo < 0) { + *mode = QCRYPTO_CIPHER_MODE_ECB; + *algo = cryptodev_builtin_get_aes_algo(sess_info->key_len, + *mode, errp); + if (*algo < 0) { return -1; } break; case VIRTIO_CRYPTO_CIPHER_AES_CBC: - mode = QCRYPTO_CIPHER_MODE_CBC; - algo = cryptodev_builtin_get_aes_algo(sess_info->key_len, - mode, errp); - if (algo < 0) { + *mode = QCRYPTO_CIPHER_MODE_CBC; + *algo = cryptodev_builtin_get_aes_algo(sess_info->key_len, + *mode, errp); + if (*algo < 0) { return -1; } break; case VIRTIO_CRYPTO_CIPHER_AES_CTR: - mode = QCRYPTO_CIPHER_MODE_CTR; - algo = cryptodev_builtin_get_aes_algo(sess_info->key_len, - mode, errp); - if (algo < 0) { + *mode = QCRYPTO_CIPHER_MODE_CTR; + *algo = cryptodev_builtin_get_aes_algo(sess_info->key_len, + *mode, errp); + if (*algo < 0) { return -1; } break; case VIRTIO_CRYPTO_CIPHER_AES_XTS: - mode = QCRYPTO_CIPHER_MODE_XTS; - algo = cryptodev_builtin_get_aes_algo(sess_info->key_len, - mode, errp); - if (algo < 0) { + *mode = QCRYPTO_CIPHER_MODE_XTS; + *algo = cryptodev_builtin_get_aes_algo(sess_info->key_len, + *mode, errp); + if (*algo < 0) { return -1; } break; case VIRTIO_CRYPTO_CIPHER_3DES_ECB: - mode = QCRYPTO_CIPHER_MODE_ECB; - algo = QCRYPTO_CIPHER_ALG_3DES; + *mode = QCRYPTO_CIPHER_MODE_ECB; + *algo = QCRYPTO_CIPHER_ALG_3DES; break; case VIRTIO_CRYPTO_CIPHER_3DES_CBC: - mode = QCRYPTO_CIPHER_MODE_CBC; - algo = QCRYPTO_CIPHER_ALG_3DES; + *mode = QCRYPTO_CIPHER_MODE_CBC; + *algo = QCRYPTO_CIPHER_ALG_3DES; break; case VIRTIO_CRYPTO_CIPHER_3DES_CTR: - mode = QCRYPTO_CIPHER_MODE_CTR; - algo = QCRYPTO_CIPHER_ALG_3DES; + *mode = QCRYPTO_CIPHER_MODE_CTR; + *algo = QCRYPTO_CIPHER_ALG_3DES; break; default: error_setg(errp, "Unsupported cipher alg :%u", @@ -226,6 +209,39 @@ static int cryptodev_builtin_create_cipher_session( return -1; } + return 0; +} + +static int cryptodev_builtin_create_cipher_session( + CryptoDevBackendBuiltin *builtin, + CryptoDevBackendSymSessionInfo *sess_info, + Error **errp) +{ + int algo; + int mode; + QCryptoCipher *cipher; + int index; + CryptoDevBackendBuiltinSession *sess; + int ret; + + if (sess_info->op_type != VIRTIO_CRYPTO_SYM_OP_CIPHER) { + error_setg(errp, "Unsupported optype :%u", sess_info->op_type); + return -1; + } + + index = cryptodev_builtin_get_unused_session_index(builtin); + if (index < 0) { + error_setg(errp, "Total number of sessions created exceeds %u", + MAX_NUM_SESSIONS); + return -1; + } + + ret = cryptodev_builtin_get_cipher_alg_mode(sess_info, + &algo, &mode, errp); + if (ret < 0) { + return -1; + } + cipher = qcrypto_cipher_new(algo, mode, sess_info->cipher_key, sess_info->key_len,