Skip to content

Fixup HKDF-Expand-Label algorithm#1051

Merged
igaw merged 5 commits intolinux-nvme:masterfrom
hreinecke:hkdf-fixes
Aug 22, 2025
Merged

Fixup HKDF-Expand-Label algorithm#1051
igaw merged 5 commits intolinux-nvme:masterfrom
hreinecke:hkdf-fixes

Conversation

@hreinecke
Copy link
Copy Markdown
Collaborator

Hi all,

here's my attempt to fixup the HKDF-Expand-Label algorithm. The first patch (from Chris Leech) implements the RFC-conformant algorithm for HKDF-Expand-Label, and the second patch adds back the original implementation via a new function nvme_import_tls_key_compat()

@hreinecke hreinecke force-pushed the hkdf-fixes branch 4 times, most recently from 2de5ac3 to d3a4104 Compare August 19, 2025 12:21
hreinecke and others added 5 commits August 19, 2025 14:42
If nvme_generate_tls_key_identity() fails we should set errno to return
a more detailed error to the caller.

Signed-off-by: Hannes Reinecke <[email protected]>
Add a testcase for TLS identity derivation to catch errors from the
HKDF-Expand-Label algorithm changes.

Signed-off-by: Hannes Reinecke <[email protected]>
The function __nvme_insert_tls_key() is only called from
__nvme_import_keys_from_config(), so rename it to __nvme_import_tls_key()
to avoid a name clash with __nvme_insert_tls_key_versioned().

Signed-off-by: Hannes Reinecke <[email protected]>
…key()

Rename to shorten the function name for better readability.

Signed-off-by: Hannes Reinecke <[email protected]>
There are issues with the Retained and TLS PSK derivations due to the
implementation not adhering to the RFC 8446 definition of the
HKDF-Expand-Label function.

  1) The 16-bit HkdfLabel.length value must be converted to network byte
     order.

  2) The variable length HkdfLabel.label and HkdfLabel.context vectors
     must be prefixed with a length byte.

To not break existing implementations keep the original algorithms with
as compat versions and update the 'psk' testcase to cover both versions.

Signed-off-by: Chris Leech <[email protected]>
Signed-off-by: Hannes Reinecke <[email protected]>
@igaw
Copy link
Copy Markdown
Collaborator

igaw commented Aug 22, 2025

Alright, not much else we can do here.

Looks good. Thanks!

@igaw igaw merged commit fde6b1f into linux-nvme:master Aug 22, 2025
11 of 12 checks passed
@igaw
Copy link
Copy Markdown
Collaborator

igaw commented Aug 22, 2025

strange one build on mainline failed in the psk tests:

https://github.com/linux-nvme/libnvme/actions/runs/17155560911/job/48671470694

I can also reproduce it locally with

./scripts/build.sh fallback

@igaw
Copy link
Copy Markdown
Collaborator

igaw commented Aug 22, 2025

