From nobody Tue Feb 10 12:40:16 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; dkim=fail; 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 1500055584354807.5032993193618; Fri, 14 Jul 2017 11:06:24 -0700 (PDT) Received: from localhost ([::1]:39279 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW4yo-0006Sn-0C for importer@patchew.org; Fri, 14 Jul 2017 14:06:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55127) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW4wu-0005C8-VI for qemu-devel@nongnu.org; Fri, 14 Jul 2017 14:04:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dW4wt-00035c-Pq for qemu-devel@nongnu.org; Fri, 14 Jul 2017 14:04:20 -0400 Received: from mail-pg0-x244.google.com ([2607:f8b0:400e:c05::244]:36653) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dW4wt-00034t-Jo for qemu-devel@nongnu.org; Fri, 14 Jul 2017 14:04:19 -0400 Received: by mail-pg0-x244.google.com with SMTP id y129so11394210pgy.3 for ; Fri, 14 Jul 2017 11:04:19 -0700 (PDT) Received: from localhost (45.78.25.254.16clouds.com. [45.78.25.254]) by smtp.gmail.com with ESMTPSA id z74sm21603981pfd.112.2017.07.14.11.04.17 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Fri, 14 Jul 2017 11:04:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4oYrGBqUTGqt7+2pMsePic9NEyXfunjgsJDFVUucTzw=; b=nSfBkLR/QeT4hqqc6G7sHcfkypVoPeH+IRLJOeutraV13FhIhmyuHBFeP9DntfMfVe 3zyBhHrQvPEx9IQ18N1AenUWxrMMDevewYv+TkbcUL2ofIDO2J25OKLFb4rXtRr+KNwr pOuTSQxYHba6alkLW1xBdhlQwE709jOaYpF3fU6KZWzzKpXWZypDRsM+zA6IJeCFF6+k 5xtdMc5Tx8fu5G24Kuwhn83RuieB/U96XtJyOC/dmFg9m6K0afQKnPI3HqqnbiwNLIPr tGfrAQPZKKf0/f/ZzYAcAJRmj+asNE8pZtl+7ODHoEo2AGTZjt3VxBfACMocA6tJ614R tXKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4oYrGBqUTGqt7+2pMsePic9NEyXfunjgsJDFVUucTzw=; b=TeoeWXT38NbxDU2lnvOtPFIGhOVIYgRBLtxWbtu7j2Vm6sN2O0oqnGBJWZmCIx7Z9J AgV6MgMvyEo+7rnZLAr7PjwsZHGeEZidy4Ts98DugePb4tekxmTfU5cA/WSrioV8EeQN SYGR1QPy4EE9uMjnvlwJ0ea72qgy/fdak/xGlRnmSVIXW+I7GZ09B09JjbiNE2jBjidQ Kzeh1DubIugaXVxIJaT8GCj8YzDg64c3gOODz6U+gDA12JhEYc/RkCnSXW+uxInHKQHT +7JInbsf7J9o8WWQg0yjEOH0FTEqKGmmJmg0EzoOndtG16mionDRACKCP4MGpfUjEYE/ VQVQ== X-Gm-Message-State: AIVw1127/hTH+V2UfL9n77f5nGPg1M5sgIdD5zeH6SzrSdIsQ9jLXmac tDhoT7nkq99utw== X-Received: by 10.98.7.87 with SMTP id b84mr6445936pfd.216.1500055458563; Fri, 14 Jul 2017 11:04:18 -0700 (PDT) From: longpeng.mike@gmail.com To: berrange@redhat.com Date: Fri, 14 Jul 2017 14:03:56 -0400 Message-Id: <1500055451-14041-4-git-send-email-longpeng.mike@gmail.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1500055451-14041-1-git-send-email-longpeng.mike@gmail.com> References: <1500055451-14041-1-git-send-email-longpeng.mike@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::244 Subject: [Qemu-devel] [PATCH v6 03/18] crypto: cipher: introduce qcrypto_cipher_ctx_new for nettle-backend 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: "Longpeng\(Mike\)" , arei.gonglei@huawei.com, weidong.huang@huawei.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Longpeng(Mike)" Extracts qcrypto_cipher_ctx_new() from qcrypto_cipher_new() for nettle-backend impls. Reviewed-by: Daniel P. Berrange Reviewed-by: Gonglei Signed-off-by: Longpeng(Mike) --- crypto/cipher-nettle.c | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/crypto/cipher-nettle.c b/crypto/cipher-nettle.c index e04e3a1..e6d6e6c 100644 --- a/crypto/cipher-nettle.c +++ b/crypto/cipher-nettle.c @@ -262,12 +262,12 @@ static void nettle_cipher_free_ctx(QCryptoCipherNettl= e *ctx) } =20 =20 -QCryptoCipher *qcrypto_cipher_new(QCryptoCipherAlgorithm alg, - QCryptoCipherMode mode, - const uint8_t *key, size_t nkey, - Error **errp) +static QCryptoCipherNettle *qcrypto_cipher_ctx_new(QCryptoCipherAlgorithm = alg, + QCryptoCipherMode mode, + const uint8_t *key, + size_t nkey, + Error **errp) { - QCryptoCipher *cipher; QCryptoCipherNettle *ctx; uint8_t *rfbkey; =20 @@ -287,12 +287,7 @@ QCryptoCipher *qcrypto_cipher_new(QCryptoCipherAlgorit= hm alg, return NULL; } =20 - cipher =3D g_new0(QCryptoCipher, 1); - cipher->alg =3D alg; - cipher->mode =3D mode; - ctx =3D g_new0(QCryptoCipherNettle, 1); - cipher->opaque =3D ctx; =20 switch (alg) { case QCRYPTO_CIPHER_ALG_DES_RFB: @@ -436,10 +431,10 @@ QCryptoCipher *qcrypto_cipher_new(QCryptoCipherAlgori= thm alg, =20 ctx->iv =3D g_new0(uint8_t, ctx->blocksize); =20 - return cipher; + return ctx; =20 error: - qcrypto_cipher_free(cipher); + nettle_cipher_free_ctx(ctx); return NULL; } =20 @@ -561,3 +556,25 @@ int qcrypto_cipher_setiv(QCryptoCipher *cipher, memcpy(ctx->iv, iv, niv); return 0; } + + +QCryptoCipher *qcrypto_cipher_new(QCryptoCipherAlgorithm alg, + QCryptoCipherMode mode, + const uint8_t *key, size_t nkey, + Error **errp) +{ + QCryptoCipher *cipher; + QCryptoCipherNettle *ctx; + + ctx =3D qcrypto_cipher_ctx_new(alg, mode, key, nkey, errp); + if (!ctx) { + return NULL; + } + + cipher =3D g_new0(QCryptoCipher, 1); + cipher->alg =3D alg; + cipher->mode =3D mode; + cipher->opaque =3D ctx; + + return cipher; +} --=20 1.8.3.1