From patchwork Fri Jul 14 18:04:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: long mike X-Patchwork-Id: 9841515 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 E5156602D8 for ; Fri, 14 Jul 2017 18:11:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D5FC628752 for ; Fri, 14 Jul 2017 18:11:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CADCA287A3; Fri, 14 Jul 2017 18:11:02 +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 7B8C128752 for ; Fri, 14 Jul 2017 18:11:02 +0000 (UTC) Received: from localhost ([::1]:39296 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW53N-0001NB-Lv for patchwork-qemu-devel@patchwork.kernel.org; Fri, 14 Jul 2017 14:11:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55266) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW4x3-0005Jg-59 for qemu-devel@nongnu.org; Fri, 14 Jul 2017 14:04:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dW4x2-0003EX-8z for qemu-devel@nongnu.org; Fri, 14 Jul 2017 14:04:29 -0400 Received: from mail-pg0-x242.google.com ([2607:f8b0:400e:c05::242]:34103) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dW4x2-0003Dw-3j for qemu-devel@nongnu.org; Fri, 14 Jul 2017 14:04:28 -0400 Received: by mail-pg0-x242.google.com with SMTP id j186so11377544pge.1 for ; Fri, 14 Jul 2017 11:04:27 -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=vE+TPMfsHhBDTh1Qhh5r5aApynT2Lib3QTIhWlikOXkvrc6wGdOpwmf1+uLQEpMtIS O/4fc0uRUa9HKc+LCkPSJo1jDzRv3E0r2riBELt6krw6J548w6EcioA6KnAjvslwf84y gSZ6uD+5QjHYQ7u/x1y7VtRBD0aTSo+Gr8909DdmN8+gZGzxZDRpq+aXPNtlurFrgJrv 68Rc7C3Wvp5VVgUwoVioS9+ldA9iXo3AJRalnRsLa2ViByXjvDTcYefHwAv7RkeYHjsv XawVsVy1ITHzRQuG0/ImPleKY780zd8KvmNjUdUM1Q+P7+pf7AF5EPcN6Hf+jpCoiF7p SLVQ== 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=EGUCKHhEO4dcI7Yvv6XYHaEE6fE0V9uzozl1C5OGc49V7lt1HnObvPM3iHn7YL2REv 5fjUroCzyAx9jb9b5ttL3xm5oXVyw6L/RuDQz6Hn2L8rm5Kup4ff2A+BUvONO4z41ABU tu+eyB7AqYRxwZc6vpNz3FsyaNpuXrflZcQR+SfM3Lpib8Qfjgsl5rq9twFgVBq03JBO GbvMi+gPFCaKs5ubN58xedVk87xH9okM9sprsv5j0C9jpA6/jWxnefk4XbHF8OZbAKIe wxrwCwWgpTtfA6e2uXna9I+xa1NvtI1aCk0PsjCnKoMs6xgwy7vFSyPWeoplKYywL9Bs Rivw== X-Gm-Message-State: AIVw110VdvnTETT1k/EtX/EeuNMUeps+AfErFRzQj6KeHFpdk89Yzox4 ZJgpxY9VfCWa1TnepbY= X-Received: by 10.84.217.29 with SMTP id o29mr17431157pli.117.1500055467354; Fri, 14 Jul 2017 11:04:27 -0700 (PDT) Received: from localhost (45.78.25.254.16clouds.com. [45.78.25.254]) by smtp.gmail.com with ESMTPSA id k73sm20575556pge.13.2017.07.14.11.04.26 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Fri, 14 Jul 2017 11:04:26 -0700 (PDT) From: longpeng.mike@gmail.com To: berrange@redhat.com Date: Fri, 14 Jul 2017 14:04:03 -0400 Message-Id: <1500055451-14041-11-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::242 Subject: [Qemu-devel] [PATCH v6 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)