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

crypto: akcipher - pass instance to crypto_grab_akcipher()

Initializing a crypto_akcipher_spawn currently requires:

1. Set spawn->base.inst to point to the instance.
2. Call crypto_grab_akcipher().

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 6db43410179b ("crypto: adiantum - initialize crypto_spawn::inst")

So just make crypto_grab_akcipher() take the instance as an argument.

To keep the function call from getting too unwieldy due to this extra
argument, also introduce a 'mask' variable into pkcs1pad_create().

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
73bed26f cd900f0c

+12 -14
+4 -2
crypto/akcipher.c
··· 90 90 .tfmsize = offsetof(struct crypto_akcipher, base), 91 91 }; 92 92 93 - int crypto_grab_akcipher(struct crypto_akcipher_spawn *spawn, const char *name, 94 - u32 type, u32 mask) 93 + int crypto_grab_akcipher(struct crypto_akcipher_spawn *spawn, 94 + struct crypto_instance *inst, 95 + const char *name, u32 type, u32 mask) 95 96 { 97 + spawn->base.inst = inst; 96 98 spawn->base.frontend = &crypto_akcipher_type; 97 99 return crypto_grab_spawn(&spawn->base, name, type, mask); 98 100 }
+5 -3
crypto/rsa-pkcs1pad.c
··· 598 598 { 599 599 const struct rsa_asn1_template *digest_info; 600 600 struct crypto_attr_type *algt; 601 + u32 mask; 601 602 struct akcipher_instance *inst; 602 603 struct pkcs1pad_inst_ctx *ctx; 603 604 struct crypto_akcipher_spawn *spawn; ··· 613 612 614 613 if ((algt->type ^ CRYPTO_ALG_TYPE_AKCIPHER) & algt->mask) 615 614 return -EINVAL; 615 + 616 + mask = crypto_requires_sync(algt->type, algt->mask); 616 617 617 618 rsa_alg_name = crypto_attr_alg_name(tb[1]); 618 619 if (IS_ERR(rsa_alg_name)) ··· 639 636 spawn = &ctx->spawn; 640 637 ctx->digest_info = digest_info; 641 638 642 - crypto_set_spawn(&spawn->base, akcipher_crypto_instance(inst)); 643 - err = crypto_grab_akcipher(spawn, rsa_alg_name, 0, 644 - crypto_requires_sync(algt->type, algt->mask)); 639 + err = crypto_grab_akcipher(spawn, akcipher_crypto_instance(inst), 640 + rsa_alg_name, 0, mask); 645 641 if (err) 646 642 goto out_free_inst; 647 643
+3 -9
include/crypto/internal/akcipher.h
··· 78 78 return crypto_instance_ctx(akcipher_crypto_instance(inst)); 79 79 } 80 80 81 - static inline void crypto_set_akcipher_spawn( 82 - struct crypto_akcipher_spawn *spawn, 83 - struct crypto_instance *inst) 84 - { 85 - crypto_set_spawn(&spawn->base, inst); 86 - } 87 - 88 - int crypto_grab_akcipher(struct crypto_akcipher_spawn *spawn, const char *name, 89 - u32 type, u32 mask); 81 + int crypto_grab_akcipher(struct crypto_akcipher_spawn *spawn, 82 + struct crypto_instance *inst, 83 + const char *name, u32 type, u32 mask); 90 84 91 85 static inline struct crypto_akcipher *crypto_spawn_akcipher( 92 86 struct crypto_akcipher_spawn *spawn)