All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: linux-crypto@vger.kernel.org
Subject: [PATCH v2 06/28] crypto: aead - pass instance to crypto_grab_aead()
Date: Thu,  2 Jan 2020 19:58:46 -0800	[thread overview]
Message-ID: <20200103035908.12048-7-ebiggers@kernel.org> (raw)
In-Reply-To: <20200103035908.12048-1-ebiggers@kernel.org>

From: Eric Biggers <ebiggers@google.com>

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 6db43410179b ("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>
---
 crypto/aead.c                  |  6 ++++--
 crypto/ccm.c                   |  8 +++++---
 crypto/cryptd.c                |  4 ++--
 crypto/essiv.c                 |  3 +--
 crypto/gcm.c                   | 16 ++++++++++------
 crypto/geniv.c                 |  4 ++--
 crypto/pcrypt.c                |  5 ++---
 include/crypto/internal/aead.h | 11 +++--------
 8 files changed, 29 insertions(+), 28 deletions(-)

diff --git a/crypto/aead.c b/crypto/aead.c
index 47f16d139e8e..c7135e00b8ea 100644
--- a/crypto/aead.c
+++ b/crypto/aead.c
@@ -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);
 }
diff --git a/crypto/ccm.c b/crypto/ccm.c
index d2279dc5b970..9c377976581d 100644
--- a/crypto/ccm.c
+++ b/crypto/ccm.c
@@ -746,6 +746,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;
@@ -759,6 +760,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);
@@ -768,9 +771,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;
 
diff --git a/crypto/cryptd.c b/crypto/cryptd.c
index 01a1f6aa30ac..5aea6d6c49a0 100644
--- a/crypto/cryptd.c
+++ b/crypto/cryptd.c
@@ -874,8 +874,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;
 
diff --git a/crypto/essiv.c b/crypto/essiv.c
index 2019250da08e..388cceb8c1a0 100644
--- a/crypto/essiv.c
+++ b/crypto/essiv.c
@@ -516,8 +516,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;
diff --git a/crypto/gcm.c b/crypto/gcm.c
index 5a01b2b956f6..4241264ff93a 100644
--- a/crypto/gcm.c
+++ b/crypto/gcm.c
@@ -866,6 +866,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;
@@ -879,6 +880,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);
@@ -888,9 +891,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;
 
@@ -1102,6 +1104,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;
@@ -1116,6 +1119,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);
@@ -1126,9 +1131,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;
 
diff --git a/crypto/geniv.c b/crypto/geniv.c
index b9e45a2a98b5..7afa48414f3a 100644
--- a/crypto/geniv.c
+++ b/crypto/geniv.c
@@ -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;
 
diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
index d6696e217128..1b632139a8c1 100644
--- a/crypto/pcrypt.c
+++ b/crypto/pcrypt.c
@@ -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;
 
diff --git a/include/crypto/internal/aead.h b/include/crypto/internal/aead.h
index 374185a7567f..27b7b0224ea6 100644
--- a/include/crypto/internal/aead.h
+++ b/include/crypto/internal/aead.h
@@ -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)
 {
-- 
2.24.1


  parent reply	other threads:[~2020-01-03  4:01 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-03  3:58 [PATCH v2 00/28] crypto: template instantiation cleanup Eric Biggers
2020-01-03  3:58 ` [PATCH v2 01/28] crypto: algapi - make crypto_drop_spawn() a no-op on uninitialized spawns Eric Biggers
2020-01-03  3:58 ` [PATCH v2 02/28] crypto: algapi - make crypto_grab_spawn() handle an ERR_PTR() name Eric Biggers
2020-01-03  3:58 ` [PATCH v2 03/28] crypto: shash - make struct shash_instance be the full size Eric Biggers
2020-01-03  3:58 ` [PATCH v2 04/28] crypto: ahash - make struct ahash_instance " Eric Biggers
2020-01-03  3:58 ` [PATCH v2 05/28] crypto: skcipher - pass instance to crypto_grab_skcipher() Eric Biggers
2020-01-03  3:58 ` Eric Biggers [this message]
2020-01-03  3:58 ` [PATCH v2 07/28] crypto: akcipher - pass instance to crypto_grab_akcipher() Eric Biggers
2020-01-03  3:58 ` [PATCH v2 08/28] crypto: algapi - pass instance to crypto_grab_spawn() Eric Biggers
2020-01-03  3:58 ` [PATCH v2 09/28] crypto: shash - introduce crypto_grab_shash() Eric Biggers
2020-01-03  3:58 ` [PATCH v2 10/28] crypto: ahash - introduce crypto_grab_ahash() Eric Biggers
2020-01-03  3:58 ` [PATCH v2 11/28] crypto: cipher - introduce crypto_cipher_spawn and crypto_grab_cipher() Eric Biggers
2020-01-03  3:58 ` [PATCH v2 12/28] crypto: adiantum - use crypto_grab_{cipher,shash} and simplify error paths Eric Biggers
2020-01-03  3:58 ` [PATCH v2 13/28] crypto: cryptd - use crypto_grab_shash() " Eric Biggers
2020-01-03  3:58 ` [PATCH v2 14/28] crypto: hmac " Eric Biggers
2020-01-03  3:58 ` [PATCH v2 15/28] crypto: authenc - use crypto_grab_ahash() " Eric Biggers
2020-01-03  3:58 ` [PATCH v2 16/28] crypto: authencesn " Eric Biggers
2020-01-03  3:58 ` [PATCH v2 17/28] crypto: gcm " Eric Biggers
2020-01-03  3:58 ` [PATCH v2 18/28] crypto: ccm " Eric Biggers
2020-01-03  3:58 ` [PATCH v2 19/28] crypto: chacha20poly1305 " Eric Biggers
2020-01-03  3:59 ` [PATCH v2 20/28] crypto: skcipher - use crypto_grab_cipher() " Eric Biggers
2020-01-03  3:59 ` [PATCH v2 21/28] crypto: cbcmac " Eric Biggers
2020-01-03  3:59 ` [PATCH v2 22/28] crypto: cmac " Eric Biggers
2020-01-03  3:59 ` [PATCH v2 23/28] crypto: vmac " Eric Biggers
2020-01-03  3:59 ` [PATCH v2 24/28] crypto: xcbc " Eric Biggers
2020-01-03  3:59 ` [PATCH v2 25/28] crypto: cipher - make crypto_spawn_cipher() take a crypto_cipher_spawn Eric Biggers
2020-01-03  3:59 ` [PATCH v2 26/28] crypto: algapi - remove obsoleted instance creation helpers Eric Biggers
2020-01-03  3:59 ` [PATCH v2 27/28] crypto: ahash - unexport crypto_ahash_type Eric Biggers
2020-01-03  3:59 ` [PATCH v2 28/28] crypto: algapi - fold crypto_init_spawn() into crypto_grab_spawn() Eric Biggers
2020-01-09  5:14 ` [PATCH v2 00/28] crypto: template instantiation cleanup Herbert Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200103035908.12048-7-ebiggers@kernel.org \
    --to=ebiggers@kernel.org \
    --cc=linux-crypto@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.