Files
linux/lib
Eric Biggers 2e8f7b170a lib/crypto: blake2b: Roll up BLAKE2b round loop on 32-bit
BLAKE2b has a state of 16 64-bit words.  Add the message data in and
there are 32 64-bit words.  With the current code where all the rounds
are unrolled to enable constant-folding of the blake2b_sigma values,
this results in a very large code size on 32-bit kernels, including a
recurring issue where gcc uses a large amount of stack.

There's just not much benefit to this unrolling when the code is already
so large.  Let's roll up the rounds when !CONFIG_64BIT.

To avoid having to duplicate the code, just write the code once using a
loop, and conditionally use 'unrolled_full' from <linux/unroll.h>.

Then, fold the now-unneeded ROUND() macro into the loop.  Finally, also
remove the now-unneeded override of the stack frame size warning.

Code size improvements for blake2b_compress_generic():

                  Size before (bytes)    Size after (bytes)
                  -------------------    ------------------
    i386, gcc           27584                 3632
    i386, clang         18208                 3248
    arm32, gcc          19912                 2860
    arm32, clang        21336                 3344

Running the BLAKE2b benchmark on a !CONFIG_64BIT kernel on an x86_64
processor shows a 16384B throughput change of 351 => 340 MB/s (gcc) or
442 MB/s => 375 MB/s (clang).  So clearly not much of a slowdown either.
But also that microbenchmark also effectively disregards cache usage,
which is important in practice and is far better in the smaller code.

Note: If we rolled up the loop on x86_64 too, the change would be
7024 bytes => 1584 bytes and 1960 MB/s => 1396 MB/s (gcc), or
6848 bytes => 1696 bytes and 1920 MB/s => 1263 MB/s (clang).
Maybe still worth it, though not quite as clearly beneficial.

Fixes: 91d689337f ("crypto: blake2b - add blake2b generic implementation")
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
Link: https://lore.kernel.org/r/20251205050330.89704-1-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
2025-12-09 15:10:21 -08:00
..
2025-03-16 22:30:49 -07:00
2025-04-11 17:32:38 -07:00
2025-04-11 17:32:37 -07:00
2024-07-12 16:39:53 -07:00
2025-11-27 09:32:47 +01:00
2023-02-02 22:50:01 -08:00
2023-02-02 22:50:01 -08:00
2025-07-08 19:11:57 -04:00
2025-03-25 10:18:31 -03:00
2025-01-12 20:21:15 -08:00
2025-01-14 19:45:35 +01:00
2025-10-24 21:39:27 +02:00
2024-10-14 16:33:24 -05:00
2023-10-16 12:44:06 -04:00
2022-10-03 17:34:32 -07:00
2025-03-17 12:17:00 -07:00
2025-11-27 14:24:30 -08:00
2024-02-15 12:17:28 -05:00
2025-03-25 10:18:31 -03:00
2024-12-09 13:48:29 -08:00
2025-09-13 16:54:46 -07:00