]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
nvme-auth: Hash DH shared secret to create session key
authorChris Leech <cleech@redhat.com>
Wed, 22 Apr 2026 19:06:36 +0000 (12:06 -0700)
committerKeith Busch <kbusch@kernel.org>
Wed, 22 Apr 2026 20:02:16 +0000 (13:02 -0700)
commitbd7b7ce96db4487bb77692a85ee4489fd2c395df
treea83dc705b248a07614685df277d19a79318f72b8
parent1cc4cdae2a3b7730d462d69e30f213fd2efe7807
nvme-auth: Hash DH shared secret to create session key

The NVMe Base Specification 8.3.5.5.9 states that the session key Ks
shall be computed from the ephemeral DH key by applying the hash
function selected by the HashID parameter.

The current implementation stores the raw DH shared secret as the
session key without hashing it. This causes redundant hash operations:

1. Augmented challenge computation (section 8.3.5.5.4) requires
   Ca = HMAC(H(g^xy mod p), C). The code compensates by hashing the
   unhashed session key in nvme_auth_augmented_challenge() to produce
   the correct result.

2. PSK generation (section 8.3.5.5.9) requires PSK = HMAC(Ks, C1 || C2)
   where Ks should already be H(g^xy mod p). As the DH shared secret
   is always larger than the HMAC block size, HMAC internally hashes
   it before use, accidentally producing the correct result.

When using secure channel concatenation with bidirectional
authentication, this results in hashing the DH value three times: twice
for augmented challenge calculations and once during PSK generation.

Fix this by:
- Modifying nvme_auth_gen_shared_secret() to hash the DH shared secret
  once after computation: Ks = H(g^xy mod p)
- Removing the hash operation from nvme_auth_augmented_challenge()
  as the session key is now already hashed
- Updating session key buffer size from DH key size to hash output size
- Adding specification references in comments

This avoid storing the raw DH shared secret and reduces the number of
hash operations from three to one when using secure channel
concatenation.

Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Eric Biggers <ebiggers@kernel.org>
Signed-off-by: Chris Leech <cleech@redhat.com>
Signed-off-by: Keith Busch <kbusch@kernel.org>
drivers/nvme/common/auth.c
drivers/nvme/host/auth.c
drivers/nvme/target/auth.c
include/linux/nvme-auth.h