From nobody Tue Feb 10 06:43:30 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.zoho.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 1494243781800718.6228625744172; Mon, 8 May 2017 04:43:01 -0700 (PDT) Received: from localhost ([::1]:58929 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d7h48-0005yP-Et for importer@patchew.org; Mon, 08 May 2017 07:43:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50815) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d7h10-0003LP-7s for qemu-devel@nongnu.org; Mon, 08 May 2017 07:39:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d7h0v-0004by-Kg for qemu-devel@nongnu.org; Mon, 08 May 2017 07:39:46 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:3984) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1d7h0v-0004bB-0Q for qemu-devel@nongnu.org; Mon, 08 May 2017 07:39:41 -0400 Received: from 172.30.72.53 (EHLO DGGEML402-HUB.china.huawei.com) ([172.30.72.53]) by dggrg01-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id AOD07416; Mon, 08 May 2017 19:38:49 +0800 (CST) Received: from localhost (10.177.18.62) by DGGEML402-HUB.china.huawei.com (10.3.17.38) with Microsoft SMTP Server id 14.3.301.0; Mon, 8 May 2017 19:38:36 +0800 From: Gonglei To: Date: Mon, 8 May 2017 19:38:19 +0800 Message-ID: <1494243504-127980-5-git-send-email-arei.gonglei@huawei.com> X-Mailer: git-send-email 2.8.2.windows.1 In-Reply-To: <1494243504-127980-1-git-send-email-arei.gonglei@huawei.com> References: <1494243504-127980-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.0A020204.591058CB.007E, 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: 05c9dca09eb5a9c373fff763f313e6fe X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] [fuzzy] X-Received-From: 45.249.212.187 Subject: [Qemu-devel] [RFC v1 4/9] cryptodev-builtin: realize stateless operation 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: pasic@linux.vnet.ibm.com, weidong.huang@huawei.com, mst@redhat.com, xin.zeng@intel.com, luonengjun@huawei.com, linqiangmin@huawei.com, Gonglei , stefanha@redhat.com, cornelia.huck@de.ibm.com, wu.wubin@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" At this point, the stateless crypto operation for cryptodev-builtin backend works. Signed-off-by: Gonglei --- backends/cryptodev-builtin.c | 71 ++++++++++++++++++++++++++++++++++++++++= +++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/backends/cryptodev-builtin.c b/backends/cryptodev-builtin.c index 1e72985..7829999 100644 --- a/backends/cryptodev-builtin.c +++ b/backends/cryptodev-builtin.c @@ -401,7 +401,76 @@ cryptodev_builtin_sym_stateless_operation( CryptoDevBackendSymStatelessInfo *op_info, uint32_t queue_index, Error **errp) { - return -VIRTIO_CRYPTO_ERR; + CryptoDevBackendSymSessionInfo *sess_info; + CryptoDevBackendSymOpInfo *sym_op_info; + int algo, mode; + int ret; + QCryptoCipher *cipher =3D NULL; + + sess_info =3D &op_info->session_info; + sym_op_info =3D &op_info->op_info; + + if (sess_info->op_type !=3D VIRTIO_CRYPTO_SYM_OP_CIPHER) { + error_setg(errp, "Unsupported op_type: %u", sess_info->op_type); + return -VIRTIO_CRYPTO_ERR; + } + + switch (sym_op_info->op_code) { + case VIRTIO_CRYPTO_CIPHER_ENCRYPT: + case VIRTIO_CRYPTO_CIPHER_DECRYPT: + ret =3D cryptodev_builtin_get_cipher_alg_mode(sess_info, + &algo, &mode, errp); + if (ret < 0) { + return -VIRTIO_CRYPTO_ERR; + } + + cipher =3D qcrypto_cipher_new(algo, mode, + sess_info->cipher_key, + sess_info->key_len, + errp); + if (!cipher) { + return -VIRTIO_CRYPTO_ERR; + } + + if (sym_op_info->iv_len > 0) { + ret =3D qcrypto_cipher_setiv(cipher, sym_op_info->iv, + sym_op_info->iv_len, errp); + if (ret < 0) { + ret =3D -VIRTIO_CRYPTO_ERR; + goto out; + } + } + + if (sess_info->direction =3D=3D VIRTIO_CRYPTO_OP_ENCRYPT) { + ret =3D qcrypto_cipher_encrypt(cipher, sym_op_info->src, + sym_op_info->dst, + sym_op_info->src_len, errp); + if (ret < 0) { + ret =3D -VIRTIO_CRYPTO_ERR; + goto out; + } + } else { + ret =3D qcrypto_cipher_decrypt(cipher, sym_op_info->src, + sym_op_info->dst, + sym_op_info->src_len, errp); + if (ret < 0) { + ret =3D -VIRTIO_CRYPTO_ERR; + goto out; + } + } + break; + + default: + error_setg(errp, "Unsupported op_code: %" PRIu32 "", + sym_op_info->op_code); + return -VIRTIO_CRYPTO_ERR; + } + + ret =3D VIRTIO_CRYPTO_OK; + +out: + qcrypto_cipher_free(cipher); + return ret; } =20 static void --=20 1.8.3.1