Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp3458824ybl; Sun, 1 Sep 2019 13:38:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqxVlXSBZoWu++t2B1AyQpDgoLQkF76SXFhjZMnLslWcSCIJfsviVwnhEMHO0leEqmsuo/sB X-Received: by 2002:a17:902:5c3:: with SMTP id f61mr24731243plf.98.1567370331606; Sun, 01 Sep 2019 13:38:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567370331; cv=none; d=google.com; s=arc-20160816; b=e4ihVd4GxlPytu3c0YaI7RlIbKTeVWKIVEbb3p6SX4Rm0K1j0GidTZ8KhcxceyCLHi zQYemDvrqdMBY3TbJFzLUzQ5PrIlxpLGQCVsg9VIiFDLaREeMqqQktl/CnG27VedcApj mEE5BRMa0XCUjrSJwVVeB6IeBE9D+U+73AXqwisunAAvDbT3rpnz7yVVDyru+gpf6oeX SiUd7Db6y/jbmHdNJUkHPQAZK8pyvkp/TC87V/drljawsouyO1NSmKSz4ryN3rPgY5gs k0+ISunn2Hrx5yaHPSAnMH9wyVJxekCUhFnHYfa+x0H9pxu39XXE77zjgtoomdWxG3kx Ek9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=VGbiPl8wVEeobRixg80bKJt/TIRpQsOH53VQPoIUIr4=; b=u/DSiELpcpne4qQBl7RkQZgd+66AP8GuUlww3cYHHKFXjmOcV7nLBcGVdpbwTlcK+0 XA6Z4AF9gt4Y1rOHQd4FnV8shF6HNN99ysk/Va9Nyl+CBbOcjwAFXCGolpLJAMWKy9jh OUgpE+LDfDkx0dpiR7Wf7TMksmxre1dpk3fBE5RNHbxXx+d0U+KvUW4FS+P+ismltsOv 7mf68uSNEe7CEAW5EtWxH2YY3tRI3SUIgLfVfd2Dm80rMoOnmGFa7bW07jf6XyldPSin 8xyPMSRHhxxfn9tkgZzyxJhTeBuEFowyPKKXViKeyZa4V8nZCoYV5G84v+gHWWUghQzx r9QQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u14si10394513pjn.61.2019.09.01.13.38.38; Sun, 01 Sep 2019 13:38:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729280AbfIAUgW (ORCPT + 99 others); Sun, 1 Sep 2019 16:36:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57666 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729213AbfIAUgV (ORCPT ); Sun, 1 Sep 2019 16:36:21 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CF7DA308FC4B; Sun, 1 Sep 2019 20:36:19 +0000 (UTC) Received: from shalem.localdomain.com (ovpn-116-36.ams2.redhat.com [10.36.116.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id A602C60920; Sun, 1 Sep 2019 20:36:15 +0000 (UTC) From: Hans de Goede To: Herbert Xu , "David S . Miller" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Russell King , Catalin Marinas , Will Deacon , Gilad Ben-Yossef , Atul Gupta Cc: Hans de Goede , Marc Zyngier , Eric Biggers , Andy Lutomirski , Ard Biesheuvel , linux-crypto@vger.kernel.org, x86@kernel.org, linux-s390@vger.kernel.org, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 9/9] crypto: sha256 - Remove sha256/224_init code duplication Date: Sun, 1 Sep 2019 22:35:32 +0200 Message-Id: <20190901203532.2615-10-hdegoede@redhat.com> In-Reply-To: <20190901203532.2615-1-hdegoede@redhat.com> References: <20190901203532.2615-1-hdegoede@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Sun, 01 Sep 2019 20:36:20 +0000 (UTC) Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org lib/crypto/sha256.c and include/crypto/sha256_base.h define 99% identical functions to init a sha256_state struct for sha224 or sha256 use. This commit moves the functions from lib/crypto/sha256.c to include/crypto/sha.h (making them static inline) and makes the sha224/256_base_init static inline functions from include/crypto/sha256_base.h wrappers around the now also static inline include/crypto/sha.h functions. Signed-off-by: Hans de Goede --- include/crypto/sha.h | 30 ++++++++++++++++++++++++++++-- include/crypto/sha256_base.h | 24 ++---------------------- lib/crypto/sha256.c | 32 -------------------------------- 3 files changed, 30 insertions(+), 56 deletions(-) diff --git a/include/crypto/sha.h b/include/crypto/sha.h index 535955c84187..5c2132c71900 100644 --- a/include/crypto/sha.h +++ b/include/crypto/sha.h @@ -123,12 +123,38 @@ extern int crypto_sha512_finup(struct shash_desc *desc, const u8 *data, * For details see lib/crypto/sha256.c */ -extern int sha256_init(struct sha256_state *sctx); +static inline int sha256_init(struct sha256_state *sctx) +{ + sctx->state[0] = SHA256_H0; + sctx->state[1] = SHA256_H1; + sctx->state[2] = SHA256_H2; + sctx->state[3] = SHA256_H3; + sctx->state[4] = SHA256_H4; + sctx->state[5] = SHA256_H5; + sctx->state[6] = SHA256_H6; + sctx->state[7] = SHA256_H7; + sctx->count = 0; + + return 0; +} extern int sha256_update(struct sha256_state *sctx, const u8 *input, unsigned int length); extern int sha256_final(struct sha256_state *sctx, u8 *hash); -extern int sha224_init(struct sha256_state *sctx); +static inline int sha224_init(struct sha256_state *sctx) +{ + sctx->state[0] = SHA224_H0; + sctx->state[1] = SHA224_H1; + sctx->state[2] = SHA224_H2; + sctx->state[3] = SHA224_H3; + sctx->state[4] = SHA224_H4; + sctx->state[5] = SHA224_H5; + sctx->state[6] = SHA224_H6; + sctx->state[7] = SHA224_H7; + sctx->count = 0; + + return 0; +} extern int sha224_update(struct sha256_state *sctx, const u8 *input, unsigned int length); extern int sha224_final(struct sha256_state *sctx, u8 *hash); diff --git a/include/crypto/sha256_base.h b/include/crypto/sha256_base.h index 59159bc944f5..b8af853690b9 100644 --- a/include/crypto/sha256_base.h +++ b/include/crypto/sha256_base.h @@ -19,34 +19,14 @@ static inline int sha224_base_init(struct shash_desc *desc) { struct sha256_state *sctx = shash_desc_ctx(desc); - sctx->state[0] = SHA224_H0; - sctx->state[1] = SHA224_H1; - sctx->state[2] = SHA224_H2; - sctx->state[3] = SHA224_H3; - sctx->state[4] = SHA224_H4; - sctx->state[5] = SHA224_H5; - sctx->state[6] = SHA224_H6; - sctx->state[7] = SHA224_H7; - sctx->count = 0; - - return 0; + return sha224_init(sctx); } static inline int sha256_base_init(struct shash_desc *desc) { struct sha256_state *sctx = shash_desc_ctx(desc); - sctx->state[0] = SHA256_H0; - sctx->state[1] = SHA256_H1; - sctx->state[2] = SHA256_H2; - sctx->state[3] = SHA256_H3; - sctx->state[4] = SHA256_H4; - sctx->state[5] = SHA256_H5; - sctx->state[6] = SHA256_H6; - sctx->state[7] = SHA256_H7; - sctx->count = 0; - - return 0; + return sha256_init(sctx); } static inline int sha256_base_do_update(struct shash_desc *desc, diff --git a/lib/crypto/sha256.c b/lib/crypto/sha256.c index 220b74c2bbd8..66cb04b0cf4e 100644 --- a/lib/crypto/sha256.c +++ b/lib/crypto/sha256.c @@ -206,38 +206,6 @@ static void sha256_transform(u32 *state, const u8 *input) memzero_explicit(W, 64 * sizeof(u32)); } -int sha256_init(struct sha256_state *sctx) -{ - sctx->state[0] = SHA256_H0; - sctx->state[1] = SHA256_H1; - sctx->state[2] = SHA256_H2; - sctx->state[3] = SHA256_H3; - sctx->state[4] = SHA256_H4; - sctx->state[5] = SHA256_H5; - sctx->state[6] = SHA256_H6; - sctx->state[7] = SHA256_H7; - sctx->count = 0; - - return 0; -} -EXPORT_SYMBOL(sha256_init); - -int sha224_init(struct sha256_state *sctx) -{ - sctx->state[0] = SHA224_H0; - sctx->state[1] = SHA224_H1; - sctx->state[2] = SHA224_H2; - sctx->state[3] = SHA224_H3; - sctx->state[4] = SHA224_H4; - sctx->state[5] = SHA224_H5; - sctx->state[6] = SHA224_H6; - sctx->state[7] = SHA224_H7; - sctx->count = 0; - - return 0; -} -EXPORT_SYMBOL(sha224_init); - int sha256_update(struct sha256_state *sctx, const u8 *data, unsigned int len) { unsigned int partial, done; -- 2.23.0