linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/20] crypto: introduce crypto_shash_tfm_digest()
@ 2020-05-02  5:31 Eric Biggers
  2020-05-02  5:31 ` [PATCH 01/20] crypto: hash - " Eric Biggers
                   ` (22 more replies)
  0 siblings, 23 replies; 28+ messages in thread
From: Eric Biggers @ 2020-05-02  5:31 UTC (permalink / raw)
  To: linux-crypto
  Cc: Cheng-Yi Chiang, ecryptfs, Enric Balletbo i Serra,
	Gilad Ben-Yossef, Guenter Roeck, Jesper Nilsson, Kamil Konieczny,
	keyrings, Krzysztof Kozlowski, Krzysztof Opasiak, Lars Persson,
	linux-bluetooth, linux-mtd, linux-nfs, linux-sctp,
	Robert Baldyga, Tom Lendacky, Vladimir Zapolskiy, Zaibo Xu

This series introduces a helper function crypto_shash_tfm_digest() which
replaces the following common pattern:

	{
		SHASH_DESC_ON_STACK(desc, tfm);
		int err;

		desc->tfm = tfm;

		err = crypto_shash_digest(desc, data, len, out);

		shash_desc_zero(desc);
	}

with:

	err = crypto_shash_tfm_digest(tfm, data, len, out);

Patch 1 introduces this helper function, and patches 2-20 convert all
relevant users to use it.

IMO, it would be easiest to take all these patches through the crypto
tree.  But taking just the "crypto:" ones and then me trying to get the
rest merged later via subsystem trees is also an option.

Eric Biggers (20):
  crypto: hash - introduce crypto_shash_tfm_digest()
  crypto: arm64/aes-glue - use crypto_shash_tfm_digest()
  crypto: essiv - use crypto_shash_tfm_digest()
  crypto: artpec6 - use crypto_shash_tfm_digest()
  crypto: ccp - use crypto_shash_tfm_digest()
  crypto: ccree - use crypto_shash_tfm_digest()
  crypto: hisilicon/sec2 - use crypto_shash_tfm_digest()
  crypto: mediatek - use crypto_shash_tfm_digest()
  crypto: n2 - use crypto_shash_tfm_digest()
  crypto: omap-sham - use crypto_shash_tfm_digest()
  crypto: s5p-sss - use crypto_shash_tfm_digest()
  nfc: s3fwrn5: use crypto_shash_tfm_digest()
  fscrypt: use crypto_shash_tfm_digest()
  ecryptfs: use crypto_shash_tfm_digest()
  nfsd: use crypto_shash_tfm_digest()
  ubifs: use crypto_shash_tfm_digest()
  Bluetooth: use crypto_shash_tfm_digest()
  sctp: use crypto_shash_tfm_digest()
  KEYS: encrypted: use crypto_shash_tfm_digest()
  ASoC: cros_ec_codec: use crypto_shash_tfm_digest()

 arch/arm64/crypto/aes-glue.c               |  4 +--
 crypto/essiv.c                             |  4 +--
 crypto/shash.c                             | 16 +++++++++
 drivers/crypto/axis/artpec6_crypto.c       | 10 ++----
 drivers/crypto/ccp/ccp-crypto-sha.c        |  9 ++---
 drivers/crypto/ccree/cc_cipher.c           |  9 ++---
 drivers/crypto/hisilicon/sec2/sec_crypto.c |  5 ++-
 drivers/crypto/mediatek/mtk-sha.c          |  7 ++--
 drivers/crypto/n2_core.c                   |  7 ++--
 drivers/crypto/omap-sham.c                 | 20 +++--------
 drivers/crypto/s5p-sss.c                   | 39 ++++------------------
 drivers/nfc/s3fwrn5/firmware.c             | 10 +-----
 fs/crypto/fname.c                          |  7 +---
 fs/crypto/hkdf.c                           |  6 +---
 fs/ecryptfs/crypto.c                       | 17 +---------
 fs/nfsd/nfs4recover.c                      | 26 ++++-----------
 fs/ubifs/auth.c                            | 20 ++---------
 fs/ubifs/master.c                          |  9 ++---
 fs/ubifs/replay.c                          | 14 ++------
 include/crypto/hash.h                      | 19 +++++++++++
 net/bluetooth/smp.c                        |  6 +---
 net/sctp/auth.c                            | 10 ++----
 net/sctp/sm_make_chunk.c                   | 23 +++++--------
 security/keys/encrypted-keys/encrypted.c   | 18 ++--------
 sound/soc/codecs/cros_ec_codec.c           |  9 +----
 25 files changed, 95 insertions(+), 229 deletions(-)

-- 
2.26.2


^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 01/20] crypto: hash - introduce crypto_shash_tfm_digest()
  2020-05-02  5:31 [PATCH 00/20] crypto: introduce crypto_shash_tfm_digest() Eric Biggers
@ 2020-05-02  5:31 ` Eric Biggers
  2020-05-02  5:31 ` [PATCH 02/20] crypto: arm64/aes-glue - use crypto_shash_tfm_digest() Eric Biggers
                   ` (21 subsequent siblings)
  22 siblings, 0 replies; 28+ messages in thread
From: Eric Biggers @ 2020-05-02  5:31 UTC (permalink / raw)
  To: linux-crypto
  Cc: Cheng-Yi Chiang, ecryptfs, Enric Balletbo i Serra,
	Gilad Ben-Yossef, Guenter Roeck, Jesper Nilsson, Kamil Konieczny,
	keyrings, Krzysztof Kozlowski, Krzysztof Opasiak, Lars Persson,
	linux-bluetooth, linux-mtd, linux-nfs, linux-sctp,
	Robert Baldyga, Tom Lendacky, Vladimir Zapolskiy, Zaibo Xu

From: Eric Biggers <ebiggers@google.com>

Currently the simplest use of the shash API is to use
crypto_shash_digest() to digest a whole buffer.  However, this still
requires allocating a hash descriptor (struct shash_desc).  Many users
don't really want to preallocate one and instead just use a one-off
descriptor on the stack like the following:

	{
		SHASH_DESC_ON_STACK(desc, tfm);
		int err;

		desc->tfm = tfm;

		err = crypto_shash_digest(desc, data, len, out);

		shash_desc_zero(desc);
	}

Wrap this in a new helper function crypto_shash_tfm_digest() that can be
used instead of the above.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 crypto/shash.c        | 16 ++++++++++++++++
 include/crypto/hash.h | 19 +++++++++++++++++++
 2 files changed, 35 insertions(+)

diff --git a/crypto/shash.c b/crypto/shash.c
index c075b26c2a1d9f..e6a4b5f39b8c64 100644
--- a/crypto/shash.c
+++ b/crypto/shash.c
@@ -206,6 +206,22 @@ int crypto_shash_digest(struct shash_desc *desc, const u8 *data,
 }
 EXPORT_SYMBOL_GPL(crypto_shash_digest);
 
+int crypto_shash_tfm_digest(struct crypto_shash *tfm, const u8 *data,
+			    unsigned int len, u8 *out)
+{
+	SHASH_DESC_ON_STACK(desc, tfm);
+	int err;
+
+	desc->tfm = tfm;
+
+	err = crypto_shash_digest(desc, data, len, out);
+
+	shash_desc_zero(desc);
+
+	return err;
+}
+EXPORT_SYMBOL_GPL(crypto_shash_tfm_digest);
+
 static int shash_default_export(struct shash_desc *desc, void *out)
 {
 	memcpy(out, shash_desc_ctx(desc), crypto_shash_descsize(desc->tfm));
diff --git a/include/crypto/hash.h b/include/crypto/hash.h
index cee446c59497c6..4829d2367eda87 100644
--- a/include/crypto/hash.h
+++ b/include/crypto/hash.h
@@ -855,6 +855,25 @@ int crypto_shash_setkey(struct crypto_shash *tfm, const u8 *key,
 int crypto_shash_digest(struct shash_desc *desc, const u8 *data,
 			unsigned int len, u8 *out);
 
+/**
+ * crypto_shash_tfm_digest() - calculate message digest for buffer
+ * @tfm: hash transformation object
+ * @data: see crypto_shash_update()
+ * @len: see crypto_shash_update()
+ * @out: see crypto_shash_final()
+ *
+ * This is a simplified version of crypto_shash_digest() for users who don't
+ * want to allocate their own hash descriptor (shash_desc).  Instead,
+ * crypto_shash_tfm_digest() takes a hash transformation object (crypto_shash)
+ * directly, and it allocates a hash descriptor on the stack internally.
+ * Note that this stack allocation may be fairly large.
+ *
+ * Context: Any context.
+ * Return: 0 on success; < 0 if an error occurred.
+ */
+int crypto_shash_tfm_digest(struct crypto_shash *tfm, const u8 *data,
+			    unsigned int len, u8 *out);
+
 /**
  * crypto_shash_export() - extract operational state for message digest
  * @desc: reference to the operational state handle whose state is exported
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 02/20] crypto: arm64/aes-glue - use crypto_shash_tfm_digest()
  2020-05-02  5:31 [PATCH 00/20] crypto: introduce crypto_shash_tfm_digest() Eric Biggers
  2020-05-02  5:31 ` [PATCH 01/20] crypto: hash - " Eric Biggers
@ 2020-05-02  5:31 ` Eric Biggers
  2020-05-02  5:31 ` [PATCH 03/20] crypto: essiv " Eric Biggers
                   ` (20 subsequent siblings)
  22 siblings, 0 replies; 28+ messages in thread
From: Eric Biggers @ 2020-05-02  5:31 UTC (permalink / raw)
  To: linux-crypto

From: Eric Biggers <ebiggers@google.com>

Instead of manually allocating a 'struct shash_desc' on the stack and
calling crypto_shash_digest(), switch to using the new helper function
crypto_shash_tfm_digest() which does this for us.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 arch/arm64/crypto/aes-glue.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/arch/arm64/crypto/aes-glue.c b/arch/arm64/crypto/aes-glue.c
index ed5409c6abf4e9..395bbf64b2abb3 100644
--- a/arch/arm64/crypto/aes-glue.c
+++ b/arch/arm64/crypto/aes-glue.c
@@ -158,7 +158,6 @@ static int __maybe_unused essiv_cbc_set_key(struct crypto_skcipher *tfm,
 					    unsigned int key_len)
 {
 	struct crypto_aes_essiv_cbc_ctx *ctx = crypto_skcipher_ctx(tfm);
-	SHASH_DESC_ON_STACK(desc, ctx->hash);
 	u8 digest[SHA256_DIGEST_SIZE];
 	int ret;
 
@@ -166,8 +165,7 @@ static int __maybe_unused essiv_cbc_set_key(struct crypto_skcipher *tfm,
 	if (ret)
 		return ret;
 
-	desc->tfm = ctx->hash;
-	crypto_shash_digest(desc, in_key, key_len, digest);
+	crypto_shash_tfm_digest(ctx->hash, in_key, key_len, digest);
 
 	return aes_expandkey(&ctx->key2, digest, sizeof(digest));
 }
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 03/20] crypto: essiv - use crypto_shash_tfm_digest()
  2020-05-02  5:31 [PATCH 00/20] crypto: introduce crypto_shash_tfm_digest() Eric Biggers
  2020-05-02  5:31 ` [PATCH 01/20] crypto: hash - " Eric Biggers
  2020-05-02  5:31 ` [PATCH 02/20] crypto: arm64/aes-glue - use crypto_shash_tfm_digest() Eric Biggers
@ 2020-05-02  5:31 ` Eric Biggers
  2020-05-02  5:31 ` [PATCH 04/20] crypto: artpec6 " Eric Biggers
                   ` (19 subsequent siblings)
  22 siblings, 0 replies; 28+ messages in thread
