From nobody Mon Feb 9 02:13:55 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 150995171199112.562000725361145; Sun, 5 Nov 2017 23:01:51 -0800 (PST) Received: from localhost ([::1]:46731 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBbPo-00011t-57 for importer@patchew.org; Mon, 06 Nov 2017 02:01:48 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49783) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBbLa-0006Gl-FL for qemu-devel@nongnu.org; Mon, 06 Nov 2017 01:57:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eBbLX-0008Hz-Qz for qemu-devel@nongnu.org; Mon, 06 Nov 2017 01:57:26 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:2331) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1eBbLW-0008Aw-Tf for qemu-devel@nongnu.org; Mon, 06 Nov 2017 01:57:23 -0500 Received: from 172.30.72.60 (EHLO DGGEMS405-HUB.china.huawei.com) ([172.30.72.60]) by dggrg04-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id DKI32703; Mon, 06 Nov 2017 14:57:20 +0800 (CST) Received: from localhost (10.177.246.209) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.361.1; Mon, 6 Nov 2017 14:57:09 +0800 From: "Longpeng(Mike)" To: , Date: Mon, 6 Nov 2017 14:57:00 +0800 Message-ID: <1509951422-20060-9-git-send-email-longpeng2@huawei.com> X-Mailer: git-send-email 1.8.4.msysgit.0 In-Reply-To: <1509951422-20060-1-git-send-email-longpeng2@huawei.com> References: <1509951422-20060-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.0A020204.5A0007D0.003E, 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: a03920536339c00fbfbb4c212d9e5256 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] [fuzzy] X-Received-From: 45.249.212.190 Subject: [Qemu-devel] [RFC 08/10] 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: wangxinxin.wang@huawei.com, "Longpeng\(Mike\)" , weidong.huang@huawei.com, qemu-devel@nongnu.org, jianjay.zhou@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 6df23b9..ba6d15c 100644 --- a/backends/cryptodev-builtin.c +++ b/backends/cryptodev-builtin.c @@ -152,73 +152,56 @@ err: return -1; } =20 -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 !=3D VIRTIO_CRYPTO_SYM_OP_CIPHER) { - error_setg(errp, "Unsupported optype :%u", sess_info->op_type); - return -1; - } - - index =3D 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 =3D QCRYPTO_CIPHER_MODE_ECB; - algo =3D cryptodev_builtin_get_aes_algo(sess_info->key_len, - mode, errp); - if (algo < 0) { + *mode =3D QCRYPTO_CIPHER_MODE_ECB; + *algo =3D cryptodev_builtin_get_aes_algo(sess_info->key_len, + *mode, errp); + if (*algo < 0) { return -1; } break; case VIRTIO_CRYPTO_CIPHER_AES_CBC: - mode =3D QCRYPTO_CIPHER_MODE_CBC; - algo =3D cryptodev_builtin_get_aes_algo(sess_info->key_len, - mode, errp); - if (algo < 0) { + *mode =3D QCRYPTO_CIPHER_MODE_CBC; + *algo =3D cryptodev_builtin_get_aes_algo(sess_info->key_len, + *mode, errp); + if (*algo < 0) { return -1; } break; case VIRTIO_CRYPTO_CIPHER_AES_CTR: - mode =3D QCRYPTO_CIPHER_MODE_CTR; - algo =3D cryptodev_builtin_get_aes_algo(sess_info->key_len, - mode, errp); - if (algo < 0) { + *mode =3D QCRYPTO_CIPHER_MODE_CTR; + *algo =3D cryptodev_builtin_get_aes_algo(sess_info->key_len, + *mode, errp); + if (*algo < 0) { return -1; } break; case VIRTIO_CRYPTO_CIPHER_AES_XTS: - mode =3D QCRYPTO_CIPHER_MODE_XTS; - algo =3D cryptodev_builtin_get_aes_algo(sess_info->key_len, - mode, errp); - if (algo < 0) { + *mode =3D QCRYPTO_CIPHER_MODE_XTS; + *algo =3D cryptodev_builtin_get_aes_algo(sess_info->key_len, + *mode, errp); + if (*algo < 0) { return -1; } break; case VIRTIO_CRYPTO_CIPHER_3DES_ECB: - mode =3D QCRYPTO_CIPHER_MODE_ECB; - algo =3D QCRYPTO_CIPHER_ALG_3DES; + *mode =3D QCRYPTO_CIPHER_MODE_ECB; + *algo =3D QCRYPTO_CIPHER_ALG_3DES; break; case VIRTIO_CRYPTO_CIPHER_3DES_CBC: - mode =3D QCRYPTO_CIPHER_MODE_CBC; - algo =3D QCRYPTO_CIPHER_ALG_3DES; + *mode =3D QCRYPTO_CIPHER_MODE_CBC; + *algo =3D QCRYPTO_CIPHER_ALG_3DES; break; case VIRTIO_CRYPTO_CIPHER_3DES_CTR: - mode =3D QCRYPTO_CIPHER_MODE_CTR; - algo =3D QCRYPTO_CIPHER_ALG_3DES; + *mode =3D QCRYPTO_CIPHER_MODE_CTR; + *algo =3D 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; } =20 + 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 !=3D VIRTIO_CRYPTO_SYM_OP_CIPHER) { + error_setg(errp, "Unsupported optype :%u", sess_info->op_type); + return -1; + } + + index =3D 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 =3D cryptodev_builtin_get_cipher_alg_mode(sess_info, + &algo, &mode, errp); + if (ret < 0) { + return -1; + } + cipher =3D qcrypto_cipher_new(algo, mode, sess_info->cipher_key, sess_info->key_len, --=20 1.8.3.1