From: Eric Biggers <ebiggers@kernel.org>
To: Arvind Sankar <nivedita@alum.mit.edu>
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>,
"linux-crypto@vger.kernel.org" <linux-crypto@vger.kernel.org>,
David Laight <David.Laight@aculab.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 6/6] crypto: lib/sha - Combine round constants and message schedule
Date: Wed, 21 Oct 2020 21:34:50 -0700 [thread overview]
Message-ID: <20201022043450.GC857@sol.localdomain> (raw)
In-Reply-To: <20201020203957.3512851-7-nivedita@alum.mit.edu>
On Tue, Oct 20, 2020 at 04:39:57PM -0400, Arvind Sankar wrote:
> Putting the round constants and the message schedule arrays together in
> one structure saves one register, which can be a significant benefit on
> register-constrained architectures. On x86-32 (tested on Broadwell
> Xeon), this gives a 10% performance benefit.
>
> Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu>
> Suggested-by: David Laight <David.Laight@ACULAB.COM>
> ---
> lib/crypto/sha256.c | 49 ++++++++++++++++++++++++++-------------------
> 1 file changed, 28 insertions(+), 21 deletions(-)
>
> diff --git a/lib/crypto/sha256.c b/lib/crypto/sha256.c
> index 3a8802d5f747..985cd0560d79 100644
> --- a/lib/crypto/sha256.c
> +++ b/lib/crypto/sha256.c
> @@ -29,6 +29,11 @@ static const u32 SHA256_K[] = {
> 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
> };
>
> +struct KW {
> + u32 K[64];
> + u32 W[64];
> +};
Note that this doubles the stack usage from 256 to 512 bytes. That's pretty
large for kernel code, especially when compiler options can increase the stack
usage well beyond the "expected" value.
So unless this gives a big performance improvement on architectures other than
32-bit x86 (which people don't really care about these days), we probably
shouldn't do this.
FWIW, it's possible to reduce the length of 'W' to 16 words by computing the
next W value just before each round 16-63, or by computing the next W values in
batches of 16 before rounds 16, 32, and 48. (This is similar to what lib/sha1.c
does for SHA-1.) In a quick userspace benchmark that seems to reduce
performance by about 25% on x86_64, though.
- Eric
next prev parent reply other threads:[~2020-10-22 4:34 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-20 20:39 [PATCH v2 0/6] crypto: lib/sha256 - cleanup/optimization Arvind Sankar
2020-10-20 20:39 ` [PATCH v2 1/6] crypto: Use memzero_explicit() for clearing state Arvind Sankar
2020-10-22 4:36 ` Eric Biggers
2020-10-23 15:39 ` Arvind Sankar
2020-10-23 15:56 ` Eric Biggers
2020-10-23 20:45 ` Herbert Xu
2020-10-23 21:53 ` Eric Biggers
2020-10-29 7:00 ` Herbert Xu
2020-10-20 20:39 ` [PATCH v2 2/6] crypto: lib/sha256 - Don't clear temporary variables Arvind Sankar
2020-10-22 4:58 ` Eric Biggers
2020-10-23 3:17 ` Arvind Sankar
2020-10-20 20:39 ` [PATCH v2 3/6] crypto: lib/sha256 - Clear W[] in sha256_update() instead of sha256_transform() Arvind Sankar
2020-10-22 4:59 ` Eric Biggers
2020-10-20 20:39 ` [PATCH v2 4/6] crypto: lib/sha256 - Unroll SHA256 loop 8 times intead of 64 Arvind Sankar
2020-10-22 5:02 ` Eric Biggers
2020-10-23 3:12 ` Arvind Sankar
2020-10-23 3:16 ` Herbert Xu
2020-10-20 20:39 ` [PATCH v2 5/6] crypto: lib/sha256 - Unroll LOAD and BLEND loops Arvind Sankar
2020-10-22 5:02 ` Eric Biggers
2020-10-20 20:39 ` [PATCH v2 6/6] crypto: lib/sha - Combine round constants and message schedule Arvind Sankar
2020-10-20 21:36 ` David Laight
2020-10-21 15:16 ` Arvind Sankar
2020-10-22 4:34 ` Eric Biggers [this message]
2020-10-22 8:20 ` David Laight
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201022043450.GC857@sol.localdomain \
--to=ebiggers@kernel.org \
--cc=David.Laight@aculab.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nivedita@alum.mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox