lib/crypto: sha2: Add hmac_sha*_init_usingrawkey()
authorEric Biggers <ebiggers@kernel.org>
Fri, 11 Jul 2025 21:58:43 +0000 (14:58 -0700)
committerEric Biggers <ebiggers@kernel.org>
Mon, 14 Jul 2025 15:20:37 +0000 (08:20 -0700)
commit7941ad696506917fa6228f44be2df0c2f0909a62
tree615fc21f7dea8b8ea5b975bc522fa1f72950c513
parent6e07c5e166597de1d7943ecf2539cad18c0e2ce1
lib/crypto: sha2: Add hmac_sha*_init_usingrawkey()

While the HMAC library functions support both incremental and one-shot
computation and both prepared and raw keys, the combination of raw key
+ incremental was missing.  It turns out that several potential users of
the HMAC library functions (tpm2-sessions.c, smb2transport.c,
trusted_tpm1.c) want exactly that.

Therefore, add the missing functions hmac_sha*_init_usingrawkey().

Implement them in an optimized way that directly initializes the HMAC
context without a separate key preparation step.

Reimplement the one-shot raw key functions hmac_sha*_usingrawkey() on
top of the new functions, which makes them a bit more efficient.

Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
Link: https://lore.kernel.org/r/20250711215844.41715-1-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
include/crypto/sha2.h
lib/crypto/sha256.c
lib/crypto/sha512.c