Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

nvme-auth: common: use crypto library in nvme_auth_transform_key()

For the HMAC computation in nvme_auth_transform_key(), use the crypto
library instead of crypto_shash. This is simpler, faster, and more
reliable. Notably, this eliminates the transformation object allocation
for every call, which was very slow.

Acked-by: Ard Biesheuvel <ardb@kernel.org>
Acked-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
Signed-off-by: Keith Busch <kbusch@kernel.org>

authored by

Eric Biggers and committed by
Keith Busch
092c05f8 4263ca1c

+10 -43
+10 -43
drivers/nvme/common/auth.c
··· 303 303 struct nvme_dhchap_key *nvme_auth_transform_key( 304 304 const struct nvme_dhchap_key *key, const char *nqn) 305 305 { 306 - const char *hmac_name; 307 - struct crypto_shash *key_tfm; 308 - SHASH_DESC_ON_STACK(shash, key_tfm); 306 + struct nvme_auth_hmac_ctx hmac; 309 307 struct nvme_dhchap_key *transformed_key; 310 308 int ret, key_len; 311 309 ··· 318 320 return ERR_PTR(-ENOMEM); 319 321 return transformed_key; 320 322 } 321 - hmac_name = nvme_auth_hmac_name(key->hash); 322 - if (!hmac_name) { 323 - pr_warn("Invalid key hash id %d\n", key->hash); 324 - return ERR_PTR(-EINVAL); 325 - } 326 - 327 - key_tfm = crypto_alloc_shash(hmac_name, 0, 0); 328 - if (IS_ERR(key_tfm)) 329 - return ERR_CAST(key_tfm); 330 - 331 - key_len = crypto_shash_digestsize(key_tfm); 323 + ret = nvme_auth_hmac_init(&hmac, key->hash, key->key, key->len); 324 + if (ret) 325 + return ERR_PTR(ret); 326 + key_len = nvme_auth_hmac_hash_len(key->hash); 332 327 transformed_key = nvme_auth_alloc_key(key_len, key->hash); 333 328 if (!transformed_key) { 334 - ret = -ENOMEM; 335 - goto out_free_key; 329 + memzero_explicit(&hmac, sizeof(hmac)); 330 + return ERR_PTR(-ENOMEM); 336 331 } 337 - 338 - shash->tfm = key_tfm; 339 - ret = crypto_shash_setkey(key_tfm, key->key, key->len); 340 - if (ret < 0) 341 - goto out_free_transformed_key; 342 - ret = crypto_shash_init(shash); 343 - if (ret < 0) 344 - goto out_free_transformed_key; 345 - ret = crypto_shash_update(shash, nqn, strlen(nqn)); 346 - if (ret < 0) 347 - goto out_free_transformed_key; 348 - ret = crypto_shash_update(shash, "NVMe-over-Fabrics", 17); 349 - if (ret < 0) 350 - goto out_free_transformed_key; 351 - ret = crypto_shash_final(shash, transformed_key->key); 352 - if (ret < 0) 353 - goto out_free_transformed_key; 354 - 355 - crypto_free_shash(key_tfm); 356 - 332 + nvme_auth_hmac_update(&hmac, nqn, strlen(nqn)); 333 + nvme_auth_hmac_update(&hmac, "NVMe-over-Fabrics", 17); 334 + nvme_auth_hmac_final(&hmac, transformed_key->key); 357 335 return transformed_key; 358 - 359 - out_free_transformed_key: 360 - nvme_auth_free_key(transformed_key); 361 - out_free_key: 362 - crypto_free_shash(key_tfm); 363 - 364 - return ERR_PTR(ret); 365 336 } 366 337 EXPORT_SYMBOL_GPL(nvme_auth_transform_key); 367 338