mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-12-29 17:25:38 +00:00
crypto: aead - pass instance to crypto_grab_aead()
Initializing a crypto_aead_spawn currently requires:
1. Set spawn->base.inst to point to the instance.
2. Call crypto_grab_aead().
But there's no reason for these steps to be separate, and in fact this
unneeded complication has caused at least one bug, the one fixed by
commit 6db4341017
("crypto: adiantum - initialize crypto_spawn::inst")
So just make crypto_grab_aead() take the instance as an argument.
To keep the function calls from getting too unwieldy due to this extra
argument, also introduce a 'mask' variable into the affected places
which weren't already using one.
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
parent
b9f76dddb1
commit
cd900f0cac
@ -207,9 +207,11 @@ static const struct crypto_type crypto_aead_type = {
|
||||
.tfmsize = offsetof(struct crypto_aead, base),
|
||||
};
|
||||
|
||||
int crypto_grab_aead(struct crypto_aead_spawn *spawn, const char *name,
|
||||
u32 type, u32 mask)
|
||||
int crypto_grab_aead(struct crypto_aead_spawn *spawn,
|
||||
struct crypto_instance *inst,
|
||||
const char *name, u32 type, u32 mask)
|
||||
{
|
||||
spawn->base.inst = inst;
|
||||
spawn->base.frontend = &crypto_aead_type;
|
||||
return crypto_grab_spawn(&spawn->base, name, type, mask);
|
||||
}
|
||||
|
@ -734,6 +734,7 @@ static int crypto_rfc4309_create(struct crypto_template *tmpl,
|
||||
struct rtattr **tb)
|
||||
{
|
||||
struct crypto_attr_type *algt;
|
||||
u32 mask;
|
||||
struct aead_instance *inst;
|
||||
struct crypto_aead_spawn *spawn;
|
||||
struct aead_alg *alg;
|
||||
@ -747,6 +748,8 @@ static int crypto_rfc4309_create(struct crypto_template *tmpl,
|
||||
if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask)
|
||||
return -EINVAL;
|
||||
|
||||
mask = crypto_requires_sync(algt->type, algt->mask);
|
||||
|
||||
ccm_name = crypto_attr_alg_name(tb[1]);
|
||||
if (IS_ERR(ccm_name))
|
||||
return PTR_ERR(ccm_name);
|
||||
@ -756,9 +759,8 @@ static int crypto_rfc4309_create(struct crypto_template *tmpl,
|
||||
return -ENOMEM;
|
||||
|
||||
spawn = aead_instance_ctx(inst);
|
||||
crypto_set_aead_spawn(spawn, aead_crypto_instance(inst));
|
||||
err = crypto_grab_aead(spawn, ccm_name, 0,
|
||||
crypto_requires_sync(algt->type, algt->mask));
|
||||
err = crypto_grab_aead(spawn, aead_crypto_instance(inst),
|
||||
ccm_name, 0, mask);
|
||||
if (err)
|
||||
goto out_free_inst;
|
||||
|
||||
|
@ -865,8 +865,8 @@ static int cryptd_create_aead(struct crypto_template *tmpl,
|
||||
ctx = aead_instance_ctx(inst);
|
||||
ctx->queue = queue;
|
||||
|
||||
crypto_set_aead_spawn(&ctx->aead_spawn, aead_crypto_instance(inst));
|
||||
err = crypto_grab_aead(&ctx->aead_spawn, name, type, mask);
|
||||
err = crypto_grab_aead(&ctx->aead_spawn, aead_crypto_instance(inst),
|
||||
name, type, mask);
|
||||
if (err)
|
||||
goto out_free_inst;
|
||||
|
||||
|
@ -500,8 +500,7 @@ static int essiv_create(struct crypto_template *tmpl, struct rtattr **tb)
|
||||
ictx = crypto_instance_ctx(inst);
|
||||
|
||||
/* AEAD cipher, e.g., "authenc(hmac(sha256),cbc(aes))" */
|
||||
crypto_set_aead_spawn(&ictx->u.aead_spawn, inst);
|
||||
err = crypto_grab_aead(&ictx->u.aead_spawn,
|
||||
err = crypto_grab_aead(&ictx->u.aead_spawn, inst,
|
||||
inner_cipher_name, 0, mask);
|
||||
if (err)
|
||||
goto out_free_inst;
|
||||
|
16
crypto/gcm.c
16
crypto/gcm.c
@ -856,6 +856,7 @@ static int crypto_rfc4106_create(struct crypto_template *tmpl,
|
||||
struct rtattr **tb)
|
||||
{
|
||||
struct crypto_attr_type *algt;
|
||||
u32 mask;
|
||||
struct aead_instance *inst;
|
||||
struct crypto_aead_spawn *spawn;
|
||||
struct aead_alg *alg;
|
||||
@ -869,6 +870,8 @@ static int crypto_rfc4106_create(struct crypto_template *tmpl,
|
||||
if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask)
|
||||
return -EINVAL;
|
||||
|
||||
mask = crypto_requires_sync(algt->type, algt->mask);
|
||||
|
||||
ccm_name = crypto_attr_alg_name(tb[1]);
|
||||
if (IS_ERR(ccm_name))
|
||||
return PTR_ERR(ccm_name);
|
||||
@ -878,9 +881,8 @@ static int crypto_rfc4106_create(struct crypto_template *tmpl,
|
||||
return -ENOMEM;
|
||||
|
||||
spawn = aead_instance_ctx(inst);
|
||||
crypto_set_aead_spawn(spawn, aead_crypto_instance(inst));
|
||||
err = crypto_grab_aead(spawn, ccm_name, 0,
|
||||
crypto_requires_sync(algt->type, algt->mask));
|
||||
err = crypto_grab_aead(spawn, aead_crypto_instance(inst),
|
||||
ccm_name, 0, mask);
|
||||
if (err)
|
||||
goto out_free_inst;
|
||||
|
||||
@ -1087,6 +1089,7 @@ static int crypto_rfc4543_create(struct crypto_template *tmpl,
|
||||
struct rtattr **tb)
|
||||
{
|
||||
struct crypto_attr_type *algt;
|
||||
u32 mask;
|
||||
struct aead_instance *inst;
|
||||
struct crypto_aead_spawn *spawn;
|
||||
struct aead_alg *alg;
|
||||
@ -1101,6 +1104,8 @@ static int crypto_rfc4543_create(struct crypto_template *tmpl,
|
||||
if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask)
|
||||
return -EINVAL;
|
||||
|
||||
mask = crypto_requires_sync(algt->type, algt->mask);
|
||||
|
||||
ccm_name = crypto_attr_alg_name(tb[1]);
|
||||
if (IS_ERR(ccm_name))
|
||||
return PTR_ERR(ccm_name);
|
||||
@ -1111,9 +1116,8 @@ static int crypto_rfc4543_create(struct crypto_template *tmpl,
|
||||
|
||||
ctx = aead_instance_ctx(inst);
|
||||
spawn = &ctx->aead;
|
||||
crypto_set_aead_spawn(spawn, aead_crypto_instance(inst));
|
||||
err = crypto_grab_aead(spawn, ccm_name, 0,
|
||||
crypto_requires_sync(algt->type, algt->mask));
|
||||
err = crypto_grab_aead(spawn, aead_crypto_instance(inst),
|
||||
ccm_name, 0, mask);
|
||||
if (err)
|
||||
goto out_free_inst;
|
||||
|
||||
|
@ -64,8 +64,8 @@ struct aead_instance *aead_geniv_alloc(struct crypto_template *tmpl,
|
||||
/* Ignore async algorithms if necessary. */
|
||||
mask |= crypto_requires_sync(algt->type, algt->mask);
|
||||
|
||||
crypto_set_aead_spawn(spawn, aead_crypto_instance(inst));
|
||||
err = crypto_grab_aead(spawn, name, type, mask);
|
||||
err = crypto_grab_aead(spawn, aead_crypto_instance(inst),
|
||||
name, type, mask);
|
||||
if (err)
|
||||
goto err_free_inst;
|
||||
|
||||
|
@ -258,9 +258,8 @@ static int pcrypt_create_aead(struct crypto_template *tmpl, struct rtattr **tb,
|
||||
if (!ctx->psdec)
|
||||
goto out_free_psenc;
|
||||
|
||||
crypto_set_aead_spawn(&ctx->spawn, aead_crypto_instance(inst));
|
||||
|
||||
err = crypto_grab_aead(&ctx->spawn, name, 0, 0);
|
||||
err = crypto_grab_aead(&ctx->spawn, aead_crypto_instance(inst),
|
||||
name, 0, 0);
|
||||
if (err)
|
||||
goto out_free_psdec;
|
||||
|
||||
|
@ -81,14 +81,9 @@ static inline struct aead_request *aead_request_cast(
|
||||
return container_of(req, struct aead_request, base);
|
||||
}
|
||||
|
||||
static inline void crypto_set_aead_spawn(
|
||||
struct crypto_aead_spawn *spawn, struct crypto_instance *inst)
|
||||
{
|
||||
crypto_set_spawn(&spawn->base, inst);
|
||||
}
|
||||
|
||||
int crypto_grab_aead(struct crypto_aead_spawn *spawn, const char *name,
|
||||
u32 type, u32 mask);
|
||||
int crypto_grab_aead(struct crypto_aead_spawn *spawn,
|
||||
struct crypto_instance *inst,
|
||||
const char *name, u32 type, u32 mask);
|
||||
|
||||
static inline void crypto_drop_aead(struct crypto_aead_spawn *spawn)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user