All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: linux-crypto@vger.kernel.org
Cc: Ard Biesheuvel <ardb@kernel.org>,
	"Jason A . Donenfeld" <Jason@zx2c4.com>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	x86@kernel.org
Subject: Re: [PATCH] lib/crypto: x86/sha512-ssse3: Roll up rounds and reduce stack usage
Date: Fri, 27 Nov 2026 11:04:48 -0800	[thread overview]
Message-ID: <20261127190448.GA8300@quark> (raw)
In-Reply-To: <20261125043159.192004-1-ebiggers@kernel.org>

On Tue, Nov 24, 2026 at 08:31:59PM -0800, Eric Biggers wrote:
> Currently, sha512_transform_ssse3() unrolls all 80 SHA-512 rounds,
> producing 13.4 KB of text.  It also stores all 80 message schedule words
> in a 640-byte stack buffer, which wasn't being zeroized on exit either.
> 
> Shrink both of these to more reasonable sizes (4.7 KB of text, and a
> 136-byte stack buffer that's zeroized on exit) by doing rounds 14
> through 77 in a loop that does 4 iterations of 16 rounds each, and by
> using a circular buffer to hold the message schedule words.
> 
> The circular buffer works well because each message schedule word in
> SHA-512 is computed only from words in the last 16 words.  The number of
> rounds per iteration is set to 16 to match the circular buffer size.
> (It's also a multiple of 8, which is how often the state cycles around.)
> 
> The message schedule could also be stored in XMM registers, but that
> approach was found to add additional overhead on older CPUs.
> 
> Signed-off-by: Eric Biggers <ebiggers@kernel.org>
> ---
> 
> This is an alternative to the series
> https://lore.kernel.org/linux-crypto/20261122022030.296468-1-ebiggers@kernel.org/
> It does 16 rounds per iteration instead of 8, and it replaces the huge
> on-stack buffer with a circular buffer instead of with XMM registers.
> This hopefully avoids any measurable regression on older CPUs, while
> still achieving the two main cleanups.
> 
>  lib/crypto/x86/sha512-ssse3-asm.S | 157 +++++++++++++++++-------------
>  1 file changed, 92 insertions(+), 65 deletions(-)

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux.git/log/?h=libcrypto-next

- Eric

      parent reply	other threads:[~2026-11-27 19:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25  4:31 [PATCH] lib/crypto: x86/sha512-ssse3: Roll up rounds and reduce stack usage Eric Biggers
2026-11-25  7:54 ` Ard Biesheuvel
2026-11-27 19:04 ` Eric Biggers [this message]

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=20261127190448.GA8300@quark \
    --to=ebiggers@kernel.org \
    --cc=Jason@zx2c4.com \
    --cc=ardb@kernel.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=x86@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.