From patchwork Fri Jul 14 18:03:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: long mike X-Patchwork-Id: 788690 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3x8LFM4k2Zz9s82 for ; Sat, 15 Jul 2017 04:05:11 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="nSfBkLR/"; dkim-atps=neutral Received: from localhost ([::1]:39272 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW4xh-0005DJ-Dh for incoming@patchwork.ozlabs.org; Fri, 14 Jul 2017 14:05:09 -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) 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) 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) 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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(QCryptoCipherNettle *ctx) } -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; @@ -287,12 +287,7 @@ QCryptoCipher *qcrypto_cipher_new(QCryptoCipherAlgorithm alg, return NULL; } - cipher = g_new0(QCryptoCipher, 1); - cipher->alg = alg; - cipher->mode = mode; - ctx = g_new0(QCryptoCipherNettle, 1); - cipher->opaque = ctx; switch (alg) { case QCRYPTO_CIPHER_ALG_DES_RFB: @@ -436,10 +431,10 @@ QCryptoCipher *qcrypto_cipher_new(QCryptoCipherAlgorithm alg, ctx->iv = g_new0(uint8_t, ctx->blocksize); - return cipher; + return ctx; error: - qcrypto_cipher_free(cipher); + nettle_cipher_free_ctx(ctx); return NULL; } @@ -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 = qcrypto_cipher_ctx_new(alg, mode, key, nkey, errp); + if (!ctx) { + return NULL; + } + + cipher = g_new0(QCryptoCipher, 1); + cipher->alg = alg; + cipher->mode = mode; + cipher->opaque = ctx; + + return cipher; +}