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

crypto: authencesn - use crypto_grab_ahash() and simplify error paths

Make the authencesn template use the new function crypto_grab_ahash() to
initialize its ahash spawn.

This is needed to make all spawns be initialized in a consistent way.

Also simplify the error handling by taking advantage of crypto_drop_*()
now accepting (as a no-op) spawns that haven't been initialized yet, and
by taking advantage of crypto_grab_*() now handling ERR_PTR() names.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Eric Biggers and committed by
Herbert Xu
37073882 37a861ad

+14 -38
+14 -38
crypto/authencesn.c
··· 393 393 struct crypto_attr_type *algt; 394 394 u32 mask; 395 395 struct aead_instance *inst; 396 + struct authenc_esn_instance_ctx *ctx; 396 397 struct hash_alg_common *auth; 397 398 struct crypto_alg *auth_base; 398 399 struct skcipher_alg *enc; 399 - struct authenc_esn_instance_ctx *ctx; 400 - const char *enc_name; 401 400 int err; 402 401 403 402 algt = crypto_get_attr_type(tb); ··· 408 409 409 410 mask = crypto_requires_sync(algt->type, algt->mask); 410 411 411 - auth = ahash_attr_alg(tb[1], CRYPTO_ALG_TYPE_HASH, 412 - CRYPTO_ALG_TYPE_AHASH_MASK | mask); 413 - if (IS_ERR(auth)) 414 - return PTR_ERR(auth); 415 - 416 - auth_base = &auth->base; 417 - 418 - enc_name = crypto_attr_alg_name(tb[2]); 419 - err = PTR_ERR(enc_name); 420 - if (IS_ERR(enc_name)) 421 - goto out_put_auth; 422 - 423 412 inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL); 424 - err = -ENOMEM; 425 413 if (!inst) 426 - goto out_put_auth; 427 - 414 + return -ENOMEM; 428 415 ctx = aead_instance_ctx(inst); 429 416 430 - err = crypto_init_ahash_spawn(&ctx->auth, auth, 431 - aead_crypto_instance(inst)); 417 + err = crypto_grab_ahash(&ctx->auth, aead_crypto_instance(inst), 418 + crypto_attr_alg_name(tb[1]), 0, mask); 432 419 if (err) 433 420 goto err_free_inst; 421 + auth = crypto_spawn_ahash_alg(&ctx->auth); 422 + auth_base = &auth->base; 434 423 435 424 err = crypto_grab_skcipher(&ctx->enc, aead_crypto_instance(inst), 436 - enc_name, 0, mask); 425 + crypto_attr_alg_name(tb[2]), 0, mask); 437 426 if (err) 438 - goto err_drop_auth; 439 - 427 + goto err_free_inst; 440 428 enc = crypto_spawn_skcipher_alg(&ctx->enc); 441 429 442 430 err = -ENAMETOOLONG; 443 431 if (snprintf(inst->alg.base.cra_name, CRYPTO_MAX_ALG_NAME, 444 432 "authencesn(%s,%s)", auth_base->cra_name, 445 433 enc->base.cra_name) >= CRYPTO_MAX_ALG_NAME) 446 - goto err_drop_enc; 434 + goto err_free_inst; 447 435 448 436 if (snprintf(inst->alg.base.cra_driver_name, CRYPTO_MAX_ALG_NAME, 449 437 "authencesn(%s,%s)", auth_base->cra_driver_name, 450 438 enc->base.cra_driver_name) >= CRYPTO_MAX_ALG_NAME) 451 - goto err_drop_enc; 439 + goto err_free_inst; 452 440 453 441 inst->alg.base.cra_flags = (auth_base->cra_flags | 454 442 enc->base.cra_flags) & CRYPTO_ALG_ASYNC; ··· 461 475 inst->free = crypto_authenc_esn_free, 462 476 463 477 err = aead_register_instance(tmpl, inst); 464 - if (err) 465 - goto err_drop_enc; 466 - 467 - out: 468 - crypto_mod_put(auth_base); 469 - return err; 470 - 471 - err_drop_enc: 472 - crypto_drop_skcipher(&ctx->enc); 473 - err_drop_auth: 474 - crypto_drop_ahash(&ctx->auth); 478 + if (err) { 475 479 err_free_inst: 476 - kfree(inst); 477 - out_put_auth: 478 - goto out; 480 + crypto_authenc_esn_free(inst); 481 + } 482 + return err; 479 483 } 480 484 481 485 static struct crypto_template crypto_authenc_esn_tmpl = {