From patchwork Fri Jul 14 11:38:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: long mike X-Patchwork-Id: 9840705 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 7090260212 for ; Fri, 14 Jul 2017 11:56:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 61D2C28755 for ; Fri, 14 Jul 2017 11:56:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 55B9828779; Fri, 14 Jul 2017 11:56:47 +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 BC1E828755 for ; Fri, 14 Jul 2017 11:56:46 +0000 (UTC) Received: from localhost ([::1]:37255 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVzDB-0001Kk-PK for patchwork-qemu-devel@patchwork.kernel.org; Fri, 14 Jul 2017 07:56:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35601) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVyvw-0000zr-Mi for qemu-devel@nongnu.org; Fri, 14 Jul 2017 07:38:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVyvv-0007o3-T9 for qemu-devel@nongnu.org; Fri, 14 Jul 2017 07:38:56 -0400 Received: from mail-pg0-x244.google.com ([2607:f8b0:400e:c05::244]:33856) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dVyvv-0007nX-NV for qemu-devel@nongnu.org; Fri, 14 Jul 2017 07:38:55 -0400 Received: by mail-pg0-x244.google.com with SMTP id j186so10399579pge.1 for ; Fri, 14 Jul 2017 04:38:55 -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=X/XrCDttJqKRe+u3ulI2zsgMyRFbIRjsUbnMWpnLe4o=; b=PhK9dz4OTSS6bEmxim2OegvieuBDnOGPYpDuc+kKkpG1MUAWeXt8hCmxsLrN+us1nw Fpui8ijYK1YuCVoAP5+3GajvlX+pGY3NCTOedtYTZIbGD5ZK1NMRoqEzjAn8u2fIMNxh zmI7fnGat2QkaFGSDy9TWZgVgqGTHbZKprr0ttClziSLyKTIOHTOLRmUqgY9oXPTWl9G HmQ87WE7p63ezKvxR5sfEYLrKq9huZdZY/CCcdyGmDwtFq5s9oM7Znt/o20PeIkWTI3z JlTGdZYyGQPmwpO86aw6WKgkmw9c4pZeKHulakFEt05MqqquqsBAHoP71+D/OWdPah89 Bj9w== 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=X/XrCDttJqKRe+u3ulI2zsgMyRFbIRjsUbnMWpnLe4o=; b=jWMxGTVFfPEnuo9CYjqkYTSMgmC0K+i+kg4CkWG+gD4iQyaHUdP93HJdRDMgPNOz/i VQdiEDrRYd02qkJ6gybbpqOiBg+t/NZmuep4T79isDNjRieu+7tia6BQYPhkCHMT46zf m2iGjsVHuxMyDDXpTNTpb/an/1rSA8CYfbNx/J+Rg1Bbmc+7mu8ueiS5LbI8a1ixm6uo fgzjw+NYTvuQ+TG+ic+gRvp/olnvbI/2iDs6Kqgu4NmLufqDtG6SS315dRmIxNZ5z6EW TyvsSg82muHXyR6IFZIIc9NHrREoj0TNimVNQkPvIM83AHFGw2rLN8JhQhIv1FGoIDIr dY7A== X-Gm-Message-State: AIVw112N6zOI3ZFxHzO+VuvcqKRRjOO1NBqrxRFKaCVc+cISLt3QNDgH r1566LggA+UVJA== X-Received: by 10.98.84.194 with SMTP id i185mr4715030pfb.69.1500032334950; Fri, 14 Jul 2017 04:38:54 -0700 (PDT) Received: from localhost (45.78.25.254.16clouds.com. [45.78.25.254]) by smtp.gmail.com with ESMTPSA id i126sm23974891pgc.6.2017.07.14.04.38.54 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Fri, 14 Jul 2017 04:38:54 -0700 (PDT) From: longpeng.mike@gmail.com To: berrange@redhat.com Date: Fri, 14 Jul 2017 07:38:31 -0400 Message-Id: <1500032321-13951-10-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:c05::244 Subject: [Qemu-devel] [PATCH v5 09/18] crypto: hmac: introduce qcrypto_hmac_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_hmac_ctx_new() from qcrypto_hmac_new() for nettle-backend impls. Reviewed-by: Daniel P. Berrange Reviewed-by: Gonglei Signed-off-by: Longpeng(Mike) --- crypto/hmac-nettle.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/crypto/hmac-nettle.c b/crypto/hmac-nettle.c index 4a9e6b2..000dfd9 100644 --- a/crypto/hmac-nettle.c +++ b/crypto/hmac-nettle.c @@ -97,11 +97,11 @@ bool qcrypto_hmac_supports(QCryptoHashAlgorithm alg) return false; } -QCryptoHmac *qcrypto_hmac_new(QCryptoHashAlgorithm alg, - const uint8_t *key, size_t nkey, - Error **errp) +static QCryptoHmacNettle * +qcrypto_hmac_ctx_new(QCryptoHashAlgorithm alg, + const uint8_t *key, size_t nkey, + Error **errp) { - QCryptoHmac *hmac; QCryptoHmacNettle *ctx; if (!qcrypto_hmac_supports(alg)) { @@ -110,16 +110,11 @@ QCryptoHmac *qcrypto_hmac_new(QCryptoHashAlgorithm alg, return NULL; } - hmac = g_new0(QCryptoHmac, 1); - hmac->alg = alg; - ctx = g_new0(QCryptoHmacNettle, 1); qcrypto_hmac_alg_map[alg].setkey(&ctx->u, nkey, key); - hmac->opaque = ctx; - - return hmac; + return ctx; } void qcrypto_hmac_free(QCryptoHmac *hmac) @@ -173,3 +168,22 @@ int qcrypto_hmac_bytesv(QCryptoHmac *hmac, return 0; } + +QCryptoHmac *qcrypto_hmac_new(QCryptoHashAlgorithm alg, + const uint8_t *key, size_t nkey, + Error **errp) +{ + QCryptoHmac *hmac; + QCryptoHmacNettle *ctx; + + ctx = qcrypto_hmac_ctx_new(alg, key, nkey, errp); + if (!ctx) { + return NULL; + } + + hmac = g_new0(QCryptoHmac, 1); + hmac->alg = alg; + hmac->opaque = ctx; + + return hmac; +}