From patchwork Fri Jul 14 18:04:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: long mike X-Patchwork-Id: 9841507 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 7FEC1602D8 for ; Fri, 14 Jul 2017 18:08:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 706DF2871A for ; Fri, 14 Jul 2017 18:08:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 654F228789; Fri, 14 Jul 2017 18:08:32 +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 1CA3E2871A for ; Fri, 14 Jul 2017 18:08:32 +0000 (UTC) Received: from localhost ([::1]:39288 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW50x-0007Xj-9D for patchwork-qemu-devel@patchwork.kernel.org; Fri, 14 Jul 2017 14:08:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55262) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW4x2-0005JN-Sy for qemu-devel@nongnu.org; Fri, 14 Jul 2017 14:04:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dW4x1-0003DV-5S for qemu-devel@nongnu.org; Fri, 14 Jul 2017 14:04:28 -0400 Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]:36610) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dW4x1-0003CA-02 for qemu-devel@nongnu.org; Fri, 14 Jul 2017 14:04:27 -0400 Received: by mail-pf0-x242.google.com with SMTP id z6so11754136pfk.3 for ; Fri, 14 Jul 2017 11:04:26 -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=A7z/1gi17zRmxkZnVPvWfzh8ijCZ5nNA/+cQbvNlvPsk81biLWSrMkbTuY7hl6TIGM xBVvlrKcuF1hfZxBJ5jqDbB/L+yd768xhjyW8DCDxNAyWgdntLBOgk8/7CXNyvHq51XF R9I3GjG8fQy2HyRj7REwA5RFWKsuTpNTnpI16kWnrny1rXEbUJcNUqhdbXc9jIUWOqCw CpRaXvYMN/hfG9nxZygN8AffLbYrMaVjchlJt41v8zG7+IgG3UX3olQwZX1uX04CEeXy qMDDTP2K3+MA/4hlcHMzWzVQZViqRWK4F+M63r4JkzW2fRiCiOPQY+aY5xKnl9/RNFCM a4cg== 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=CL2vQEkm9ygLX4ccs82fliv7sYfBYR6Jhk1C7BRSXd5SpJ2wKAKFX1JpzId4mq3uue gaT1MRX0JmdW5nf4t8ydPpj4GFj1xm1s8drz3kQ81bU4/HT2h1ixFjyfy24usI87Yx1p abMVyQJaNqfYdhb4HhpPs2dgzNvQWgT4uXPBSaFWkgkWpwmXDpVqt6Uaf0doHYWc2ltA h08fkzl/E3U74czfZvB3PVY87HDHkVl2E+c/M7AT3wwFvY3yCGl7gv9xCiZ8Kvf3/f04 PNnUZb2UCZqGAQuZCOHreaH4nRi97yZzRldrxuprJQxnXGRruC6kS3z/d9vYSkMdi1UH gFtg== X-Gm-Message-State: AIVw110+DBRdiHM2tBhpfI6vXuVLCC0gXgrjNmhqF8QtQvPb7etk595j uc6nvtlXvStrWVhsou0= X-Received: by 10.98.163.203 with SMTP id q72mr6431465pfl.97.1500055466235; Fri, 14 Jul 2017 11:04:26 -0700 (PDT) Received: from localhost (45.78.25.254.16clouds.com. [45.78.25.254]) by smtp.gmail.com with ESMTPSA id 79sm17426513pgg.46.2017.07.14.11.04.25 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Fri, 14 Jul 2017 11:04:25 -0700 (PDT) From: longpeng.mike@gmail.com To: berrange@redhat.com Date: Fri, 14 Jul 2017 14:04:02 -0400 Message-Id: <1500055451-14041-10-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:c00::242 Subject: [Qemu-devel] [PATCH v6 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; +}