From patchwork Fri Jul 14 11:38:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: long mike X-Patchwork-Id: 9840663 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 A2FE7602D8 for ; Fri, 14 Jul 2017 11:41:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9393A28755 for ; Fri, 14 Jul 2017 11:41:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 857A02876E; Fri, 14 Jul 2017 11:41:57 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 CD05228755 for ; Fri, 14 Jul 2017 11:41:56 +0000 (UTC) Received: from localhost ([::1]:37178 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVyyq-0003PR-1j for patchwork-qemu-devel@patchwork.kernel.org; Fri, 14 Jul 2017 07:41:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35507) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVyvr-0000uK-S1 for qemu-devel@nongnu.org; Fri, 14 Jul 2017 07:38:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVyvo-0007iq-Pz for qemu-devel@nongnu.org; Fri, 14 Jul 2017 07:38:51 -0400 Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]:33727) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dVyvo-0007iE-Jr for qemu-devel@nongnu.org; Fri, 14 Jul 2017 07:38:48 -0400 Received: by mail-pf0-x242.google.com with SMTP id e199so10743410pfh.0 for ; Fri, 14 Jul 2017 04:38:48 -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=UrCbIr8beT5nTGxW70cpwoXIXN4Ocp9t8/SzBwm+fdzjGxd9KnJFbgO3rD7nz+Q/Y/ J94LOg0HE6E3LiJAaARfTrqITNP8BXvjDX+dDDRpRLpQ6qIpQgoYn6YgiUhYQtoaJxtt +kbJ8dmQ3G5tRUkMRWGE9TJujl8MrbQ6XOQBUwIS4Psbp/rn7df7thtwwPyGF9fbOrCB bRz0AouFRY2HLPwNtqInRcs9PWOPU8fbxeODvciUB5DLlbkklEgWudBWsRO6qtxRZLGU r47Qsi2cOvwqez+y3LZEc+Dz2ObmqQegb3DGYGDRr20T7iYDuVzvvtVdxK9Arv1NMCcS F96Q== 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=HYlFEdmfr2kB0VhyLlWnikRkCK28YihoF5qlAS+zhZt6ancNJeiDwsuzcRYm36M9Jz xv0gkOCL2K8XV1KnYk/y62n9czYewQ1wJtsWtWNmH+x+LmfaqhpArs8lYMV1js8D1w9i J2eKRfBepdE5SM/sxLqPQxBcbB+4fJxqGDBbVdvnerzOobL5e/d8ixhvXvM5xSY5xdjc FaXID5Ic+HZLvNlKUdzoaWUbLZWJrSwfODLq5ITikztnunZFk9SfcLb113wMVLpX9fjx oHJx655TXo/E8amo7/pPojVWXvjrRbZXbQQY2ybasN2gPXTSp5J1BgrquO92dcTndI36 LQ2A== X-Gm-Message-State: AIVw110xiTnAYVY+FFxH5js/xb4obXZLL6X6vSn+j+jsA32tOL+IF884 ay/JToHBfKgoiA== X-Received: by 10.98.42.4 with SMTP id q4mr4868331pfq.143.1500032327707; Fri, 14 Jul 2017 04:38:47 -0700 (PDT) Received: from localhost (45.78.25.254.16clouds.com. [45.78.25.254]) by smtp.gmail.com with ESMTPSA id 28sm20683787pfq.125.2017.07.14.04.38.46 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Fri, 14 Jul 2017 04:38:47 -0700 (PDT) From: longpeng.mike@gmail.com To: berrange@redhat.com Date: Fri, 14 Jul 2017 07:38:25 -0400 Message-Id: <1500032321-13951-4-git-send-email-longpeng.mike@gmail.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1500032321-13951-1-git-send-email-longpeng.mike@gmail.com> References: <1500032321-13951-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:c00::242 Subject: [Qemu-devel] [PATCH v5 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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; +}