dm-verity: use SHA-256 library for SHA-256
authorEric Biggers <ebiggers@kernel.org>
Tue, 14 Oct 2025 21:16:55 +0000 (14:16 -0700)
committerMikulas Patocka <mpatocka@redhat.com>
Mon, 20 Oct 2025 13:47:27 +0000 (15:47 +0200)
commitba0f428c9b40364f1af92523860c787068987b8c
treebccffbcfd67b96d321b0d5c487b2b5f95935cd58
parent3ee6c4bc5307d9fcc681dc7ee15822a54b94b39c
dm-verity: use SHA-256 library for SHA-256

When the hash algorithm is SHA-256 and the verity version is not 0, use
the SHA-256 library instead of crypto_shash.

This is a prerequisite for making dm-verity interleave the computation
of SHA-256 hashes for increased performance.  That optimization is
available in the SHA-256 library but not in crypto_shash.

Even without interleaved hashing, switching to the library also slightly
improves performance by itself because it avoids the overhead of
crypto_shash, including indirect calls and other API overhead.
(Benchmark on x86_64, AMD Zen 5: hashing 4K blocks gets 2.1% faster.)

SHA-256 is by far the most common hash algorithm used with dm-verity.
It makes sense to optimize for the common case and fall back to the
generic crypto layer for uncommon cases, as suggested by Linus:
https://lore.kernel.org/r/CAHk-=wgp-fOSsZsYrbyzqCAfEvrt5jQs1jL-97Wc4seMNTUyng@mail.gmail.com

Signed-off-by: Eric Biggers <ebiggers@kernel.org>
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
drivers/md/Kconfig
drivers/md/dm-verity-target.c
drivers/md/dm-verity.h