From patchwork Fri Jul 14 11:38:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: long mike X-Patchwork-Id: 9840677 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 B250F60212 for ; Fri, 14 Jul 2017 11:46:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A4B3D28755 for ; Fri, 14 Jul 2017 11:46:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 96D9928779; Fri, 14 Jul 2017 11:46:58 +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 B575828755 for ; Fri, 14 Jul 2017 11:46:57 +0000 (UTC) Received: from localhost ([::1]:37206 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVz3g-0000Uz-RW for patchwork-qemu-devel@patchwork.kernel.org; Fri, 14 Jul 2017 07:46:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35652) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVyw2-0001Cn-2A for qemu-devel@nongnu.org; Fri, 14 Jul 2017 07:39:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVyvx-0007p5-5u for qemu-devel@nongnu.org; Fri, 14 Jul 2017 07:39:02 -0400 Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]:33859) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dVyvx-0007oV-01 for qemu-devel@nongnu.org; Fri, 14 Jul 2017 07:38:57 -0400 Received: by mail-pg0-x243.google.com with SMTP id j186so10399622pge.1 for ; Fri, 14 Jul 2017 04:38:56 -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=tu9HnCtwAaYKj9xNpuvx5voUZ1kSyRjgyPTrhRHlOQI=; b=fPGfqDFzA+UgCZN7l53j9Dj70feuMxDqenXjNFEt85B0azuQfxcQLImhvWoEyMy4XW lEIJcV18QXIKbYU3RP7sTne2WYQ8jfGG3qPopx/lh2FTJCzDAlobenQ9TRZ411FEXnNs jtWWLIKU/U7VIJa94ge9GHXK63Bhdev5bCV9CZk4W4Mp7xfnonyCz+G58NwFcmTZtMco ZpfabJX4i7muJbXjHRfIO+MRXn1qFTt14Aw4f0s1kSlGtu5xVTuuUY1W7SzWLrWzFxJ7 fkdLB+0cHWEee6L3yk6ExREhjrOOvER6eboxLvyH2/gTUnX9LewPxmZSktHjWvz97hXy eWpw== 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=tu9HnCtwAaYKj9xNpuvx5voUZ1kSyRjgyPTrhRHlOQI=; b=A9lDuTIOk9I6zQFNDEHwdUiny/hx9cQTYdain3LCAZ3B3WTMWGKUr8C04MQnTIJbpF RerC8ZglAQOClFHh2QA6ZJL00mqWVVogLbP8ySlDz0tniIM4MOzCnXGufeZ99uz68Y5A C86eXaIbB3Uieiui+wCc/BwWol+1I7aHB4y3sqK+PBGHGPzkXXah9MevYwj4tT+aWuRt uGpR7DzjveoQz8zdlVwh1ANJWo8rCYTsEYHPR6IAaVjfgHgWM0VamPLI0BcqReSVyIla XpcH6JrI3Ygl1KjwjGWZOMlwX7BwUJQ8AnH1raKO+avZ+OE686Lha4BeSjIgTXcDR7wT qQIw== X-Gm-Message-State: AIVw1135ZFKl2P9G7cNVlmfvDABWAdZ9Qa/EN8w68XHPKYxD0EMeicmT OOriFmFaiFzDrg== X-Received: by 10.98.224.206 with SMTP id d75mr4818598pfm.12.1500032336104; Fri, 14 Jul 2017 04:38:56 -0700 (PDT) Received: from localhost (45.78.25.254.16clouds.com. [45.78.25.254]) by smtp.gmail.com with ESMTPSA id f10sm15849972pgu.54.2017.07.14.04.38.55 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Fri, 14 Jul 2017 04:38:55 -0700 (PDT) From: longpeng.mike@gmail.com To: berrange@redhat.com Date: Fri, 14 Jul 2017 07:38:32 -0400 Message-Id: <1500032321-13951-11-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::243 Subject: [Qemu-devel] [PATCH v5 10/18] crypto: hmac: introduce qcrypto_hmac_ctx_new for glib-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 glib-backend impls. Reviewed-by: Daniel P. Berrange Reviewed-by: Gonglei Signed-off-by: Longpeng(Mike) --- crypto/hmac-glib.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/crypto/hmac-glib.c b/crypto/hmac-glib.c index 08a1fdd..f0ccfd6 100644 --- a/crypto/hmac-glib.c +++ b/crypto/hmac-glib.c @@ -49,11 +49,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 QCryptoHmacGlib * +qcrypto_hmac_ctx_new(QCryptoHashAlgorithm alg, + const uint8_t *key, size_t nkey, + Error **errp) { - QCryptoHmac *hmac; QCryptoHmacGlib *ctx; if (!qcrypto_hmac_supports(alg)) { @@ -62,9 +62,6 @@ QCryptoHmac *qcrypto_hmac_new(QCryptoHashAlgorithm alg, return NULL; } - hmac = g_new0(QCryptoHmac, 1); - hmac->alg = alg; - ctx = g_new0(QCryptoHmacGlib, 1); ctx->ghmac = g_hmac_new(qcrypto_hmac_alg_map[alg], @@ -74,12 +71,10 @@ QCryptoHmac *qcrypto_hmac_new(QCryptoHashAlgorithm alg, goto error; } - hmac->opaque = ctx; - return hmac; + return ctx; error: g_free(ctx); - g_free(hmac); return NULL; } @@ -134,6 +129,25 @@ 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; + QCryptoHmacGlib *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; +} + #else bool qcrypto_hmac_supports(QCryptoHashAlgorithm alg)