Skip to content

Commit 744eac7

Browse files
ebiggerskeithbusch
authored andcommitted
nvme-auth: use crypto_shash_tfm_digest()
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 <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Keith Busch <[email protected]>
1 parent d2f51b3 commit 744eac7

File tree

1 file changed

+2
-21
lines changed

1 file changed

+2
-21
lines changed

drivers/nvme/common/auth.c

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,6 @@ int nvme_auth_augmented_challenge(u8 hmac_id, u8 *skey, size_t skey_len,
341341
u8 *challenge, u8 *aug, size_t hlen)
342342
{
343343
struct crypto_shash *tfm;
344-
struct shash_desc *desc;
345344
u8 *hashed_key;
346345
const char *hmac_name;
347346
int ret;
@@ -369,29 +368,11 @@ int nvme_auth_augmented_challenge(u8 hmac_id, u8 *skey, size_t skey_len,
369368
goto out_free_key;
370369
}
371370

372-
desc = kmalloc(sizeof(struct shash_desc) + crypto_shash_descsize(tfm),
373-
GFP_KERNEL);
374-
if (!desc) {
375-
ret = -ENOMEM;
376-
goto out_free_hash;
377-
}
378-
desc->tfm = tfm;
379-
380371
ret = crypto_shash_setkey(tfm, hashed_key, hlen);
381372
if (ret)
382-
goto out_free_desc;
383-
384-
ret = crypto_shash_init(desc);
385-
if (ret)
386-
goto out_free_desc;
387-
388-
ret = crypto_shash_update(desc, challenge, hlen);
389-
if (ret)
390-
goto out_free_desc;
373+
goto out_free_hash;
391374

392-
ret = crypto_shash_final(desc, aug);
393-
out_free_desc:
394-
kfree_sensitive(desc);
375+
ret = crypto_shash_tfm_digest(tfm, challenge, hlen, aug);
395376
out_free_hash:
396377
crypto_free_shash(tfm);
397378
out_free_key:

0 commit comments

Comments
 (0)