[PATCH 15/21] nvme-auth: host: remove allocation of crypto_shash

Eric Biggers
2026-03-02T08:01:34Z

Now that the crypto_shash that is being allocated in
nvme_auth_process_dhchap_challenge() and stored in the
struct nvme_dhchap_queue_context is no longer used, remove it.

Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---
drivers/nvme/host/auth.c | 29 ++---------------------------
1 file changed, 2 insertions(+), 27 deletions(-)

diff --git a/drivers/nvme/host/auth.c b/drivers/nvme/host/auth.c
index 2f27f550a7442..c8cd633cb0eae 100644
--- a/drivers/nvme/host/auth.c
+++ b/drivers/nvme/host/auth.c
@@ -5,11 +5,10 @@

#include <linux/crc32.h>
#include <linux/base64.h>
#include <linux/prandom.h>
#include <linux/unaligned.h>
-#include <crypto/hash.h>
#include <crypto/dh.h>
#include "nvme.h"
#include "fabrics.h"
#include <linux/nvme-auth.h>
#include <linux/nvme-keyring.h>
@@ -20,11 +19,10 @@ static mempool_t *nvme_chap_buf_pool;

struct nvme_dhchap_queue_context {
struct list_head entry;
struct work_struct auth_work;
struct nvme_ctrl *ctrl;
- struct crypto_shash *shash_tfm;
struct crypto_kpp *dh_tfm;
struct nvme_dhchap_key *transformed_key;
void *buf;
int qid;
int error;
@@ -181,42 +179,21 @@ static int nvme_auth_process_dhchap_challenge(struct nvme_ctrl *ctrl,
chap->qid, data->hashid);
chap->status = NVME_AUTH_DHCHAP_FAILURE_HASH_UNUSABLE;
return -EPROTO;
}

- if (chap->hash_id == data->hashid && chap->shash_tfm &&
- !strcmp(crypto_shash_alg_name(chap->shash_tfm), hmac_name) &&
- crypto_shash_digestsize(chap->shash_tfm) == data->hl) {
+ if (chap->hash_id == data->hashid && chap->hash_len == data->hl) {
dev_dbg(ctrl->device,
"qid %d: reuse existing hash %s\n",
chap->qid, hmac_name);
goto select_kpp;
}

- /* Reset if hash cannot be reused */
- if (chap->shash_tfm) {
- crypto_free_shash(chap->shash_tfm);
- chap->hash_id = 0;
- chap->hash_len = 0;
- }
- chap->shash_tfm = crypto_alloc_shash(hmac_name, 0,
- CRYPTO_ALG_ALLOCATES_MEMORY);
- if (IS_ERR(chap->shash_tfm)) {
- dev_warn(ctrl->device,
- "qid %d: failed to allocate hash %s, error %ld\n",
- chap->qid, hmac_name, PTR_ERR(chap->shash_tfm));
- chap->shash_tfm = NULL;
- chap->status = NVME_AUTH_DHCHAP_FAILURE_FAILED;
- return -ENOMEM;
- }
-
- if (crypto_shash_digestsize(chap->shash_tfm) != data->hl) {
+ if (nvme_auth_hmac_hash_len(data->hashid) != data->hl) {
dev_warn(ctrl->device,
"qid %d: invalid hash length %d\n",
chap->qid, data->hl);
- crypto_free_shash(chap->shash_tfm);
- chap->shash_tfm = NULL;
chap->status = NVME_AUTH_DHCHAP_FAILURE_HASH_UNUSABLE;
return -EPROTO;
}

chap->hash_id = data->hashid;
@@ -656,12 +633,10 @@ static void nvme_auth_reset_dhchap(struct nvme_dhchap_queue_context *chap)

static void nvme_auth_free_dhchap(struct nvme_dhchap_queue_context *chap)
{
nvme_auth_reset_dhchap(chap);
chap->authenticated = false;
- if (chap->shash_tfm)
- crypto_free_shash(chap->shash_tfm);
if (chap->dh_tfm)
crypto_free_kpp(chap->dh_tfm);
}

void nvme_auth_revoke_tls_key(struct nvme_ctrl *ctrl)
--
2.53.0