public inbox for linux-crypto@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] nvme-auth: use crypto_shash_tfm_digest()
@ 2023-10-29  5:00 Eric Biggers
  2023-10-30 13:28 ` Christoph Hellwig
  2023-10-30 15:03 ` Keith Busch
  0 siblings, 2 replies; 4+ messages in thread
From: Eric Biggers @ 2023-10-29  5:00 UTC (permalink / raw)
  To: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg,
	linux-nvme
  Cc: linux-crypto

From: Eric Biggers <ebiggers@google.com>

Simplify nvme_auth_augmented_challenge() by using
crypto_shash_tfm_digest() instead of an alloc+init+update+final
sequence.  This should also improve performance.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 drivers/nvme/common/auth.c | 23 ++---------------------
 1 file changed, 2 insertions(+), 21 deletions(-)

diff --git a/drivers/nvme/common/auth.c b/drivers/nvme/common/auth.c
index d90e4f0c08b7..54cffbc24b4a 100644
--- a/drivers/nvme/common/auth.c
+++ b/drivers/nvme/common/auth.c
@@ -324,21 +324,20 @@ static int nvme_auth_hash_skey(int hmac_id, u8 *skey, size_t skey_len, u8 *hkey)
 			 skey_len);
 
 	crypto_free_shash(tfm);
 	return ret;
 }
 
 int nvme_auth_augmented_challenge(u8 hmac_id, u8 *skey, size_t skey_len,
 		u8 *challenge, u8 *aug, size_t hlen)
 {
 	struct crypto_shash *tfm;
-	struct shash_desc *desc;
 	u8 *hashed_key;
 	const char *hmac_name;
 	int ret;
 
 	hashed_key = kmalloc(hlen, GFP_KERNEL);
 	if (!hashed_key)
 		return -ENOMEM;
 
 	ret = nvme_auth_hash_skey(hmac_id, skey,
 				  skey_len, hashed_key);
@@ -352,43 +351,25 @@ int nvme_auth_augmented_challenge(u8 hmac_id, u8 *skey, size_t skey_len,
 		ret = -EINVAL;
 		goto out_free_key;
 	}
 
 	tfm = crypto_alloc_shash(hmac_name, 0, 0);
 	if (IS_ERR(tfm)) {
 		ret = PTR_ERR(tfm);
 		goto out_free_key;
 	}
 
-	desc = kmalloc(sizeof(struct shash_desc) + crypto_shash_descsize(tfm),
-		       GFP_KERNEL);
-	if (!desc) {
-		ret = -ENOMEM;
-		goto out_free_hash;
-	}
-	desc->tfm = tfm;
-
 	ret = crypto_shash_setkey(tfm, hashed_key, hlen);
 	if (ret)
-		goto out_free_desc;
-
-	ret = crypto_shash_init(desc);
-	if (ret)
-		goto out_free_desc;
-
-	ret = crypto_shash_update(desc, challenge, hlen);
-	if (ret)
-		goto out_free_desc;
+		goto out_free_hash;
 
-	ret = crypto_shash_final(desc, aug);
-out_free_desc:
-	kfree_sensitive(desc);
+	ret = crypto_shash_tfm_digest(tfm, challenge, hlen, aug);
 out_free_hash:
 	crypto_free_shash(tfm);
 out_free_key:
 	kfree_sensitive(hashed_key);
 	return ret;
 }
 EXPORT_SYMBOL_GPL(nvme_auth_augmented_challenge);
 
 int nvme_auth_gen_privkey(struct crypto_kpp *dh_tfm, u8 dh_gid)
 {

base-commit: 2af9b20dbb39f6ebf9b9b6c090271594627d818e
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-11-20 13:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-29  5:00 [PATCH] nvme-auth: use crypto_shash_tfm_digest() Eric Biggers
2023-10-30 13:28 ` Christoph Hellwig
2023-11-20 13:51   ` Sagi Grimberg
2023-10-30 15:03 ` Keith Busch

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox