crypto: authenc - use crypto_grab_ahash() and simplify error paths
Make the authenc 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>
This commit is contained in:
parent
39e7a283b3
commit
37a861adc9
|
@ -375,11 +375,10 @@ static int crypto_authenc_create(struct crypto_template *tmpl,
|
||||||
struct crypto_attr_type *algt;
|
struct crypto_attr_type *algt;
|
||||||
u32 mask;
|
u32 mask;
|
||||||
struct aead_instance *inst;
|
struct aead_instance *inst;
|
||||||
|
struct authenc_instance_ctx *ctx;
|
||||||
struct hash_alg_common *auth;
|
struct hash_alg_common *auth;
|
||||||
struct crypto_alg *auth_base;
|
struct crypto_alg *auth_base;
|
||||||
struct skcipher_alg *enc;
|
struct skcipher_alg *enc;
|
||||||
struct authenc_instance_ctx *ctx;
|
|
||||||
const char *enc_name;
|
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
algt = crypto_get_attr_type(tb);
|
algt = crypto_get_attr_type(tb);
|
||||||
|
@ -391,35 +390,22 @@ static int crypto_authenc_create(struct crypto_template *tmpl,
|
||||||
|
|
||||||
mask = crypto_requires_sync(algt->type, algt->mask);
|
mask = crypto_requires_sync(algt->type, algt->mask);
|
||||||
|
|
||||||
auth = ahash_attr_alg(tb[1], CRYPTO_ALG_TYPE_HASH,
|
|
||||||
CRYPTO_ALG_TYPE_AHASH_MASK | mask);
|
|
||||||
if (IS_ERR(auth))
|
|
||||||
return PTR_ERR(auth);
|
|
||||||
|
|
||||||
auth_base = &auth->base;
|
|
||||||
|
|
||||||
enc_name = crypto_attr_alg_name(tb[2]);
|
|
||||||
err = PTR_ERR(enc_name);
|
|
||||||
if (IS_ERR(enc_name))
|
|
||||||
goto out_put_auth;
|
|
||||||
|
|
||||||
inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL);
|
inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL);
|
||||||
err = -ENOMEM;
|
|
||||||
if (!inst)
|
if (!inst)
|
||||||
goto out_put_auth;
|
return -ENOMEM;
|
||||||
|
|
||||||
ctx = aead_instance_ctx(inst);
|
ctx = aead_instance_ctx(inst);
|
||||||
|
|
||||||
err = crypto_init_ahash_spawn(&ctx->auth, auth,
|
err = crypto_grab_ahash(&ctx->auth, aead_crypto_instance(inst),
|
||||||
aead_crypto_instance(inst));
|
crypto_attr_alg_name(tb[1]), 0, mask);
|
||||||
if (err)
|
if (err)
|
||||||
goto err_free_inst;
|
goto err_free_inst;
|
||||||
|
auth = crypto_spawn_ahash_alg(&ctx->auth);
|
||||||
|
auth_base = &auth->base;
|
||||||
|
|
||||||
err = crypto_grab_skcipher(&ctx->enc, aead_crypto_instance(inst),
|
err = crypto_grab_skcipher(&ctx->enc, aead_crypto_instance(inst),
|
||||||
enc_name, 0, mask);
|
crypto_attr_alg_name(tb[2]), 0, mask);
|
||||||
if (err)
|
if (err)
|
||||||
goto err_drop_auth;
|
goto err_free_inst;
|
||||||
|
|
||||||
enc = crypto_spawn_skcipher_alg(&ctx->enc);
|
enc = crypto_spawn_skcipher_alg(&ctx->enc);
|
||||||
|
|
||||||
ctx->reqoff = ALIGN(2 * auth->digestsize + auth_base->cra_alignmask,
|
ctx->reqoff = ALIGN(2 * auth->digestsize + auth_base->cra_alignmask,
|
||||||
|
@ -430,12 +416,12 @@ static int crypto_authenc_create(struct crypto_template *tmpl,
|
||||||
"authenc(%s,%s)", auth_base->cra_name,
|
"authenc(%s,%s)", auth_base->cra_name,
|
||||||
enc->base.cra_name) >=
|
enc->base.cra_name) >=
|
||||||
CRYPTO_MAX_ALG_NAME)
|
CRYPTO_MAX_ALG_NAME)
|
||||||
goto err_drop_enc;
|
goto err_free_inst;
|
||||||
|
|
||||||
if (snprintf(inst->alg.base.cra_driver_name, CRYPTO_MAX_ALG_NAME,
|
if (snprintf(inst->alg.base.cra_driver_name, CRYPTO_MAX_ALG_NAME,
|
||||||
"authenc(%s,%s)", auth_base->cra_driver_name,
|
"authenc(%s,%s)", auth_base->cra_driver_name,
|
||||||
enc->base.cra_driver_name) >= CRYPTO_MAX_ALG_NAME)
|
enc->base.cra_driver_name) >= CRYPTO_MAX_ALG_NAME)
|
||||||
goto err_drop_enc;
|
goto err_free_inst;
|
||||||
|
|
||||||
inst->alg.base.cra_flags = (auth_base->cra_flags |
|
inst->alg.base.cra_flags = (auth_base->cra_flags |
|
||||||
enc->base.cra_flags) & CRYPTO_ALG_ASYNC;
|
enc->base.cra_flags) & CRYPTO_ALG_ASYNC;
|
||||||
|
@ -460,21 +446,11 @@ static int crypto_authenc_create(struct crypto_template *tmpl,
|
||||||
inst->free = crypto_authenc_free;
|
inst->free = crypto_authenc_free;
|
||||||
|
|
||||||
err = aead_register_instance(tmpl, inst);
|
err = aead_register_instance(tmpl, inst);
|
||||||
if (err)
|
if (err) {
|
||||||
goto err_drop_enc;
|
|
||||||
|
|
||||||
out:
|
|
||||||
crypto_mod_put(auth_base);
|
|
||||||
return err;
|
|
||||||
|
|
||||||
err_drop_enc:
|
|
||||||
crypto_drop_skcipher(&ctx->enc);
|
|
||||||
err_drop_auth:
|
|
||||||
crypto_drop_ahash(&ctx->auth);
|
|
||||||
err_free_inst:
|
err_free_inst:
|
||||||
kfree(inst);
|
crypto_authenc_free(inst);
|
||||||
out_put_auth:
|
}
|
||||||
goto out;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct crypto_template crypto_authenc_tmpl = {
|
static struct crypto_template crypto_authenc_tmpl = {
|
||||||
|
|
Loading…
Reference in New Issue