› meson test -C .build-ci psk  -v
ninja: Entering directory `/home/wagi/work/libnvme-upstream/.build-ci'
ninja: no work to do.
1/1 libnvme / psk RUNNING
>>> MALLOC_PERTURB_=198 MSAN_OPTIONS=halt_on_error=1:abort_on_error=1:print_summary=1:print_stacktrace=1 LD_LIBRARY_PATH=/home/wagi/work/libnvme-upstream/.build-ci/subprojects/openssl-3.0.8:/home/wagi/work/libnvme-upstream/.build-ci/src:/home/wagi/work/libnvme-upstream/.build-ci/subprojects/json-c-0.18 ASAN_OPTIONS=halt_on_error=1:abort_on_error=1:print_summary=1 UBSAN_OPTIONS=halt_on_error=1:abort_on_error=1:print_summary=1:print_stacktrace=1 MESON_TEST_ITERATION=1 /home/wagi/work/libnvme-upstream/.build-ci/test/test-psk
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― ✀  ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
test nvme_export_tls_key hmac 1 NVMeTLSkey-1:01:VRLbtnN9AQb2WXW3c9+wEf/DRLz0QuLdbYvEhwtdWwNf9LrZ:
test nvme_export_tls_key hmac 2 NVMeTLSkey-1:02:VRLbtnN9AQb2WXW3c9+wEf/DRLz0QuLdbYvEhwtdWwP/w0S89ELi3W2LxIcLXVsDn8kXZQ==:
test nvme_import_tls_key hmac 1 NVMeTLSkey-1:01:VRLbtnN9AQb2WXW3c9+wEf/DRLz0QuLdbYvEhwtdWwNf9LrZ:
test nvme_import_tls_key hmac 2 NVMeTLSkey-1:02:VRLbtnN9AQb2WXW3c9+wEf/DRLz0QuLdbYvEhwtdWwP/w0S89ELi3W2LxIcLXVsDn8kXZQ==:
test nvme_export_tls_key_versioned hmac 0 NVMeTLSkey-1:00:VRLbtnN9AQb2WXW3c9+wEf/DRLz0QuLdbYvEhwtdWwNf9LrZ:
test nvme_export_tls_key_versioned hmac 1 NVMeTLSkey-1:01:VRLbtnN9AQb2WXW3c9+wEf/DRLz0QuLdbYvEhwtdWwNf9LrZ:
test nvme_export_tls_key_versioned hmac 2 NVMeTLSkey-1:02:VRLbtnN9AQb2WXW3c9+wEf/DRLz0QuLdbYvEhwtdWwP/w0S89ELi3W2LxIcLXVsDn8kXZQ==:
test nvme_import_tls_key_versioned hmac 0 NVMeTLSkey-1:00:VRLbtnN9AQb2WXW3c9+wEf/DRLz0QuLdbYvEhwtdWwNf9LrZ:
test nvme_import_tls_key_versioned hmac 1 NVMeTLSkey-1:01:VRLbtnN9AQb2WXW3c9+wEf/DRLz0QuLdbYvEhwtdWwNf9LrZ:
test nvme_import_tls_key_versioned hmac 2 NVMeTLSkey-1:02:VRLbtnN9AQb2WXW3c9+wEf/DRLz0QuLdbYvEhwtdWwP/w0S89ELi3W2LxIcLXVsDn8kXZQ==:
test nvme_generate_tls_key_identity host nqn.psk-test-host subsys nqn.psk-test-subsys hmac 1 NVMe1R01 nqn.psk-test-host nqn.psk-test-subsys iSbjiStwJ/1TrTvDlt2fjFmzvsytOJelidNnA+X5lEU=
ERROR: got 'NVMe1R01 nqn.psk-test-host nqn.psk-test-subsys mJUDthe4jhFVFSnaBaydV/EHJK6OvIuw8xap5IkTnG0=', expected 'NVMe1R01 nqn.psk-test-host nqn.psk-test-subsys iSbjiStwJ/1TrTvDlt2fjFmzvsytOJelidNnA+X5lEU='
test nvme_generate_tls_key_identity host nqn.psk-test-host subsys nqn.psk-test-subsys hmac 2 NVMe1R02 nqn.psk-test-host nqn.psk-test-subsys QhW2+Rp6RzHlNtCslyRxMnwJ11tKKhz8JCAQpQ+XUD8f9td1VeH5h53yz2wKJG1a
ERROR: got 'NVMe1R02 nqn.psk-test-host nqn.psk-test-subsys J6B5sIVRCNLtZutDfmNnfPeqOFbnewwc8KEkhcOcO0dAWfdJYe/DrMyIC7znu00M', expected 'NVMe1R02 nqn.psk-test-host nqn.psk-test-subsys QhW2+Rp6RzHlNtCslyRxMnwJ11tKKhz8JCAQpQ+XUD8f9td1VeH5h53yz2wKJG1a'
test nvme_generate_tls_key_identity_compat host nqn.psk-test-host subsys nqn.psk-test-subsys hmac 1 NVMe1R01 nqn.psk-test-host nqn.psk-test-subsys 66GuqV08TsAGII39teWUfwQwizjv06Jy8jOcX3NAAzM=
ERROR: got 'NVMe1R01 nqn.psk-test-host nqn.psk-test-subsys mJUDthe4jhFVFSnaBaydV/EHJK6OvIuw8xap5IkTnG0=', expected 'NVMe1R01 nqn.psk-test-host nqn.psk-test-subsys 66GuqV08TsAGII39teWUfwQwizjv06Jy8jOcX3NAAzM='
test nvme_generate_tls_key_identity_compat host nqn.psk-test-host subsys nqn.psk-test-subsys hmac 2 NVMe1R02 nqn.psk-test-host nqn.psk-test-subsys RsKmYJ3nAn1ApjjMloJFbAkLPivONDAX/xW327YBUsn2eGShXSjCZvBaOxscLqmz
ERROR: got 'NVMe1R02 nqn.psk-test-host nqn.psk-test-subsys J6B5sIVRCNLtZutDfmNnfPeqOFbnewwc8KEkhcOcO0dAWfdJYe/DrMyIC7znu00M', expected 'NVMe1R02 nqn.psk-test-host nqn.psk-test-subsys RsKmYJ3nAn1ApjjMloJFbAkLPivONDAX/xW327YBUsn2eGShXSjCZvBaOxscLqmz'
――――――――――――――――――――――――――――――――――――――――――――――――――――――――

@igaw
Copy link
Copy Markdown
Collaborator

igaw commented Aug 22, 2025

This might be related with the openssl version which is pulled in via the fallback mechanism.

@igaw
Copy link
Copy Markdown
Collaborator

igaw commented Aug 22, 2025

The fallback uses OpenSSL-3.0.8 which is not the latest in the LTS branch but still supported in upstream.

So we either update the dependency on OpenSSL correctly or make the code backwards compatible with OpenSSL 3.0.x LTS version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants