fscrypt and NVMe authentication each carry private HKDF
implementations. Add HKDF-SHA256, HKDF-SHA384, and HKDF-SHA512
functions to lib/crypto and convert both users.
Patches 1-4 are intended for review and inclusion.
Patch 5 is RFC only and is not intended to be applied. It shows how
the OVPN epoch-key code currently under development can use the new
HKDF API. That patch has an additional dependency on the OVPN epoch
series. It is included here to allow the API to be reviewed against
a third user. The OVPN conversion will be submitted separately once
its prerequisite code is ready.
HKDF-Expand accepts info as an array of segments and processes them as
if concatenated. This preserves the byte ordering used by fscrypt and
allows NVMe to encode HkdfLabel without allocating a temporary buffer.
HKDF-Extract produces a prepared HMAC key, avoiding repeated key setup
when the same PRK is expanded more than once. The implementation uses
the direct HMAC library functions and neither allocates memory nor
returns errors.
The series is intended for the libcrypto tree. Patches 3 and 4 need
review from the fscrypt and NVMe maintainers, respectively.
Tested with:
- HKDF KUnit tests
- NVMe authentication KUnit tests
- kvm-xfstests smoketest on ext4
- kvm-xfstests generic/582, generic/583, and generic/584 on ext4 and f2fs
- kvm-xfstests encrypt group on ext4 and f2fs
The following shortlog and diffstat refers only to the first 4 patches.
Marco Baffo (4):
lib/crypto: add HKDF-SHA{256,384,512}
lib/crypto: tests: add HKDF KUnit tests
fscrypt: use HKDF library functions
nvme-auth: use HKDF library functions for TLS PSK derivation
drivers/nvme/common/auth.c | 120 ++++++++-------
fs/crypto/hkdf.c | 56 ++-----
include/crypto/hkdf.h | 131 ++++++++++++++++
lib/crypto/.kunitconfig | 1 +
lib/crypto/Makefile | 4 +-
lib/crypto/hkdf-sha256.c | 22 +++
lib/crypto/hkdf-sha512.c | 34 +++++
lib/crypto/hkdf-template.h | 97 ++++++++++++
lib/crypto/tests/Kconfig | 8 +
lib/crypto/tests/Makefile | 1 +
lib/crypto/tests/hkdf_kunit.c | 276 ++++++++++++++++++++++++++++++++++
11 files changed, 653 insertions(+), 97 deletions(-)
create mode 100644 include/crypto/hkdf.h
create mode 100644 lib/crypto/hkdf-sha256.c
create mode 100644 lib/crypto/hkdf-sha512.c
create mode 100644 lib/crypto/hkdf-template.h
create mode 100644 lib/crypto/tests/hkdf_kunit.c
base-commit: e4f23159c8d09b6b15d47f2c95e0a3e7c62f52a2
--
2.43.0