Skip to content

Commit cd900f0

Browse files
ebiggersherbertx
authored andcommitted
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 6db4341 ("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>
1 parent b9f76dd commit cd900f0

8 files changed

Lines changed: 29 additions & 28 deletions

File tree

‎crypto/aead.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,11 @@ static const struct crypto_type crypto_aead_type = {
207207
.tfmsize = offsetof(struct crypto_aead, base),
208208
};
209209

210-
int crypto_grab_aead(struct crypto_aead_spawn *spawn, const char *name,
211-
u32 type, u32 mask)
210+
int crypto_grab_aead(struct crypto_aead_spawn *spawn,
211+
struct crypto_instance *inst,
212+
const char *name, u32 type, u32 mask)
212213
{
214+
spawn->base.inst = inst;
213215
spawn->base.frontend = &crypto_aead_type;
214216
return crypto_grab_spawn(&spawn->base, name, type, mask);
215217
}

‎crypto/ccm.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,7 @@ static int crypto_rfc4309_create(struct crypto_template *tmpl,
734734
struct rtattr **tb)
735735
{
736736
struct crypto_attr_type *algt;
737+
u32 mask;
737738
struct aead_instance *inst;
738739
struct crypto_aead_spawn *spawn;
739740
struct aead_alg *alg;
@@ -747,6 +748,8 @@ static int crypto_rfc4309_create(struct crypto_template *tmpl,
747748
if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask)
748749
return -EINVAL;
749750

751+
mask = crypto_requires_sync(algt->type, algt->mask);
752+
750753
ccm_name = crypto_attr_alg_name(tb[1]);
751754
if (IS_ERR(ccm_name))
752755
return PTR_ERR(ccm_name);
@@ -756,9 +759,8 @@ static int crypto_rfc4309_create(struct crypto_template *tmpl,
756759
return -ENOMEM;
757760

758761
spawn = aead_instance_ctx(inst);
759-
crypto_set_aead_spawn(spawn, aead_crypto_instance(inst));
760-
err = crypto_grab_aead(spawn, ccm_name, 0,
761-
crypto_requires_sync(algt->type, algt->mask));
762+
err = crypto_grab_aead(spawn, aead_crypto_instance(inst),
763+
ccm_name, 0, mask);
762764
if (err)
763765
goto out_free_inst;
764766

‎crypto/cryptd.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -865,8 +865,8 @@ static int cryptd_create_aead(struct crypto_template *tmpl,
865865
ctx = aead_instance_ctx(inst);
866866
ctx->queue = queue;
867867

868-
crypto_set_aead_spawn(&ctx->aead_spawn, aead_crypto_instance(inst));
869-
err = crypto_grab_aead(&ctx->aead_spawn, name, type, mask);
868+
err = crypto_grab_aead(&ctx->aead_spawn, aead_crypto_instance(inst),
869+
name, type, mask);
870870
if (err)
871871
goto out_free_inst;
872872

‎crypto/essiv.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,7 @@ static int essiv_create(struct crypto_template *tmpl, struct rtattr **tb)
500500
ictx = crypto_instance_ctx(inst);
501501

502502
/* AEAD cipher, e.g., "authenc(hmac(sha256),cbc(aes))" */
503-
crypto_set_aead_spawn(&ictx->u.aead_spawn, inst);
504-
err = crypto_grab_aead(&ictx->u.aead_spawn,
503+
err = crypto_grab_aead(&ictx->u.aead_spawn, inst,
505504
inner_cipher_name, 0, mask);
506505
if (err)
507506
goto out_free_inst;

‎crypto/gcm.c‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,7 @@ static int crypto_rfc4106_create(struct crypto_template *tmpl,
856856
struct rtattr **tb)
857857
{
858858
struct crypto_attr_type *algt;
859+
u32 mask;
859860
struct aead_instance *inst;
860861
struct crypto_aead_spawn *spawn;
861862
struct aead_alg *alg;
@@ -869,6 +870,8 @@ static int crypto_rfc4106_create(struct crypto_template *tmpl,
869870
if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask)
870871
return -EINVAL;
871872

873+
mask = crypto_requires_sync(algt->type, algt->mask);
874+
872875
ccm_name = crypto_attr_alg_name(tb[1]);
873876
if (IS_ERR(ccm_name))
874877
return PTR_ERR(ccm_name);
@@ -878,9 +881,8 @@ static int crypto_rfc4106_create(struct crypto_template *tmpl,
878881
return -ENOMEM;
879882

880883
spawn = aead_instance_ctx(inst);
881-
crypto_set_aead_spawn(spawn, aead_crypto_instance(inst));
882-
err = crypto_grab_aead(spawn, ccm_name, 0,
883-
crypto_requires_sync(algt->type, algt->mask));
884+
err = crypto_grab_aead(spawn, aead_crypto_instance(inst),
885+
ccm_name, 0, mask);
884886
if (err)
885887
goto out_free_inst;
886888

@@ -1087,6 +1089,7 @@ static int crypto_rfc4543_create(struct crypto_template *tmpl,
10871089
struct rtattr **tb)
10881090
{
10891091
struct crypto_attr_type *algt;
1092+
u32 mask;
10901093
struct aead_instance *inst;
10911094
struct crypto_aead_spawn *spawn;
10921095
struct aead_alg *alg;
@@ -1101,6 +1104,8 @@ static int crypto_rfc4543_create(struct crypto_template *tmpl,
11011104
if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask)
11021105
return -EINVAL;
11031106

1107+
mask = crypto_requires_sync(algt->type, algt->mask);
1108+
11041109
ccm_name = crypto_attr_alg_name(tb[1]);
11051110
if (IS_ERR(ccm_name))
11061111
return PTR_ERR(ccm_name);
@@ -1111,9 +1116,8 @@ static int crypto_rfc4543_create(struct crypto_template *tmpl,
11111116

11121117
ctx = aead_instance_ctx(inst);
11131118
spawn = &ctx->aead;
1114-
crypto_set_aead_spawn(spawn, aead_crypto_instance(inst));
1115-
err = crypto_grab_aead(spawn, ccm_name, 0,
1116-
crypto_requires_sync(algt->type, algt->mask));
1119+
err = crypto_grab_aead(spawn, aead_crypto_instance(inst),
1120+
ccm_name, 0, mask);
11171121
if (err)
11181122
goto out_free_inst;
11191123

‎crypto/geniv.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ struct aead_instance *aead_geniv_alloc(struct crypto_template *tmpl,
6464
/* Ignore async algorithms if necessary. */
6565
mask |= crypto_requires_sync(algt->type, algt->mask);
6666

67-
crypto_set_aead_spawn(spawn, aead_crypto_instance(inst));
68-
err = crypto_grab_aead(spawn, name, type, mask);
67+
err = crypto_grab_aead(spawn, aead_crypto_instance(inst),
68+
name, type, mask);
6969
if (err)
7070
goto err_free_inst;
7171

‎crypto/pcrypt.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,8 @@ static int pcrypt_create_aead(struct crypto_template *tmpl, struct rtattr **tb,
258258
if (!ctx->psdec)
259259
goto out_free_psenc;
260260

261-
crypto_set_aead_spawn(&ctx->spawn, aead_crypto_instance(inst));
262-
263-
err = crypto_grab_aead(&ctx->spawn, name, 0, 0);
261+
err = crypto_grab_aead(&ctx->spawn, aead_crypto_instance(inst),
262+
name, 0, 0);
264263
if (err)
265264
goto out_free_psdec;
266265

‎include/crypto/internal/aead.h‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,9 @@ static inline struct aead_request *aead_request_cast(
8181
return container_of(req, struct aead_request, base);
8282
}
8383

84-
static inline void crypto_set_aead_spawn(
85-
struct crypto_aead_spawn *spawn, struct crypto_instance *inst)
86-
{
87-
crypto_set_spawn(&spawn->base, inst);
88-
}
89-
90-
int crypto_grab_aead(struct crypto_aead_spawn *spawn, const char *name,
91-
u32 type, u32 mask);
84+
int crypto_grab_aead(struct crypto_aead_spawn *spawn,
85+
struct crypto_instance *inst,
86+
const char *name, u32 type, u32 mask);
9287

9388
static inline void crypto_drop_aead(struct crypto_aead_spawn *spawn)
9489
{

0 commit comments

Comments
 (0)