diff options
author | Eric Biggers <ebiggers@kernel.org> | 2025-09-15 11:08:14 -0500 |
---|---|---|
committer | Eric Biggers <ebiggers@kernel.org> | 2025-09-17 13:09:39 -0500 |
commit | 4ca24d6abbca5df76c4b189dd94fb055613de297 (patch) | |
tree | cfcd3f1d5efc964c0548e3b4ab4d9d84d540c232 /scripts/extract-fwblobs | |
parent | f0883b9c395ecdf7e66a58b6027fd35056cf152c (diff) |
lib/crypto: sha256: Add support for 2-way interleaved hashing
Many arm64 and x86_64 CPUs can compute two SHA-256 hashes in nearly the
same speed as one, if the instructions are interleaved. This is because
SHA-256 is serialized block-by-block, and two interleaved hashes take
much better advantage of the CPU's instruction-level parallelism.
Meanwhile, a very common use case for SHA-256 hashing in the Linux
kernel is dm-verity and fs-verity. Both use a Merkle tree that has a
fixed block size, usually 4096 bytes with an empty or 32-byte salt
prepended. Usually, many blocks need to be hashed at a time. This is
an ideal scenario for 2-way interleaved hashing.
To enable this optimization, add a new function sha256_finup_2x() to the
SHA-256 library API. It computes the hash of two equal-length messages,
starting from a common initial context.
For now it always falls back to sequential processing. Later patches
will wire up arm64 and x86_64 optimized implementations.
Note that the interleaving factor could in principle be higher than 2x.
However, that runs into many practical difficulties and CPU throughput
limitations. Thus, both the implementations I'm adding are 2x. In the
interest of using the simplest solution, the API matches that.
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
Link: https://lore.kernel.org/r/20250915160819.140019-2-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
Diffstat (limited to 'scripts/extract-fwblobs')
0 files changed, 0 insertions, 0 deletions