From: Eric Biggers @ 2020-05-02  5:31 UTC (permalink / raw)
  To: linux-crypto

From: Eric Biggers <ebiggers@google.com>

Instead of manually allocating a 'struct shash_desc' on the stack and
calling crypto_shash_digest(), switch to using the new helper function
crypto_shash_tfm_digest() which does this for us.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 crypto/essiv.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/crypto/essiv.c b/crypto/essiv.c
index 465a89c9d1effe..a7f45dbc4ee289 100644
--- a/crypto/essiv.c
+++ b/crypto/essiv.c
@@ -66,7 +66,6 @@ static int essiv_skcipher_setkey(struct crypto_skcipher *tfm,
 				 const u8 *key, unsigned int keylen)
 {
 	struct essiv_tfm_ctx *tctx = crypto_skcipher_ctx(tfm);
-	SHASH_DESC_ON_STACK(desc, tctx->hash);
 	u8 salt[HASH_MAX_DIGESTSIZE];
 	int err;
 
@@ -78,8 +77,7 @@ static int essiv_skcipher_setkey(struct crypto_skcipher *tfm,
 	if (err)
 		return err;
 
-	desc->tfm = tctx->hash;
-	err = crypto_shash_digest(desc, key, keylen, salt);
+	err = crypto_shash_tfm_digest(tctx->hash, key, keylen, salt);
 	if (err)
 		return err;
 
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 04/20] crypto: artpec6 - use crypto_shash_tfm_digest()
  2020-05-02  5:31 [PATCH 00/20] crypto: introduce crypto_shash_tfm_digest() Eric Biggers
                   ` (2 preceding siblings ...)
  2020-05-02  5:31 ` [PATCH 03/20] crypto: essiv " Eric Biggers
@ 2020-05-02  5:31 ` Eric Biggers
  2020-05-02  5:31 ` [PATCH 05/20] crypto: ccp " Eric Biggers
                   ` (18 subsequent siblings)
  22 siblings, 0 replies; 28+ messages in thread
From: Eric Biggers @ 2020-05-02  5:31 UTC (permalink / raw)
  To: linux-crypto; +Cc: Jesper Nilsson, Lars Persson

From: Eric Biggers <ebiggers@google.com>

Instead of manually allocating a 'struct shash_desc' on the stack and
calling crypto_shash_digest(), switch to using the new helper function
crypto_shash_tfm_digest() which does this for us.

Cc: Jesper Nilsson <jesper.nilsson@axis.com>
Cc: Lars Persson <lars.persson@axis.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 drivers/crypto/axis/artpec6_crypto.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/drivers/crypto/axis/artpec6_crypto.c b/drivers/crypto/axis/artpec6_crypto.c
index fcf1effc7661ec..62ba0325a61871 100644
--- a/drivers/crypto/axis/artpec6_crypto.c
+++ b/drivers/crypto/axis/artpec6_crypto.c
@@ -2239,16 +2239,12 @@ artpec6_crypto_hash_set_key(struct crypto_ahash *tfm,
 	blocksize = crypto_tfm_alg_blocksize(crypto_ahash_tfm(tfm));
 
 	if (keylen > blocksize) {
-		SHASH_DESC_ON_STACK(hdesc, tfm_ctx->child_hash);
-
-		hdesc->tfm = tfm_ctx->child_hash;
-
 		tfm_ctx->hmac_key_length = blocksize;
-		ret = crypto_shash_digest(hdesc, key, keylen,
-					  tfm_ctx->hmac_key);
+
+		ret = crypto_shash_tfm_digest(tfm_ctx->child_hash, key, keylen,
+					      tfm_ctx->hmac_key);
 		if (ret)
 			return ret;
-
 	} else {
 		memcpy(tfm_ctx->hmac_key, key, keylen);
 		tfm_ctx->hmac_key_length = keylen;
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 05/20] crypto: ccp - use crypto_shash_tfm_digest()
  2020-05-02  5:31 [PATCH 00/20] crypto: introduce crypto_shash_tfm_digest() Eric Biggers
                   ` (3 preceding siblings ...)
  2020-05-02  5:31 ` [PATCH 04/20] crypto: artpec6 " Eric Biggers
@ 2020-05-02  5:31 ` Eric Biggers
  2020-05-07 21:23   ` Tom Lendacky
  2020-05-02  5:31 ` [PATCH 06/20] crypto: ccree " Eric Biggers
                   ` (17 subsequent siblings)
  22 siblings, 1 reply; 28+ messages in thread
From: Eric Biggers @ 2020-05-02  5:31 UTC (permalink / raw)
  To: linux-crypto; +Cc: Tom Lendacky

From: Eric Biggers <ebiggers@google.com>

Instead of manually allocating a 'struct shash_desc' on the stack and
calling crypto_shash_digest(), switch to using the new helper function
crypto_shash_tfm_digest() which does this for us.

Cc: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 drivers/crypto/ccp/ccp-crypto-sha.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/crypto/ccp/ccp-crypto-sha.c b/drivers/crypto/ccp/ccp-crypto-sha.c
index 474e6f1a6a84ec..b0cc2bd73af804 100644
--- a/drivers/crypto/ccp/ccp-crypto-sha.c
+++ b/drivers/crypto/ccp/ccp-crypto-sha.c
@@ -272,9 +272,6 @@ static int ccp_sha_setkey(struct crypto_ahash *tfm, const u8 *key,
 {
 	struct ccp_ctx *ctx = crypto_tfm_ctx(crypto_ahash_tfm(tfm));
 	struct crypto_shash *shash = ctx->u.sha.hmac_tfm;
-
-	SHASH_DESC_ON_STACK(sdesc, shash);
-
 	unsigned int block_size = crypto_shash_blocksize(shash);
 	unsigned int digest_size = crypto_shash_digestsize(shash);
 	int i, ret;
@@ -289,10 +286,8 @@ static int ccp_sha_setkey(struct crypto_ahash *tfm, const u8 *key,
 
 	if (key_len > block_size) {
 		/* Must hash the input key */
-		sdesc->tfm = shash;
-
-		ret = crypto_shash_digest(sdesc, key, key_len,
-					  ctx->u.sha.key);
+		ret = crypto_shash_tfm_digest(shash, key, key_len,
+					      ctx->u.sha.key);
 		if (ret)
 			return -EINVAL;
 
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 06/20] crypto: ccree - use crypto_shash_tfm_digest()
  2020-05-02  5:31 [PATCH 00/20] crypto: introduce crypto_shash_tfm_digest() Eric Biggers
                   ` (4 preceding siblings ...)
  2020-05-02  5:31 ` [PATCH 05/20] crypto: ccp " Eric Biggers
@ 2020-05-02  5:31 ` Eric Biggers
  2020-05-03 14:01   ` Gilad Ben-Yossef
  2020-05-02  5:31 ` [PATCH 07/20] crypto: hisilicon/sec2 " Eric Biggers
                   ` (16 subsequent siblings)
  22 siblings, 1 reply; 28+ messages in thread
From: Eric Biggers @ 2020-05-02  5:31 UTC (permalink / raw)
  To: linux-crypto; +Cc: Gilad Ben-Yossef

From: Eric Biggers <ebiggers@google.com>

Instead of manually allocating a 'struct shash_desc' on the stack and
calling crypto_shash_digest(), switch to using the new helper function
crypto_shash_tfm_digest() which does this for us.

Cc: Gilad Ben-Yossef <gilad@benyossef.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 drivers/crypto/ccree/cc_cipher.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/crypto/ccree/cc_cipher.c b/drivers/crypto/ccree/cc_cipher.c
index a84335328f371c..872ea3ff1c6ba7 100644
--- a/drivers/crypto/ccree/cc_cipher.c
+++ b/drivers/crypto/ccree/cc_cipher.c
@@ -427,12 +427,9 @@ static int cc_cipher_setkey(struct crypto_skcipher *sktfm, const u8 *key,
 		int key_len = keylen >> 1;
 		int err;
 
-		SHASH_DESC_ON_STACK(desc, ctx_p->shash_tfm);
-
-		desc->tfm = ctx_p->shash_tfm;
-
-		err = crypto_shash_digest(desc, ctx_p->user.key, key_len,
-					  ctx_p->user.key + key_len);
+		err = crypto_shash_tfm_digest(ctx_p->shash_tfm,
+					      ctx_p->user.key, key_len,
+					      ctx_p->user.key + key_len);
 		if (err) {
 			dev_err(dev, "Failed to hash ESSIV key.\n");
 			return err;
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 07/20] crypto: hisilicon/sec2 - use crypto_shash_tfm_digest()
  2020-05-02  5:31 [PATCH 00/20] crypto: introduce crypto_shash_tfm_digest() Eric Biggers
                   ` (5 preceding siblings ...)
  2020-05-02  5:31 ` [PATCH 06/20] crypto: ccree " Eric Biggers
@ 2020-05-02  5:31 ` Eric Biggers
  2020-05-02  5:31 ` [PATCH 08/20] crypto: mediatek " Eric Biggers
                   ` (15 subsequent siblings)
  22 siblings, 0 replies; 28+ messages in thread
From: Eric Biggers @ 2020-05-02  5:31 UTC (permalink / raw)
  To: linux-crypto; +Cc: Zaibo Xu

From: Eric Biggers <ebiggers@google.com>

Instead of manually allocating a 'struct shash_desc' on the stack and
calling crypto_shash_digest(), switch to using the new helper function
crypto_shash_tfm_digest() which does this for us.

Cc: Zaibo Xu <xuzaibo@huawei.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 drivers/crypto/hisilicon/sec2/sec_crypto.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/crypto/hisilicon/sec2/sec_crypto.c b/drivers/crypto/hisilicon/sec2/sec_crypto.c
index 7f1c6a31b82f35..848ab492d26e3e 100644
--- a/drivers/crypto/hisilicon/sec2/sec_crypto.c
+++ b/drivers/crypto/hisilicon/sec2/sec_crypto.c
@@ -832,7 +832,6 @@ static int sec_aead_auth_set_key(struct sec_auth_ctx *ctx,
 				 struct crypto_authenc_keys *keys)
 {
 	struct crypto_shash *hash_tfm = ctx->hash_tfm;
-	SHASH_DESC_ON_STACK(shash, hash_tfm);
 	int blocksize, ret;
 
 	if (!keys->authkeylen) {
@@ -842,8 +841,8 @@ static int sec_aead_auth_set_key(struct sec_auth_ctx *ctx,
 
 	blocksize = crypto_shash_blocksize(hash_tfm);
 	if (keys->authkeylen > blocksize) {
-		ret = crypto_shash_digest(shash, keys->authkey,
-					  keys->authkeylen, ctx->a_key);
+		ret = crypto_shash_tfm_digest(hash_tfm, keys->authkey,
+					      keys->authkeylen, ctx->a_key);
 		if (ret) {
 			pr_err("hisi_sec2: aead auth digest error!\n");
 			return -EINVAL;
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 08/20] crypto: mediatek - use crypto_shash_tfm_digest()
  2020-05-02  5:31 [PATCH 00/20] crypto: introduce crypto_shash_tfm_digest() Eric Biggers
                   ` (6 preceding siblings ...)
  2020-05-02  5:31 ` [PATCH 07/20] crypto: hisilicon/sec2 " Eric Biggers
@ 2020-05-02  5:31 ` Eric Biggers
  2020-05-02  5:31 ` [PATCH 09/20] crypto: n2 " Eric Biggers
                   ` (14 subsequent siblings)
  22 siblings, 0 replies; 28+ messages in thread
From: Eric Biggers @ 2020-05-02  5:31 UTC (permalink / raw)
  To: linux-crypto

From: Eric Biggers <ebiggers@google.com>

Instead of manually allocating a 'struct shash_desc' on the stack and
calling crypto_shash_digest(), switch to using the new helper function
crypto_shash_tfm_digest() which does this for us.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 drivers/crypto/mediatek/mtk-sha.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/crypto/mediatek/mtk-sha.c b/drivers/crypto/mediatek/mtk-sha.c
index bd6309e57ab81a..da3f0b8814aa49 100644
--- a/drivers/crypto/mediatek/mtk-sha.c
+++ b/drivers/crypto/mediatek/mtk-sha.c
@@ -805,12 +805,9 @@ static int mtk_sha_setkey(struct crypto_ahash *tfm, const u8 *key,
 	size_t ds = crypto_shash_digestsize(bctx->shash);
 	int err, i;
 
-	SHASH_DESC_ON_STACK(shash, bctx->shash);
-
-	shash->tfm = bctx->shash;
-
 	if (keylen > bs) {
-		err = crypto_shash_digest(shash, key, keylen, bctx->ipad);
+		err = crypto_shash_tfm_digest(bctx->shash, key, keylen,
+					      bctx->ipad);
 		if (err)
 			return err;
 		keylen = ds;
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 09/20] crypto: n2 - use crypto_shash_tfm_digest()
  2020-05-02  5:31 [PATCH 00/20] crypto: introduce crypto_shash_tfm_digest() Eric Biggers
                   ` (7 preceding siblings ...)
  2020-05-02  5:31 ` [PATCH 08/20] crypto: mediatek " Eric Biggers
@ 2020-05-02  5:31 ` Eric Biggers
  2020-05-02  5:31 ` [PATCH 10/20] crypto: omap-sham " Eric Biggers
                   ` (13 subsequent siblings)
  22 siblings, 0 replies; 28+ messages in thread
From: Eric Biggers @ 2020-05-02  5:31 UTC (permalink / raw)
  To: linux-crypto

From: Eric Biggers <ebiggers@google.com>

Instead of manually allocating a 'struct shash_desc' on the stack and
calling crypto_shash_digest(), switch to using the new helper function
crypto_shash_tfm_digest() which does this for us.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 drivers/crypto/n2_core.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/crypto/n2_core.c b/drivers/crypto/n2_core.c
index f5c468f2cc82e9..6a828bbecea400 100644
--- a/drivers/crypto/n2_core.c
+++ b/drivers/crypto/n2_core.c
@@ -462,7 +462,6 @@ static int n2_hmac_async_setkey(struct crypto_ahash *tfm, const u8 *key,
 	struct n2_hmac_ctx *ctx = crypto_ahash_ctx(tfm);
 	struct crypto_shash *child_shash = ctx->child_shash;
 	struct crypto_ahash *fallback_tfm;
-	SHASH_DESC_ON_STACK(shash, child_shash);
 	int err, bs, ds;
 
 	fallback_tfm = ctx->base.fallback_tfm;
@@ -470,14 +469,12 @@ static int n2_hmac_async_setkey(struct crypto_ahash *tfm, const u8 *key,
 	if (err)
 		return err;
 
-	shash->tfm = child_shash;
-
 	bs = crypto_shash_blocksize(child_shash);
 	ds = crypto_shash_digestsize(child_shash);
 	BUG_ON(ds > N2_HASH_KEY_MAX);
 	if (keylen > bs) {
-		err = crypto_shash_digest(shash, key, keylen,
-					  ctx->hash_key);
+		err = crypto_shash_tfm_digest(child_shash, key, keylen,
+					      ctx->hash_key);
 		if (err)
 			return err;
 		keylen = ds;
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 10/20] crypto: omap-sham - use crypto_shash_tfm_digest()
  2020-05-02  5:31 [PATCH 00/20] crypto: introduce crypto_shash_tfm_digest() Eric Biggers
                   ` (8 preceding siblings ...)
  2020-05-02  5:31 ` [PATCH 09/20] crypto: n2 " Eric Biggers
@ 2020-05-02  5:31 ` Eric Biggers
  2020-05-02  5:31 ` [PATCH 11/20] crypto: s5p-sss " Eric Biggers
                   ` (12 subsequent siblings)
  22 siblings, 0 replies; 28+ messages in thread
From: Eric Biggers @ 2020-05-02  5:31 UTC (permalink / raw)
  To: linux-crypto

From: Eric Biggers <ebiggers@google.com>

Instead of manually allocating a 'struct shash_desc' on the stack and
calling crypto_shash_digest(), switch to using the new helper function
crypto_shash_tfm_digest() which does this for us.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 drivers/crypto/omap-sham.c | 20 ++++----------------
 1 file changed, 4 insertions(+), 16 deletions(-)

diff --git a/drivers/crypto/omap-sham.c b/drivers/crypto/omap-sham.c
index e4072cd385857c..d600c5b3fdd3f6 100644
--- a/drivers/crypto/omap-sham.c
+++ b/drivers/crypto/omap-sham.c
@@ -1245,16 +1245,6 @@ static int omap_sham_update(struct ahash_request *req)
 	return omap_sham_enqueue(req, OP_UPDATE);
 }
 
-static int omap_sham_shash_digest(struct crypto_shash *tfm, u32 flags,
-				  const u8 *data, unsigned int len, u8 *out)
-{
-	SHASH_DESC_ON_STACK(shash, tfm);
-
-	shash->tfm = tfm;
-
-	return crypto_shash_digest(shash, data, len, out);
-}
-
 static int omap_sham_final_shash(struct ahash_request *req)
 {
 	struct omap_sham_ctx *tctx = crypto_tfm_ctx(req->base.tfm);
@@ -1270,9 +1260,8 @@ static int omap_sham_final_shash(struct ahash_request *req)
 	    !test_bit(FLAGS_AUTO_XOR, &ctx->dd->flags))
 		offset = get_block_size(ctx);
 
-	return omap_sham_shash_digest(tctx->fallback, req->base.flags,
-				      ctx->buffer + offset,
-				      ctx->bufcnt - offset, req->result);
+	return crypto_shash_tfm_digest(tctx->fallback, ctx->buffer + offset,
+				       ctx->bufcnt - offset, req->result);
 }
 
 static int omap_sham_final(struct ahash_request *req)
@@ -1351,9 +1340,8 @@ static int omap_sham_setkey(struct crypto_ahash *tfm, const u8 *key,
 		return err;
 
 	if (keylen > bs) {
-		err = omap_sham_shash_digest(bctx->shash,
-				crypto_shash_get_flags(bctx->shash),
-				key, keylen, bctx->ipad);
+		err = crypto_shash_tfm_digest(bctx->shash, key, keylen,
+					      bctx->ipad);
 		if (err)
 			return err;
 		keylen = ds;
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 11/20] crypto: s5p-sss - use crypto_shash_tfm_digest()
  2020-05-02  5:31 [PATCH 00/20] crypto: introduce crypto_shash_tfm_digest() Eric Biggers
                   ` (9 preceding siblings ...)
  2020-05-02  5:31 ` [PATCH 10/20] crypto: omap-sham " Eric Biggers
@ 2020-05-02  5:31 ` Eric Biggers
  2020-05-05 14:19   ` Krzysztof Kozlowski
  2020-05-02  5:31 ` [PATCH 12/20] nfc: s3fwrn5: " Eric Biggers
                   ` (11 subsequent siblings)
  22 siblings, 1 reply; 28+ messages in thread
From: Eric Biggers @ 2020-05-02  5:31 UTC (permalink / raw)
  To: linux-crypto; +Cc: Krzysztof Kozlowski, Vladimir Zapolskiy, Kamil Konieczny

From: Eric Biggers <ebiggers@google.com>

Instead of manually allocating a 'struct shash_desc' on the stack and
calling crypto_shash_digest(), switch to using the new helper function
crypto_shash_tfm_digest() which does this for us.

Cc: Krzysztof Kozlowski <krzk@kernel.org>
Cc: Vladimir Zapolskiy <vz@mleia.com>
Cc: Kamil Konieczny <k.konieczny@samsung.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 drivers/crypto/s5p-sss.c | 39 ++++++---------------------------------
 1 file changed, 6 insertions(+), 33 deletions(-)

diff --git a/drivers/crypto/s5p-sss.c b/drivers/crypto/s5p-sss.c
index 2a16800d257954..341433fbcc4a8b 100644
--- a/drivers/crypto/s5p-sss.c
+++ b/drivers/crypto/s5p-sss.c
@@ -1520,37 +1520,6 @@ static int s5p_hash_update(struct ahash_request *req)
 	return s5p_hash_enqueue(req, true); /* HASH_OP_UPDATE */
 }
 
-/**
- * s5p_hash_shash_digest() - calculate shash digest
- * @tfm:	crypto transformation
- * @flags:	tfm flags
- * @data:	input data
- * @len:	length of data
- * @out:	output buffer
- */
-static int s5p_hash_shash_digest(struct crypto_shash *tfm, u32 flags,
-				 const u8 *data, unsigned int len, u8 *out)
-{
-	SHASH_DESC_ON_STACK(shash, tfm);
-
-	shash->tfm = tfm;
-
-	return crypto_shash_digest(shash, data, len, out);
-}
-
-/**
- * s5p_hash_final_shash() - calculate shash digest
- * @req:	AHASH request
- */
-static int s5p_hash_final_shash(struct ahash_request *req)
-{
-	struct s5p_hash_ctx *tctx = crypto_tfm_ctx(req->base.tfm);
-	struct s5p_hash_reqctx *ctx = ahash_request_ctx(req);
-
-	return s5p_hash_shash_digest(tctx->fallback, req->base.flags,
-				     ctx->buffer, ctx->bufcnt, req->result);
-}
-
 /**
  * s5p_hash_final() - close up hash and calculate digest
  * @req:	AHASH request
@@ -1582,8 +1551,12 @@ static int s5p_hash_final(struct ahash_request *req)
 	if (ctx->error)
 		return -EINVAL; /* uncompleted hash is not needed */
 
-	if (!ctx->digcnt && ctx->bufcnt < BUFLEN)
-		return s5p_hash_final_shash(req);
+	if (!ctx->digcnt && ctx->bufcnt < BUFLEN) {
+		struct s5p_hash_ctx *tctx = crypto_tfm_ctx(req->base.tfm);
+
+		return crypto_shash_tfm_digest(tctx->fallback, ctx->buffer,
+					       ctx->bufcnt, req->result);
+	}
 
 	return s5p_hash_enqueue(req, false); /* HASH_OP_FINAL */
 }
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 12/20] nfc: s3fwrn5: use crypto_shash_tfm_digest()
  2020-05-02  5:31 [PATCH 00/20] crypto: introduce crypto_shash_tfm_digest() Eric Biggers
                   ` (10 preceding siblings ...)
  2020-05-02  5:31 ` [PATCH 11/20] crypto: s5p-sss " Eric Biggers
@ 2020-05-02  5:31 ` Eric Biggers
  2020-05-02  5:31 ` [PATCH 13/20] fscrypt: " Eric Biggers
                   ` (10 subsequent siblings)
  22 siblings, 0 replies; 28+ messages in thread
From: Eric Biggers @ 2020-05-02  5:31 UTC (permalink / raw)
  To: linux-crypto; +Cc: Robert Baldyga, Krzysztof Opasiak

From: Eric Biggers <ebiggers@google.com>

Instead of manually allocating a 'struct shash_desc' on the stack and
calling crypto_shash_digest(), switch to using the new helper function
crypto_shash_tfm_digest() which does this for us.

Cc: Robert Baldyga <r.baldyga@samsung.com>
Cc: Krzysztof Opasiak <k.opasiak@samsung.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 drivers/nfc/s3fwrn5/firmware.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/drivers/nfc/s3fwrn5/firmware.c b/drivers/nfc/s3fwrn5/firmware.c
index de613c623a2cf0..69857f0807040c 100644
--- a/drivers/nfc/s3fwrn5/firmware.c
+++ b/drivers/nfc/s3fwrn5/firmware.c
@@ -434,15 +434,7 @@ int s3fwrn5_fw_download(struct s3fwrn5_fw_info *fw_info)
 		goto out;
 	}
 
-	{
-		SHASH_DESC_ON_STACK(desc, tfm);
-
-		desc->tfm = tfm;
-
-		ret = crypto_shash_digest(desc, fw->image, image_size,
-					  hash_data);
-		shash_desc_zero(desc);
-	}
+	ret = crypto_shash_tfm_digest(tfm, fw->image, image_size, hash_data);
 
 	crypto_free_shash(tfm);
 	if (ret) {
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 13/20] fscrypt: use crypto_shash_tfm_digest()
  2020-05-02  5:31 [PATCH 00/20] crypto: introduce crypto_shash_tfm_digest() Eric Biggers
                   ` (11 preceding siblings ...)
  2020-05-02  5:31 ` [PATCH 12/20] nfc: s3fwrn5: " Eric Biggers
@ 2020-05-02  5:31 ` Eric Biggers
  2020-05-02  5:31 ` [PATCH 14/20] ecryptfs: " Eric Biggers
                   ` (9 subsequent siblings)
  22 siblings, 0 replies; 28+ messages in thread
From: Eric Biggers @ 2020-05-02  5:31 UTC (permalink / raw)
  To: linux-crypto

From: Eric Biggers <ebiggers@google.com>

Instead of manually allocating a 'struct shash_desc' on the stack and
calling crypto_shash_digest(), switch to using the new helper function
crypto_shash_tfm_digest() which does this for us.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 fs/crypto/fname.c | 7 +------
 fs/crypto/hkdf.c  | 6 +-----
 2 files changed, 2 insertions(+), 11 deletions(-)

diff --git a/fs/crypto/fname.c b/fs/crypto/fname.c
index 4c212442a8f7f1..5c9fb013e3f757 100644
--- a/fs/crypto/fname.c
+++ b/fs/crypto/fname.c
@@ -83,13 +83,8 @@ static int fscrypt_do_sha256(const u8 *data, unsigned int data_len, u8 *result)
 			tfm = prev_tfm;
 		}
 	}
-	{
-		SHASH_DESC_ON_STACK(desc, tfm);
 
-		desc->tfm = tfm;
-
-		return crypto_shash_digest(desc, data, data_len, result);
-	}
+	return crypto_shash_tfm_digest(tfm, data, data_len, result);
 }
 
 static inline bool fscrypt_is_dot_dotdot(const struct qstr *str)
diff --git a/fs/crypto/hkdf.c b/fs/crypto/hkdf.c
index efb95bd19a8948..0cba7928446d34 100644
--- a/fs/crypto/hkdf.c
+++ b/fs/crypto/hkdf.c
@@ -44,17 +44,13 @@ static int hkdf_extract(struct crypto_shash *hmac_tfm, const u8 *ikm,
 			unsigned int ikmlen, u8 prk[HKDF_HASHLEN])
 {
 	static const u8 default_salt[HKDF_HASHLEN];
-	SHASH_DESC_ON_STACK(desc, hmac_tfm);
 	int err;
 
 	err = crypto_shash_setkey(hmac_tfm, default_salt, HKDF_HASHLEN);
 	if (err)
 		return err;
 
-	desc->tfm = hmac_tfm;
-	err = crypto_shash_digest(desc, ikm, ikmlen, prk);
-	shash_desc_zero(desc);
-	return err;
+	return crypto_shash_tfm_digest(hmac_tfm, ikm, ikmlen, prk);
 }
 
 /*
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 14/20] ecryptfs: use crypto_shash_tfm_digest()
  2020-05-02  5:31 [PATCH 00/20] crypto: introduce crypto_shash_tfm_digest() Eric Biggers
                   ` (12 preceding siblings ...)
  2020-05-02  5:31 ` [PATCH 13/20] fscrypt: " Eric Biggers
@ 2020-05-02  5:31 ` Eric Biggers
  2020-05-02  5:31 ` [PATCH 15/20] nfsd: " Eric Biggers
                   ` (8 subsequent siblings)
  22 siblings, 0 replies; 28+ messages in thread
From: Eric Biggers @ 2020-05-02  5:31 UTC (permalink / raw)
  To: linux-crypto; +Cc: ecryptfs

From: Eric Biggers <ebiggers@google.com>

Instead of manually allocating a 'struct shash_desc' on the stack and
calling crypto_shash_digest(), switch to using the new helper function
crypto_shash_tfm_digest() which does this for us.

Cc: ecryptfs@vger.kernel.org
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 fs/ecryptfs/crypto.c | 17 +----------------
 1 file changed, 1 insertion(+), 16 deletions(-)

diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c
index 2c449aed1b9209..0681540c48d985 100644
--- a/fs/ecryptfs/crypto.c
+++ b/fs/ecryptfs/crypto.c
@@ -48,18 +48,6 @@ void ecryptfs_from_hex(char *dst, char *src, int dst_size)
 	}
 }
 
-static int ecryptfs_hash_digest(struct crypto_shash *tfm,
-				char *src, int len, char *dst)
-{
-	SHASH_DESC_ON_STACK(desc, tfm);
-	int err;
-
-	desc->tfm = tfm;
-	err = crypto_shash_digest(desc, src, len, dst);
-	shash_desc_zero(desc);
-	return err;
-}
-
 /**
  * ecryptfs_calculate_md5 - calculates the md5 of @src
  * @dst: Pointer to 16 bytes of allocated memory
@@ -74,11 +62,8 @@ static int ecryptfs_calculate_md5(char *dst,
 				  struct ecryptfs_crypt_stat *crypt_stat,
 				  char *src, int len)
 {
-	struct crypto_shash *tfm;
-	int rc = 0;
+	int rc = crypto_shash_tfm_digest(crypt_stat->hash_tfm, src, len, dst);
 
-	tfm = crypt_stat->hash_tfm;
-	rc = ecryptfs_hash_digest(tfm, src, len, dst);
 	if (rc) {
 		printk(KERN_ERR
 		       "%s: Error computing crypto hash; rc = [%d]\n",
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 15/20] nfsd: use crypto_shash_tfm_digest()
  2020-05-02  5:31 [PATCH 00/20] crypto: introduce crypto_shash_tfm_digest() Eric Biggers
                   ` (13 preceding siblings ...)
  2020-05-02  5:31 ` [PATCH 14/20] ecryptfs: " Eric Biggers
@ 2020-05-02  5:31 ` Eric Biggers
  2020-05-04 19:09   ` J. Bruce Fields
  2020-05-02  5:31 ` [PATCH 16/20] ubifs: " Eric Biggers
                   ` (7 subsequent siblings)
  22 siblings, 1 reply; 28+ messages in thread
From: Eric Biggers @ 2020-05-02  5:31 UTC (permalink / raw)
  To: linux-crypto; +Cc: linux-nfs

From: Eric Biggers <ebiggers@google.com>

Instead of manually allocating a 'struct shash_desc' on the stack and
calling crypto_shash_digest(), switch to using the new helper function
crypto_shash_tfm_digest() which does this for us.

Cc: linux-nfs@vger.kernel.org
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 fs/nfsd/nfs4recover.c | 26 ++++++--------------------
 1 file changed, 6 insertions(+), 20 deletions(-)

diff --git a/fs/nfsd/nfs4recover.c b/fs/nfsd/nfs4recover.c
index a8fb18609146a2..9e40dfecf1b1a6 100644
--- a/fs/nfsd/nfs4recover.c
+++ b/fs/nfsd/nfs4recover.c
@@ -127,16 +127,8 @@ nfs4_make_rec_clidname(char *dname, const struct xdr_netobj *clname)
  		goto out;
 	}
 
-	{
-		SHASH_DESC_ON_STACK(desc, tfm);
-
-		desc->tfm = tfm;
-
-		status = crypto_shash_digest(desc, clname->data, clname->len,
-					     cksum.data);
-		shash_desc_zero(desc);
-	}
-
+	status = crypto_shash_tfm_digest(tfm, clname->data, clname->len,
+					 cksum.data);
 	if (status)
 		goto out;
 
@@ -1148,7 +1140,6 @@ nfsd4_cld_create_v2(struct nfs4_client *clp)
 	struct crypto_shash *tfm = cn->cn_tfm;
 	struct xdr_netobj cksum;
 	char *principal = NULL;
-	SHASH_DESC_ON_STACK(desc, tfm);
 
 	/* Don't upcall if it's already stored */
 	if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
@@ -1170,16 +1161,14 @@ nfsd4_cld_create_v2(struct nfs4_client *clp)
 	else if (clp->cl_cred.cr_principal)
 		principal = clp->cl_cred.cr_principal;
 	if (principal) {
-		desc->tfm = tfm;
 		cksum.len = crypto_shash_digestsize(tfm);
 		cksum.data = kmalloc(cksum.len, GFP_KERNEL);
 		if (cksum.data == NULL) {
 			ret = -ENOMEM;
 			goto out;
 		}
-		ret = crypto_shash_digest(desc, principal, strlen(principal),
-					  cksum.data);
-		shash_desc_zero(desc);
+		ret = crypto_shash_tfm_digest(tfm, principal, strlen(principal),
+					      cksum.data);
 		if (ret) {
 			kfree(cksum.data);
 			goto out;
@@ -1343,7 +1332,6 @@ nfsd4_cld_check_v2(struct nfs4_client *clp)
 	struct crypto_shash *tfm = cn->cn_tfm;
 	struct xdr_netobj cksum;
 	char *principal = NULL;
-	SHASH_DESC_ON_STACK(desc, tfm);
 
 	/* did we already find that this client is stable? */
 	if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
@@ -1381,14 +1369,12 @@ nfsd4_cld_check_v2(struct nfs4_client *clp)
 			principal = clp->cl_cred.cr_principal;
 		if (principal == NULL)
 			return -ENOENT;
-		desc->tfm = tfm;
 		cksum.len = crypto_shash_digestsize(tfm);
 		cksum.data = kmalloc(cksum.len, GFP_KERNEL);
 		if (cksum.data == NULL)
 			return -ENOENT;
-		status = crypto_shash_digest(desc, principal, strlen(principal),
-					     cksum.data);
-		shash_desc_zero(desc);
+		status = crypto_shash_tfm_digest(tfm, principal,
+						 strlen(principal), cksum.data);
 		if (status) {
 			kfree(cksum.data);
 			return -ENOENT;
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 16/20] ubifs: use crypto_shash_tfm_digest()
  2020-05-02  5:31 [PATCH 00/20] crypto: introduce crypto_shash_tfm_digest() Eric Biggers
                   ` (14 preceding siblings ...)
  2020-05-02  5:31 ` [PATCH 15/20] nfsd: " Eric Biggers
@ 2020-05-02  5:31 ` Eric Biggers
  2020-05-02  5:31 ` [PATCH 17/20] Bluetooth: " Eric Biggers
                   ` (6 subsequent siblings)
  22 siblings, 0 replies; 28+ messages in thread
From: Eric Biggers @ 2020-05-02  5:31 UTC (permalink / raw)
  To: linux-crypto; +Cc: linux-mtd

From: Eric Biggers <ebiggers@google.com>

Instead of manually allocating a 'struct shash_desc' on the stack and
calling crypto_shash_digest(), switch to using the new helper function
crypto_shash_tfm_digest() which does this for us.

Cc: linux-mtd@lists.infradead.org
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 fs/ubifs/auth.c   | 20 +++-----------------
 fs/ubifs/master.c |  9 +++------
 fs/ubifs/replay.c | 14 +++-----------
 3 files changed, 9 insertions(+), 34 deletions(-)

diff --git a/fs/ubifs/auth.c b/fs/ubifs/auth.c
index 8cdbd53d780ca7..1e374baafc5255 100644
--- a/fs/ubifs/auth.c
+++ b/fs/ubifs/auth.c
@@ -31,15 +31,9 @@ int __ubifs_node_calc_hash(const struct ubifs_info *c, const void *node,
 			    u8 *hash)
 {
 	const struct ubifs_ch *ch = node;
-	SHASH_DESC_ON_STACK(shash, c->hash_tfm);
-	int err;
-
-	shash->tfm = c->hash_tfm;
 
-	err = crypto_shash_digest(shash, node, le32_to_cpu(ch->len), hash);
-	if (err < 0)
-		return err;
-	return 0;
+	return crypto_shash_tfm_digest(c->hash_tfm, node, le32_to_cpu(ch->len),
+				       hash);
 }
 
 /**
@@ -53,15 +47,7 @@ int __ubifs_node_calc_hash(const struct ubifs_info *c, const void *node,
 static int ubifs_hash_calc_hmac(const struct ubifs_info *c, const u8 *hash,
 				 u8 *hmac)
 {
-	SHASH_DESC_ON_STACK(shash, c->hmac_tfm);
-	int err;
-
-	shash->tfm = c->hmac_tfm;
-
-	err = crypto_shash_digest(shash, hash, c->hash_len, hmac);
-	if (err < 0)
-		return err;
-	return 0;
+	return crypto_shash_tfm_digest(c->hmac_tfm, hash, c->hash_len, hmac);
 }
 
 /**
diff --git a/fs/ubifs/master.c b/fs/ubifs/master.c
index 52a85c01397ef9..911d0555b9f2b1 100644
--- a/fs/ubifs/master.c
+++ b/fs/ubifs/master.c
@@ -68,12 +68,9 @@ static int mst_node_check_hash(const struct ubifs_info *c,
 	u8 calc[UBIFS_MAX_HASH_LEN];
 	const void *node = mst;
 
-	SHASH_DESC_ON_STACK(shash, c->hash_tfm);
-
-	shash->tfm = c->hash_tfm;
-
-	crypto_shash_digest(shash, node + sizeof(struct ubifs_ch),
-			    UBIFS_MST_NODE_SZ - sizeof(struct ubifs_ch), calc);
+	crypto_shash_tfm_digest(c->hash_tfm, node + sizeof(struct ubifs_ch),
+				UBIFS_MST_NODE_SZ - sizeof(struct ubifs_ch),
+				calc);
 
 	if (ubifs_check_hash(c, expected, calc))
 		return -EPERM;
diff --git a/fs/ubifs/replay.c b/fs/ubifs/replay.c
index b28ac4dfb4070a..c4047a8f641077 100644
--- a/fs/ubifs/replay.c
+++ b/fs/ubifs/replay.c
@@ -558,7 +558,7 @@ static int is_last_bud(struct ubifs_info *c, struct ubifs_bud *bud)
 	return data == 0xFFFFFFFF;
 }
 
-/* authenticate_sleb_hash and authenticate_sleb_hmac are split out for stack usage */
+/* authenticate_sleb_hash is split out for stack usage */
 static int authenticate_sleb_hash(struct ubifs_info *c, struct shash_desc *log_hash, u8 *hash)
 {
 	SHASH_DESC_ON_STACK(hash_desc, c->hash_tfm);
@@ -569,15 +569,6 @@ static int authenticate_sleb_hash(struct ubifs_info *c, struct shash_desc *log_h
 	return crypto_shash_final(hash_desc, hash);
 }
 
-static int authenticate_sleb_hmac(struct ubifs_info *c, u8 *hash, u8 *hmac)
-{
-	SHASH_DESC_ON_STACK(hmac_desc, c->hmac_tfm);
-
-	hmac_desc->tfm = c->hmac_tfm;
-
-	return crypto_shash_digest(hmac_desc, hash, c->hash_len, hmac);
-}
-
 /**
  * authenticate_sleb - authenticate one scan LEB
  * @c: UBIFS file-system description object
@@ -624,7 +615,8 @@ static int authenticate_sleb(struct ubifs_info *c, struct ubifs_scan_leb *sleb,
 			if (err)
 				goto out;
 
-			err = authenticate_sleb_hmac(c, hash, hmac);
+			err = crypto_shash_tfm_digest(c->hmac_tfm, hash,
+						      c->hash_len, hmac);
 			if (err)
 				goto out;
 
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 17/20] Bluetooth: use crypto_shash_tfm_digest()
  2020-05-02  5:31 [PATCH 00/20] crypto: introduce crypto_shash_tfm_digest() Eric Biggers
                   ` (15 preceding siblings ...)
  2020-05-02  5:31 ` [PATCH 16/20] ubifs: " Eric Biggers
@ 2020-05-02  5:31 ` Eric Biggers
  2020-05-02  5:31 ` [PATCH 18/20] sctp: " Eric Biggers
                   ` (5 subsequent siblings)
  22 siblings, 0 replies; 28+ messages in thread
From: Eric Biggers @ 2020-05-02  5:31 UTC (permalink / raw)
  To: linux-crypto; +Cc: linux-bluetooth

From: Eric Biggers <ebiggers@google.com>

Instead of manually allocating a 'struct shash_desc' on the stack and
calling crypto_shash_digest(), switch to using the new helper function
crypto_shash_tfm_digest() which does this for us.

Cc: linux-bluetooth@vger.kernel.org
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 net/bluetooth/smp.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
index 1476a91ce93572..d022f126eb026b 100644
--- a/net/bluetooth/smp.c
+++ b/net/bluetooth/smp.c
@@ -170,7 +170,6 @@ static int aes_cmac(struct crypto_shash *tfm, const u8 k[16], const u8 *m,
 		    size_t len, u8 mac[16])
 {
 	uint8_t tmp[16], mac_msb[16], msg_msb[CMAC_MSG_MAX];
-	SHASH_DESC_ON_STACK(desc, tfm);
 	int err;
 
 	if (len > CMAC_MSG_MAX)
@@ -181,8 +180,6 @@ static int aes_cmac(struct crypto_shash *tfm, const u8 k[16], const u8 *m,
 		return -EINVAL;
 	}
 
-	desc->tfm = tfm;
-
 	/* Swap key and message from LSB to MSB */
 	swap_buf(k, tmp, 16);
 	swap_buf(m, msg_msb, len);
@@ -196,8 +193,7 @@ static int aes_cmac(struct crypto_shash *tfm, const u8 k[16], const u8 *m,
 		return err;
 	}
 
-	err = crypto_shash_digest(desc, msg_msb, len, mac_msb);
-	shash_desc_zero(desc);
+	err = crypto_shash_tfm_digest(tfm, msg_msb, len, mac_msb);
 	if (err) {
 		BT_ERR("Hash computation error %d", err);
 		return err;
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 18/20] sctp: use crypto_shash_tfm_digest()
  2020-05-02  5:31 [PATCH 00/20] crypto: introduce crypto_shash_tfm_digest() Eric Biggers
                   ` (16 preceding siblings ...)
  2020-05-02  5:31 ` [PATCH 17/20] Bluetooth: " Eric Biggers
@ 2020-05-02  5:31 ` Eric Biggers
  2020-05-02  5:31 ` [PATCH 19/20] KEYS: encrypted: " Eric Biggers
                   ` (4 subsequent siblings)
  22 siblings, 0 replies; 28+ messages in thread
From: Eric Biggers @ 2020-05-02  5:31 UTC (permalink / raw)
  To: linux-crypto; +Cc: linux-sctp

From: Eric Biggers <ebiggers@google.com>

Instead of manually allocating a 'struct shash_desc' on the stack and
calling crypto_shash_digest(), switch to using the new helper function
crypto_shash_tfm_digest() which does this for us.

Cc: linux-sctp@vger.kernel.org
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 net/sctp/auth.c          | 10 ++--------
 net/sctp/sm_make_chunk.c | 23 ++++++++---------------
 2 files changed, 10 insertions(+), 23 deletions(-)

diff --git a/net/sctp/auth.c b/net/sctp/auth.c
index 4278764d82b827..83e97e8892e05a 100644
--- a/net/sctp/auth.c
+++ b/net/sctp/auth.c
@@ -741,14 +741,8 @@ void sctp_auth_calculate_hmac(const struct sctp_association *asoc,
 	if (crypto_shash_setkey(tfm, &asoc_key->data[0], asoc_key->len))
 		goto free;
 
-	{
-		SHASH_DESC_ON_STACK(desc, tfm);
-
-		desc->tfm = tfm;
-		crypto_shash_digest(desc, (u8 *)auth,
-				    end - (unsigned char *)auth, digest);
-		shash_desc_zero(desc);
-	}
+	crypto_shash_tfm_digest(tfm, (u8 *)auth, end - (unsigned char *)auth,
+				digest);
 
 free:
 	if (free_key)
diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c
index 09050c1d5517e7..c786215ba69a54 100644
--- a/net/sctp/sm_make_chunk.c
+++ b/net/sctp/sm_make_chunk.c
@@ -1666,17 +1666,14 @@ static struct sctp_cookie_param *sctp_pack_cookie(
 	       ntohs(init_chunk->chunk_hdr->length), raw_addrs, addrs_len);
 
 	if (sctp_sk(ep->base.sk)->hmac) {
-		SHASH_DESC_ON_STACK(desc, sctp_sk(ep->base.sk)->hmac);
+		struct crypto_shash *tfm = sctp_sk(ep->base.sk)->hmac;
 		int err;
 
 		/* Sign the message.  */
-		desc->tfm = sctp_sk(ep->base.sk)->hmac;
-
-		err = crypto_shash_setkey(desc->tfm, ep->secret_key,
+		err = crypto_shash_setkey(tfm, ep->secret_key,
 					  sizeof(ep->secret_key)) ?:
-		      crypto_shash_digest(desc, (u8 *)&cookie->c, bodysize,
-					  cookie->signature);
-		shash_desc_zero(desc);
+		      crypto_shash_tfm_digest(tfm, (u8 *)&cookie->c, bodysize,
+					      cookie->signature);
 		if (err)
 			goto free_cookie;
 	}
@@ -1737,17 +1734,13 @@ struct sctp_association *sctp_unpack_cookie(
 
 	/* Check the signature.  */
 	{
-		SHASH_DESC_ON_STACK(desc, sctp_sk(ep->base.sk)->hmac);
+		struct crypto_shash *tfm = sctp_sk(ep->base.sk)->hmac;
 		int err;
 
-		desc->tfm = sctp_sk(ep->base.sk)->hmac;
-
-		err = crypto_shash_setkey(desc->tfm, ep->secret_key,
+		err = crypto_shash_setkey(tfm, ep->secret_key,
 					  sizeof(ep->secret_key)) ?:
-		      crypto_shash_digest(desc, (u8 *)bear_cookie, bodysize,
-					  digest);
-		shash_desc_zero(desc);
-
+		      crypto_shash_tfm_digest(tfm, (u8 *)bear_cookie, bodysize,
+					      digest);
 		if (err) {
 			*error = -SCTP_IERROR_NOMEM;
 			goto fail;
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 19/20] KEYS: encrypted: use crypto_shash_tfm_digest()
  2020-05-02  5:31 [PATCH 00/20] crypto: introduce crypto_shash_tfm_digest() Eric Biggers
                   ` (17 preceding siblings ...)
  2020-05-02  5:31 ` [PATCH 18/20] sctp: " Eric Biggers
@ 2020-05-02  5:31 ` Eric Biggers
  2020-05-02  5:31 ` [PATCH 20/20] ASoC: cros_ec_codec: " Eric Biggers
                   ` (3 subsequent siblings)
  22 siblings, 0 replies; 28+ messages in thread
From: Eric Biggers @ 2020-05-02  5:31 UTC (permalink / raw)
  To: linux-crypto; +Cc: keyrings

From: Eric Biggers <ebiggers@google.com>

Instead of manually allocating a 'struct shash_desc' on the stack and
calling crypto_shash_digest(), switch to using the new helper function
crypto_shash_tfm_digest() which does this for us.

Cc: keyrings@vger.kernel.org
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 security/keys/encrypted-keys/encrypted.c | 18 +++---------------
 1 file changed, 3 insertions(+), 15 deletions(-)

diff --git a/security/keys/encrypted-keys/encrypted.c b/security/keys/encrypted-keys/encrypted.c
index f6797ba44bf716..14cf81d1a30b14 100644
--- a/security/keys/encrypted-keys/encrypted.c
+++ b/security/keys/encrypted-keys/encrypted.c
@@ -323,19 +323,6 @@ static struct key *request_user_key(const char *master_desc, const u8 **master_k
 	return ukey;
 }
 
-static int calc_hash(struct crypto_shash *tfm, u8 *digest,
-		     const u8 *buf, unsigned int buflen)
-{
-	SHASH_DESC_ON_STACK(desc, tfm);
-	int err;
-
-	desc->tfm = tfm;
-
-	err = crypto_shash_digest(desc, buf, buflen, digest);
-	shash_desc_zero(desc);
-	return err;
-}
-
 static int calc_hmac(u8 *digest, const u8 *key, unsigned int keylen,
 		     const u8 *buf, unsigned int buflen)
 {
@@ -351,7 +338,7 @@ static int calc_hmac(u8 *digest, const u8 *key, unsigned int keylen,
 
 	err = crypto_shash_setkey(tfm, key, keylen);
 	if (!err)
-		err = calc_hash(tfm, digest, buf, buflen);
+		err = crypto_shash_tfm_digest(tfm, buf, buflen, digest);
 	crypto_free_shash(tfm);
 	return err;
 }
@@ -381,7 +368,8 @@ static int get_derived_key(u8 *derived_key, enum derived_key_type key_type,
 
 	memcpy(derived_buf + strlen(derived_buf) + 1, master_key,
 	       master_keylen);
-	ret = calc_hash(hash_tfm, derived_key, derived_buf, derived_buf_len);
+	ret = crypto_shash_tfm_digest(hash_tfm, derived_buf, derived_buf_len,
+				      derived_key);
 	kzfree(derived_buf);
 	return ret;
 }
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 20/20] ASoC: cros_ec_codec: use crypto_shash_tfm_digest()
  2020-05-02  5:31 [PATCH 00/20] crypto: introduce crypto_shash_tfm_digest() Eric Biggers
                   ` (18 preceding siblings ...)
  2020-05-02  5:31 ` [PATCH 19/20] KEYS: encrypted: " Eric Biggers
@ 2020-05-02  5:31 ` Eric Biggers
  2020-05-02  6:44 ` [PATCH 00/20] crypto: introduce crypto_shash_tfm_digest() Marcel Holtmann
                   ` (2 subsequent siblings)
  22 siblings, 0 replies; 28+ messages in thread
From: Eric Biggers @ 2020-05-02  5:31 UTC (permalink / raw)
  To: linux-crypto; +Cc: Cheng-Yi Chiang, Enric Balletbo i Serra, Guenter Roeck

From: Eric Biggers <ebiggers@google.com>

Instead of manually allocating a 'struct shash_desc' on the stack and
calling crypto_shash_digest(), switch to using the new helper function
crypto_shash_tfm_digest() which does this for us.

Cc: Cheng-Yi Chiang <cychiang@chromium.org>
Cc: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Cc: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 sound/soc/codecs/cros_ec_codec.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/sound/soc/codecs/cros_ec_codec.c b/sound/soc/codecs/cros_ec_codec.c
index d3dc42aa682565..bfdd852bdc0de4 100644
--- a/sound/soc/codecs/cros_ec_codec.c
+++ b/sound/soc/codecs/cros_ec_codec.c
@@ -115,14 +115,7 @@ static int calculate_sha256(struct cros_ec_codec_priv *priv,
 		return PTR_ERR(tfm);
 	}
 
-	{
-		SHASH_DESC_ON_STACK(desc, tfm);
-
-		desc->tfm = tfm;
-
-		crypto_shash_digest(desc, buf, size, digest);
-		shash_desc_zero(desc);
-	}
+	crypto_shash_tfm_digest(tfm, buf, size, digest);
 
 	crypto_free_shash(tfm);
 
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* Re: [PATCH 00/20] crypto: introduce crypto_shash_tfm_digest()
  2020-05-02  5:31 [PATCH 00/20] crypto: introduce crypto_shash_tfm_digest() Eric Biggers
                   ` (19 preceding siblings ...)
  2020-05-02  5:31 ` [PATCH 20/20] ASoC: cros_ec_codec: " Eric Biggers
@ 2020-05-02  6:44 ` Marcel Holtmann
  2020-05-03 16:13 ` Ard Biesheuvel
  2020-05-08  6:07 ` Herbert Xu
  22 siblings, 0 replies; 28+ messages in thread
From: Marcel Holtmann @ 2020-05-02  6:44 UTC (permalink / raw)
  To: Eric Biggers
  Cc: linux-crypto, Cheng-Yi Chiang, ecryptfs, Enric Balletbo i Serra,
	Gilad Ben-Yossef, Guenter Roeck, Jesper Nilsson, Kamil Konieczny,
	keyrings, Krzysztof Kozlowski, Krzysztof Opasiak, Lars Persson,
	linux-bluetooth, linux-mtd, linux-nfs, linux-sctp,
	Robert Baldyga, Tom Lendacky, Vladimir Zapolskiy, Zaibo Xu

Hi Eric,

> This series introduces a helper function crypto_shash_tfm_digest() which
> replaces the following common pattern:
> 
> 	{
> 		SHASH_DESC_ON_STACK(desc, tfm);
> 		int err;
> 
> 		desc->tfm = tfm;
> 
> 		err = crypto_shash_digest(desc, data, len, out);
> 
> 		shash_desc_zero(desc);
> 	}
> 
> with:
> 
> 	err = crypto_shash_tfm_digest(tfm, data, len, out);
> 
> Patch 1 introduces this helper function, and patches 2-20 convert all
> relevant users to use it.
> 
> IMO, it would be easiest to take all these patches through the crypto
> tree.  But taking just the "crypto:" ones and then me trying to get the
> rest merged later via subsystem trees is also an option.

I am fine if you take the net/bluetooth/smp.c change through the crypto tree.

Acked-by: Marcel Holtmann <marcel@holtmann.org>

Regards

Marcel


^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 06/20] crypto: ccree - use crypto_shash_tfm_digest()
  2020-05-02  5:31 ` [PATCH 06/20] crypto: ccree " Eric Biggers
@ 2020-05-03 14:01   ` Gilad Ben-Yossef
  0 siblings, 0 replies; 28+ messages in thread
From: Gilad Ben-Yossef @ 2020-05-03 14:01 UTC (permalink / raw)
  To: Eric Biggers; +Cc: Linux Crypto Mailing List

On Sat, May 2, 2020 at 8:33 AM Eric Biggers <ebiggers@kernel.org> wrote:
>
> From: Eric Biggers <ebiggers@google.com>
>
> Instead of manually allocating a 'struct shash_desc' on the stack and
> calling crypto_shash_digest(), switch to using the new helper function
> crypto_shash_tfm_digest() which does this for us.
>
> Cc: Gilad Ben-Yossef <gilad@benyossef.com>
> Signed-off-by: Eric Biggers <ebiggers@google.com>
> ---
>  drivers/crypto/ccree/cc_cipher.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/crypto/ccree/cc_cipher.c b/drivers/crypto/ccree/cc_cipher.c
> index a84335328f371c..872ea3ff1c6ba7 100644
> --- a/drivers/crypto/ccree/cc_cipher.c
> +++ b/drivers/crypto/ccree/cc_cipher.c
> @@ -427,12 +427,9 @@ static int cc_cipher_setkey(struct crypto_skcipher *sktfm, const u8 *key,
>                 int key_len = keylen >> 1;
>                 int err;
>
> -               SHASH_DESC_ON_STACK(desc, ctx_p->shash_tfm);
> -
> -               desc->tfm = ctx_p->shash_tfm;
> -
> -               err = crypto_shash_digest(desc, ctx_p->user.key, key_len,
> -                                         ctx_p->user.key + key_len);
> +               err = crypto_shash_tfm_digest(ctx_p->shash_tfm,
> +                                             ctx_p->user.key, key_len,
> +                                             ctx_p->user.key + key_len);
>                 if (err) {
>                         dev_err(dev, "Failed to hash ESSIV key.\n");
>                         return err;
> --
> 2.26.2
>

Acked-by: Gilad Ben-Yossef <gilad@benyossef.com>

Thanks,
Gilad


-- 
Gilad Ben-Yossef
Chief Coffee Drinker

values of β will give rise to dom!

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 00/20] crypto: introduce crypto_shash_tfm_digest()
  2020-05-02  5:31 [PATCH 00/20] crypto: introduce crypto_shash_tfm_digest() Eric Biggers
                   ` (20 preceding siblings ...)
  2020-05-02  6:44 ` [PATCH 00/20] crypto: introduce crypto_shash_tfm_digest() Marcel Holtmann
@ 2020-05-03 16:13 ` Ard Biesheuvel
  2020-05-08  6:07 ` Herbert Xu
  22 siblings, 0 replies; 28+ messages in thread
From: Ard Biesheuvel @ 2020-05-03 16:13 UTC (permalink / raw)
  To: Eric Biggers
  Cc: Linux Crypto Mailing List, Cheng-Yi Chiang, ecryptfs,
	Enric Balletbo i Serra, Gilad Ben-Yossef, Guenter Roeck,
	Jesper Nilsson, Kamil Konieczny, keyrings, Krzysztof Kozlowski,
	Krzysztof Opasiak, Lars Persson, linux-bluetooth, linux-mtd,
	linux-nfs, linux-sctp, Robert Baldyga, Tom Lendacky,
	Vladimir Zapolskiy, Zaibo Xu

On Sat, 2 May 2020 at 07:33, Eric Biggers <ebiggers@kernel.org> wrote:
>
> This series introduces a helper function crypto_shash_tfm_digest() which
> replaces the following common pattern:
>
>         {
>                 SHASH_DESC_ON_STACK(desc, tfm);
>                 int err;
>
>                 desc->tfm = tfm;
>
>                 err = crypto_shash_digest(desc, data, len, out);
>
>                 shash_desc_zero(desc);
>         }
>
> with:
>
>         err = crypto_shash_tfm_digest(tfm, data, len, out);
>
> Patch 1 introduces this helper function, and patches 2-20 convert all
> relevant users to use it.
>
> IMO, it would be easiest to take all these patches through the crypto
> tree.  But taking just the "crypto:" ones and then me trying to get the
> rest merged later via subsystem trees is also an option.
>
> Eric Biggers (20):
>   crypto: hash - introduce crypto_shash_tfm_digest()
>   crypto: arm64/aes-glue - use crypto_shash_tfm_digest()
>   crypto: essiv - use crypto_shash_tfm_digest()
>   crypto: artpec6 - use crypto_shash_tfm_digest()
>   crypto: ccp - use crypto_shash_tfm_digest()
>   crypto: ccree - use crypto_shash_tfm_digest()
>   crypto: hisilicon/sec2 - use crypto_shash_tfm_digest()
>   crypto: mediatek - use crypto_shash_tfm_digest()
>   crypto: n2 - use crypto_shash_tfm_digest()
>   crypto: omap-sham - use crypto_shash_tfm_digest()
>   crypto: s5p-sss - use crypto_shash_tfm_digest()
>   nfc: s3fwrn5: use crypto_shash_tfm_digest()
>   fscrypt: use crypto_shash_tfm_digest()
>   ecryptfs: use crypto_shash_tfm_digest()
>   nfsd: use crypto_shash_tfm_digest()
>   ubifs: use crypto_shash_tfm_digest()
>   Bluetooth: use crypto_shash_tfm_digest()
>   sctp: use crypto_shash_tfm_digest()
>   KEYS: encrypted: use crypto_shash_tfm_digest()
>   ASoC: cros_ec_codec: use crypto_shash_tfm_digest()
>

For the series,

Acked-by: Ard Biesheuvel <ardb@kernel.org>


>  arch/arm64/crypto/aes-glue.c               |  4 +--
>  crypto/essiv.c                             |  4 +--
>  crypto/shash.c                             | 16 +++++++++
>  drivers/crypto/axis/artpec6_crypto.c       | 10 ++----
>  drivers/crypto/ccp/ccp-crypto-sha.c        |  9 ++---
>  drivers/crypto/ccree/cc_cipher.c           |  9 ++---
>  drivers/crypto/hisilicon/sec2/sec_crypto.c |  5 ++-
>  drivers/crypto/mediatek/mtk-sha.c          |  7 ++--
>  drivers/crypto/n2_core.c                   |  7 ++--
>  drivers/crypto/omap-sham.c                 | 20 +++--------
>  drivers/crypto/s5p-sss.c                   | 39 ++++------------------
>  drivers/nfc/s3fwrn5/firmware.c             | 10 +-----
>  fs/crypto/fname.c                          |  7 +---
>  fs/crypto/hkdf.c                           |  6 +---
>  fs/ecryptfs/crypto.c                       | 17 +---------
>  fs/nfsd/nfs4recover.c                      | 26 ++++-----------
>  fs/ubifs/auth.c                            | 20 ++---------
>  fs/ubifs/master.c                          |  9 ++---
>  fs/ubifs/replay.c                          | 14 ++------
>  include/crypto/hash.h                      | 19 +++++++++++
>  net/bluetooth/smp.c                        |  6 +---
>  net/sctp/auth.c                            | 10 ++----
>  net/sctp/sm_make_chunk.c                   | 23 +++++--------
>  security/keys/encrypted-keys/encrypted.c   | 18 ++--------
>  sound/soc/codecs/cros_ec_codec.c           |  9 +----
>  25 files changed, 95 insertions(+), 229 deletions(-)
>
> --
> 2.26.2
>

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 15/20] nfsd: use crypto_shash_tfm_digest()
  2020-05-02  5:31 ` [PATCH 15/20] nfsd: " Eric Biggers
@ 2020-05-04 19:09   ` J. Bruce Fields
  0 siblings, 0 replies; 28+ messages in thread
From: J. Bruce Fields @ 2020-05-04 19:09 UTC (permalink / raw)
  To: Eric Biggers; +Cc: linux-crypto, linux-nfs

On Fri, May 01, 2020 at 10:31:17PM -0700, Eric Biggers wrote:
> From: Eric Biggers <ebiggers@google.com>
> 
> Instead of manually allocating a 'struct shash_desc' on the stack and
> calling crypto_shash_digest(), switch to using the new helper function
> crypto_shash_tfm_digest() which does this for us.
> 
> Cc: linux-nfs@vger.kernel.org
> Signed-off-by: Eric Biggers <ebiggers@google.com>

Acked-by: J. Bruce Fields <bfields@redhat.com>

if you need it.

--b.

> ---
>  fs/nfsd/nfs4recover.c | 26 ++++++--------------------
>  1 file changed, 6 insertions(+), 20 deletions(-)
> 
> diff --git a/fs/nfsd/nfs4recover.c b/fs/nfsd/nfs4recover.c
> index a8fb18609146a2..9e40dfecf1b1a6 100644
> --- a/fs/nfsd/nfs4recover.c
> +++ b/fs/nfsd/nfs4recover.c
> @@ -127,16 +127,8 @@ nfs4_make_rec_clidname(char *dname, const struct xdr_netobj *clname)
>   		goto out;
>  	}
>  
> -	{
> -		SHASH_DESC_ON_STACK(desc, tfm);
> -
> -		desc->tfm = tfm;
> -
> -		status = crypto_shash_digest(desc, clname->data, clname->len,
> -					     cksum.data);
> -		shash_desc_zero(desc);
> -	}
> -
> +	status = crypto_shash_tfm_digest(tfm, clname->data, clname->len,
> +					 cksum.data);
>  	if (status)
>  		goto out;
>  
> @@ -1148,7 +1140,6 @@ nfsd4_cld_create_v2(struct nfs4_client *clp)
>  	struct crypto_shash *tfm = cn->cn_tfm;
>  	struct xdr_netobj cksum;
>  	char *principal = NULL;
> -	SHASH_DESC_ON_STACK(desc, tfm);
>  
>  	/* Don't upcall if it's already stored */
>  	if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
> @@ -1170,16 +1161,14 @@ nfsd4_cld_create_v2(struct nfs4_client *clp)
>  	else if (clp->cl_cred.cr_principal)
>  		principal = clp->cl_cred.cr_principal;
>  	if (principal) {
> -		desc->tfm = tfm;
>  		cksum.len = crypto_shash_digestsize(tfm);
>  		cksum.data = kmalloc(cksum.len, GFP_KERNEL);
>  		if (cksum.data == NULL) {
>  			ret = -ENOMEM;
>  			goto out;
>  		}
> -		ret = crypto_shash_digest(desc, principal, strlen(principal),
> -					  cksum.data);
> -		shash_desc_zero(desc);
> +		ret = crypto_shash_tfm_digest(tfm, principal, strlen(principal),
> +					      cksum.data);
>  		if (ret) {
>  			kfree(cksum.data);
>  			goto out;
> @@ -1343,7 +1332,6 @@ nfsd4_cld_check_v2(struct nfs4_client *clp)
>  	struct crypto_shash *tfm = cn->cn_tfm;
>  	struct xdr_netobj cksum;
>  	char *principal = NULL;
> -	SHASH_DESC_ON_STACK(desc, tfm);
>  
>  	/* did we already find that this client is stable? */
>  	if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
> @@ -1381,14 +1369,12 @@ nfsd4_cld_check_v2(struct nfs4_client *clp)
>  			principal = clp->cl_cred.cr_principal;
>  		if (principal == NULL)
>  			return -ENOENT;
> -		desc->tfm = tfm;
>  		cksum.len = crypto_shash_digestsize(tfm);
>  		cksum.data = kmalloc(cksum.len, GFP_KERNEL);
>  		if (cksum.data == NULL)
>  			return -ENOENT;
> -		status = crypto_shash_digest(desc, principal, strlen(principal),
> -					     cksum.data);
> -		shash_desc_zero(desc);
> +		status = crypto_shash_tfm_digest(tfm, principal,
> +						 strlen(principal), cksum.data);
>  		if (status) {
>  			kfree(cksum.data);
>  			return -ENOENT;
> -- 
> 2.26.2

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 11/20] crypto: s5p-sss - use crypto_shash_tfm_digest()
  2020-05-02  5:31 ` [PATCH 11/20] crypto: s5p-sss " Eric Biggers
@ 2020-05-05 14:19   ` Krzysztof Kozlowski
  0 siblings, 0 replies; 28+ messages in thread
From: Krzysztof Kozlowski @ 2020-05-05 14:19 UTC (permalink / raw)
  To: Eric Biggers; +Cc: linux-crypto, Vladimir Zapolskiy, Kamil Konieczny

On Fri, May 01, 2020 at 10:31:13PM -0700, Eric Biggers wrote:
> From: Eric Biggers <ebiggers@google.com>
> 
> Instead of manually allocating a 'struct shash_desc' on the stack and
> calling crypto_shash_digest(), switch to using the new helper function
> crypto_shash_tfm_digest() which does this for us.
> 
> Cc: Krzysztof Kozlowski <krzk@kernel.org>
> Cc: Vladimir Zapolskiy <vz@mleia.com>
> Cc: Kamil Konieczny <k.konieczny@samsung.com>
> Signed-off-by: Eric Biggers <ebiggers@google.com>
> ---
>  drivers/crypto/s5p-sss.c | 39 ++++++---------------------------------
>  1 file changed, 6 insertions(+), 33 deletions(-)

Acked-by: Krzysztof Kozlowski <krzk@kernel.org>

Best regards,
Krzysztof


^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 05/20] crypto: ccp - use crypto_shash_tfm_digest()
  2020-05-02  5:31 ` [PATCH 05/20] crypto: ccp " Eric Biggers
@ 2020-05-07 21:23   ` Tom Lendacky
  0 siblings, 0 replies; 28+ messages in thread
From: Tom Lendacky @ 2020-05-07 21:23 UTC (permalink / raw)
  To: Eric Biggers, linux-crypto

On 5/2/20 12:31 AM, Eric Biggers wrote:
> From: Eric Biggers <ebiggers@google.com>
> 
> Instead of manually allocating a 'struct shash_desc' on the stack and
> calling crypto_shash_digest(), switch to using the new helper function
> crypto_shash_tfm_digest() which does this for us.
> 
> Cc: Tom Lendacky <thomas.lendacky@amd.com>
> Signed-off-by: Eric Biggers <ebiggers@google.com>

Acked-by: Tom Lendacky <thomas.lendacky@amd.com>

> ---
>   drivers/crypto/ccp/ccp-crypto-sha.c | 9 ++-------
>   1 file changed, 2 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/crypto/ccp/ccp-crypto-sha.c b/drivers/crypto/ccp/ccp-crypto-sha.c
> index 474e6f1a6a84ec..b0cc2bd73af804 100644
> --- a/drivers/crypto/ccp/ccp-crypto-sha.c
> +++ b/drivers/crypto/ccp/ccp-crypto-sha.c
> @@ -272,9 +272,6 @@ static int ccp_sha_setkey(struct crypto_ahash *tfm, const u8 *key,
>   {
>   	struct ccp_ctx *ctx = crypto_tfm_ctx(crypto_ahash_tfm(tfm));
>   	struct crypto_shash *shash = ctx->u.sha.hmac_tfm;
> -
> -	SHASH_DESC_ON_STACK(sdesc, shash);
> -
>   	unsigned int block_size = crypto_shash_blocksize(shash);
>   	unsigned int digest_size = crypto_shash_digestsize(shash);
>   	int i, ret;
> @@ -289,10 +286,8 @@ static int ccp_sha_setkey(struct crypto_ahash *tfm, const u8 *key,
>   
>   	if (key_len > block_size) {
>   		/* Must hash the input key */
> -		sdesc->tfm = shash;
> -
> -		ret = crypto_shash_digest(sdesc, key, key_len,
> -					  ctx->u.sha.key);
> +		ret = crypto_shash_tfm_digest(shash, key, key_len,
> +					      ctx->u.sha.key);
>   		if (ret)
>   			return -EINVAL;
>   
> 

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 00/20] crypto: introduce crypto_shash_tfm_digest()
  2020-05-02  5:31 [PATCH 00/20] crypto: introduce crypto_shash_tfm_digest() Eric Biggers
                   ` (21 preceding siblings ...)
  2020-05-03 16:13 ` Ard Biesheuvel
@ 2020-05-08  6:07 ` Herbert Xu
  22 siblings, 0 replies; 28+ messages in thread
From: Herbert Xu @ 2020-05-08  6:07 UTC (permalink / raw)
  To: Eric Biggers
  Cc: linux-crypto, cychiang, ecryptfs, enric.balletbo, gilad, groeck,
	jesper.nilsson, k.konieczny, keyrings, krzk, k.opasiak,
	lars.persson, linux-bluetooth, linux-mtd, linux-nfs, linux-sctp,
	r.baldyga, thomas.lendacky, vz, xuzaibo

Eric Biggers <ebiggers@kernel.org> wrote:
> This series introduces a helper function crypto_shash_tfm_digest() which
> replaces the following common pattern:
> 
>        {
>                SHASH_DESC_ON_STACK(desc, tfm);
>                int err;
> 
>                desc->tfm = tfm;
> 
>                err = crypto_shash_digest(desc, data, len, out);
> 
>                shash_desc_zero(desc);
>        }
> 
> with:
> 
>        err = crypto_shash_tfm_digest(tfm, data, len, out);
> 
> Patch 1 introduces this helper function, and patches 2-20 convert all
> relevant users to use it.
> 
> IMO, it would be easiest to take all these patches through the crypto
> tree.  But taking just the "crypto:" ones and then me trying to get the
> rest merged later via subsystem trees is also an option.
> 
> Eric Biggers (20):
>  crypto: hash - introduce crypto_shash_tfm_digest()
>  crypto: arm64/aes-glue - use crypto_shash_tfm_digest()
>  crypto: essiv - use crypto_shash_tfm_digest()
>  crypto: artpec6 - use crypto_shash_tfm_digest()
>  crypto: ccp - use crypto_shash_tfm_digest()
>  crypto: ccree - use crypto_shash_tfm_digest()
>  crypto: hisilicon/sec2 - use crypto_shash_tfm_digest()
>  crypto: mediatek - use crypto_shash_tfm_digest()
>  crypto: n2 - use crypto_shash_tfm_digest()
>  crypto: omap-sham - use crypto_shash_tfm_digest()
>  crypto: s5p-sss - use crypto_shash_tfm_digest()
>  nfc: s3fwrn5: use crypto_shash_tfm_digest()
>  fscrypt: use crypto_shash_tfm_digest()
>  ecryptfs: use crypto_shash_tfm_digest()
>  nfsd: use crypto_shash_tfm_digest()
>  ubifs: use crypto_shash_tfm_digest()
>  Bluetooth: use crypto_shash_tfm_digest()
>  sctp: use crypto_shash_tfm_digest()
>  KEYS: encrypted: use crypto_shash_tfm_digest()
>  ASoC: cros_ec_codec: use crypto_shash_tfm_digest()
> 
> arch/arm64/crypto/aes-glue.c               |  4 +--
> crypto/essiv.c                             |  4 +--
> crypto/shash.c                             | 16 +++++++++
> drivers/crypto/axis/artpec6_crypto.c       | 10 ++----
> drivers/crypto/ccp/ccp-crypto-sha.c        |  9 ++---
> drivers/crypto/ccree/cc_cipher.c           |  9 ++---
> drivers/crypto/hisilicon/sec2/sec_crypto.c |  5 ++-
> drivers/crypto/mediatek/mtk-sha.c          |  7 ++--
> drivers/crypto/n2_core.c                   |  7 ++--
> drivers/crypto/omap-sham.c                 | 20 +++--------
> drivers/crypto/s5p-sss.c                   | 39 ++++------------------
> drivers/nfc/s3fwrn5/firmware.c             | 10 +-----
> fs/crypto/fname.c                          |  7 +---
> fs/crypto/hkdf.c                           |  6 +---
> fs/ecryptfs/crypto.c                       | 17 +---------
> fs/nfsd/nfs4recover.c                      | 26 ++++-----------
> fs/ubifs/auth.c                            | 20 ++---------
> fs/ubifs/master.c                          |  9 ++---
> fs/ubifs/replay.c                          | 14 ++------
> include/crypto/hash.h                      | 19 +++++++++++
> net/bluetooth/smp.c                        |  6 +---
> net/sctp/auth.c                            | 10 ++----
> net/sctp/sm_make_chunk.c                   | 23 +++++--------
> security/keys/encrypted-keys/encrypted.c   | 18 ++--------
> sound/soc/codecs/cros_ec_codec.c           |  9 +----
> 25 files changed, 95 insertions(+), 229 deletions(-)

All applied.  Thanks.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2020-05-08  6:07 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-02  5:31 [PATCH 00/20] crypto: introduce crypto_shash_tfm_digest() Eric Biggers
2020-05-02  5:31 ` [PATCH 01/20] crypto: hash - " Eric Biggers
2020-05-02  5:31 ` [PATCH 02/20] crypto: arm64/aes-glue - use crypto_shash_tfm_digest() Eric Biggers
2020-05-02  5:31 ` [PATCH 03/20] crypto: essiv " Eric Biggers
2020-05-02  5:31 ` [PATCH 04/20] crypto: artpec6 " Eric Biggers
2020-05-02  5:31 ` [PATCH 05/20] crypto: ccp " Eric Biggers
2020-05-07 21:23   ` Tom Lendacky
2020-05-02  5:31 ` [PATCH 06/20] crypto: ccree " Eric Biggers
2020-05-03 14:01   ` Gilad Ben-Yossef
2020-05-02  5:31 ` [PATCH 07/20] crypto: hisilicon/sec2 " Eric Biggers
2020-05-02  5:31 ` [PATCH 08/20] crypto: mediatek " Eric Biggers
2020-05-02  5:31 ` [PATCH 09/20] crypto: n2 " Eric Biggers
2020-05-02  5:31 ` [PATCH 10/20] crypto: omap-sham " Eric Biggers
2020-05-02  5:31 ` [PATCH 11/20] crypto: s5p-sss " Eric Biggers
2020-05-05 14:19   ` Krzysztof Kozlowski
2020-05-02  5:31 ` [PATCH 12/20] nfc: s3fwrn5: " Eric Biggers
2020-05-02  5:31 ` [PATCH 13/20] fscrypt: " Eric Biggers
2020-05-02  5:31 ` [PATCH 14/20] ecryptfs: " Eric Biggers
2020-05-02  5:31 ` [PATCH 15/20] nfsd: " Eric Biggers
2020-05-04 19:09   ` J. Bruce Fields
2020-05-02  5:31 ` [PATCH 16/20] ubifs: " Eric Biggers
2020-05-02  5:31 ` [PATCH 17/20] Bluetooth: " Eric Biggers
2020-05-02  5:31 ` [PATCH 18/20] sctp: " Eric Biggers
2020-05-02  5:31 ` [PATCH 19/20] KEYS: encrypted: " Eric Biggers
2020-05-02  5:31 ` [PATCH 20/20] ASoC: cros_ec_codec: " Eric Biggers
2020-05-02  6:44 ` [PATCH 00/20] crypto: introduce crypto_shash_tfm_digest() Marcel Holtmann
2020-05-03 16:13 ` Ard Biesheuvel
2020-05-08  6:07 ` Herbert Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).