From: Eric Biggers <ebiggers@kernel.org>
To: Chris Leech <cleech@redhat.com>
Cc: linux-nvme@lists.infradead.org, Hannes Reinecke <hare@suse.de>,
Keith Busch <kbusch@kernel.org>, Christoph Hellwig <hch@lst.de>,
Sagi Grimberg <sagi@grimberg.me>,
Chaitanya Kulkarni <kch@nvidia.com>
Subject: Re: [PATCH] nvme-auth: Hash DH shared secret to create session key
Date: Tue, 10 Mar 2026 22:13:40 -0700 [thread overview]
Message-ID: <20260311051340.GA2270@sol> (raw)
In-Reply-To: <20260311012116.2504291-1-cleech@redhat.com>
On Tue, Mar 10, 2026 at 06:21:16PM -0700, Chris Leech wrote:
> +/**
> + * nvme_auth_gen_session_key() - Generate an ephemeral session key
> + * @dh_tfm: Diffie-Hellman transform with local private key already set
> + * @ctrl_key: Peer's public key
> + * @ctrl_key_len: Length of @ctrl_key
> + * @sess_key: Output buffer for the session key
> + * @sess_key_len: Size of @sess_key buffer
> + * @hash_id: Hash algorithm identifier
> + *
> + * NVMe base specification 8.3.5.5.9: The session key Ks shall be computed from
> + * the ephemeral DH key (i.e., g^xy mod p) ... by applying the hash function
> + * H() selected by the HashID parameter ... (i.e., Ks = H(g^xy mod p)).
> + *
> + * Return: 0 on success, negative errno on failure.
> + */
> +int nvme_auth_gen_session_key(struct crypto_kpp *dh_tfm,
> const u8 *ctrl_key, size_t ctrl_key_len,
ctrl_key and ctrl_key_len should be public_key and public_key_len. It
is the public key of the other side, which can be either the host or the
controller.
> + hash_len = nvme_auth_hmac_hash_len(hash_id);
> + if (!hash_len) {
> + pr_warn("%s: invalid hash algorithm %d\n", __func__, hash_id);
> + return -EINVAL;
> + }
> +
> + if (sess_key_len < hash_len) {
> + pr_warn("%s: sess_key buffer too small (%zu < %zu)\n",
> + __func__, sess_key_len, hash_len);
> + return -EINVAL;
> + }
Probably should be tightened to 'sess_key_len != hash_len', since this
function writes to exactly hash_len bytes and does not report the length
it actually wrote.
- Eric
next prev parent reply other threads:[~2026-03-11 5:14 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-11 1:21 [PATCH] nvme-auth: Hash DH shared secret to create session key Chris Leech
2026-03-11 5:13 ` Eric Biggers [this message]
2026-03-11 15:47 ` Martin George
2026-03-11 16:44 ` Chris Leech
2026-03-12 6:57 ` Hannes Reinecke
2026-03-11 23:16 ` [PATCH v2] " Chris Leech
2026-03-12 4:09 ` Eric Biggers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260311051340.GA2270@sol \
--to=ebiggers@kernel.org \
--cc=cleech@redhat.com \
--cc=hare@suse.de \
--cc=hch@lst.de \
--cc=kbusch@kernel.org \
--cc=kch@nvidia.com \
--cc=linux-nvme@lists.infradead.org \
--cc=sagi@grimberg.me \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox