Commit 744eac78 authored by Eric Biggers's avatar Eric Biggers Committed by Keith Busch

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: default avatarEric Biggers <ebiggers@google.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarKeith Busch <kbusch@kernel.org>
parent d2f51b35
...@@ -341,7 +341,6 @@ int nvme_auth_augmented_challenge(u8 hmac_id, u8 *skey, size_t skey_len, ...@@ -341,7 +341,6 @@ int nvme_auth_augmented_challenge(u8 hmac_id, u8 *skey, size_t skey_len,
u8 *challenge, u8 *aug, size_t hlen) u8 *challenge, u8 *aug, size_t hlen)
{ {
struct crypto_shash *tfm; struct crypto_shash *tfm;
struct shash_desc *desc;
u8 *hashed_key; u8 *hashed_key;
const char *hmac_name; const char *hmac_name;
int ret; int ret;
...@@ -369,29 +368,11 @@ int nvme_auth_augmented_challenge(u8 hmac_id, u8 *skey, size_t skey_len, ...@@ -369,29 +368,11 @@ int nvme_auth_augmented_challenge(u8 hmac_id, u8 *skey, size_t skey_len,
goto out_free_key; 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); ret = crypto_shash_setkey(tfm, hashed_key, hlen);
if (ret) if (ret)
goto out_free_desc; goto out_free_hash;
ret = crypto_shash_init(desc);
if (ret)
goto out_free_desc;
ret = crypto_shash_update(desc, challenge, hlen);
if (ret)
goto out_free_desc;
ret = crypto_shash_final(desc, aug); ret = crypto_shash_tfm_digest(tfm, challenge, hlen, aug);
out_free_desc:
kfree_sensitive(desc);
out_free_hash: out_free_hash:
crypto_free_shash(tfm); crypto_free_shash(tfm);
out_free_key: out_free_key:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment