linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] crypto: caam: fix asynchronous hash
@ 2024-01-18  9:25 Gaurav Jain
  2024-01-24 22:04 ` Eric Biggers
  2024-01-26  9:03 ` Herbert Xu
  0 siblings, 2 replies; 3+ messages in thread
From: Gaurav Jain @ 2024-01-18  9:25 UTC (permalink / raw)
  To: Herbert Xu, David S . Miller, Eric Biggers, Horia Geanta,
	Pankaj Gupta, Varun Sethi, Meenakshi Aggarwal, Aisheng Dong
  Cc: Silvano Di Ninno, linux-crypto, linux-kernel, linux-imx, Gaurav Jain

ahash_alg->setkey is updated to ahash_nosetkey in ahash.c
so checking setkey() function to determine hmac algorithm is not valid.

to fix this added is_hmac variable in structure caam_hash_alg to determine
whether the algorithm is hmac or not.

Fixes: 2f1f34c1bf7b ("crypto: ahash - optimize performance when wrapping shash")
Signed-off-by: Gaurav Jain <gaurav.jain@nxp.com>
---
changes in v2:
	- remove if condition based on crypto_hash_alg_has_setkey() funcion.
	- added is_hmac variable in caam_hash_alg and updated the if
	  condition for checking hmac algorithm.

 drivers/crypto/caam/caamalg_qi2.c | 7 +++++--
 drivers/crypto/caam/caamhash.c    | 7 +++++--
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/crypto/caam/caamalg_qi2.c b/drivers/crypto/caam/caamalg_qi2.c
index a148ff1f0872..a4f6884416a0 100644
--- a/drivers/crypto/caam/caamalg_qi2.c
+++ b/drivers/crypto/caam/caamalg_qi2.c
@@ -4545,6 +4545,7 @@ struct caam_hash_alg {
 	struct list_head entry;
 	struct device *dev;
 	int alg_type;
+	bool is_hmac;
 	struct ahash_alg ahash_alg;
 };
 
@@ -4571,7 +4572,7 @@ static int caam_hash_cra_init(struct crypto_tfm *tfm)
 
 	ctx->dev = caam_hash->dev;
 
-	if (alg->setkey) {
+	if (caam_hash->is_hmac) {
 		ctx->adata.key_dma = dma_map_single_attrs(ctx->dev, ctx->key,
 							  ARRAY_SIZE(ctx->key),
 							  DMA_TO_DEVICE,
@@ -4611,7 +4612,7 @@ static int caam_hash_cra_init(struct crypto_tfm *tfm)
 	 * For keyed hash algorithms shared descriptors
 	 * will be created later in setkey() callback
 	 */
-	return alg->setkey ? 0 : ahash_set_sh_desc(ahash);
+	return caam_hash->is_hmac ? 0 : ahash_set_sh_desc(ahash);
 }
 
 static void caam_hash_cra_exit(struct crypto_tfm *tfm)
@@ -4646,12 +4647,14 @@ static struct caam_hash_alg *caam_hash_alloc(struct device *dev,
 			 template->hmac_name);
 		snprintf(alg->cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s",
 			 template->hmac_driver_name);
+		t_alg->is_hmac = true;
 	} else {
 		snprintf(alg->cra_name, CRYPTO_MAX_ALG_NAME, "%s",
 			 template->name);
 		snprintf(alg->cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s",
 			 template->driver_name);
 		t_alg->ahash_alg.setkey = NULL;
+		t_alg->is_hmac = false;
 	}
 	alg->cra_module = THIS_MODULE;
 	alg->cra_init = caam_hash_cra_init;
diff --git a/drivers/crypto/caam/caamhash.c b/drivers/crypto/caam/caamhash.c
index 290c8500c247..fdd724228c2f 100644
--- a/drivers/crypto/caam/caamhash.c
+++ b/drivers/crypto/caam/caamhash.c
@@ -1753,6 +1753,7 @@ static struct caam_hash_template driver_hash[] = {
 struct caam_hash_alg {
 	struct list_head entry;
 	int alg_type;
+	bool is_hmac;
 	struct ahash_engine_alg ahash_alg;
 };
 
@@ -1804,7 +1805,7 @@ static int caam_hash_cra_init(struct crypto_tfm *tfm)
 	} else {
 		if (priv->era >= 6) {
 			ctx->dir = DMA_BIDIRECTIONAL;
-			ctx->key_dir = alg->setkey ? DMA_TO_DEVICE : DMA_NONE;
+			ctx->key_dir = caam_hash->is_hmac ? DMA_TO_DEVICE : DMA_NONE;
 		} else {
 			ctx->dir = DMA_TO_DEVICE;
 			ctx->key_dir = DMA_NONE;
@@ -1862,7 +1863,7 @@ static int caam_hash_cra_init(struct crypto_tfm *tfm)
 	 * For keyed hash algorithms shared descriptors
 	 * will be created later in setkey() callback
 	 */
-	return alg->setkey ? 0 : ahash_set_sh_desc(ahash);
+	return caam_hash->is_hmac ? 0 : ahash_set_sh_desc(ahash);
 }
 
 static void caam_hash_cra_exit(struct crypto_tfm *tfm)
@@ -1915,12 +1916,14 @@ caam_hash_alloc(struct caam_hash_template *template,
 			 template->hmac_name);
 		snprintf(alg->cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s",
 			 template->hmac_driver_name);
+		t_alg->is_hmac = true;
 	} else {
 		snprintf(alg->cra_name, CRYPTO_MAX_ALG_NAME, "%s",
 			 template->name);
 		snprintf(alg->cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s",
 			 template->driver_name);
 		halg->setkey = NULL;
+		t_alg->is_hmac = false;
 	}
 	alg->cra_module = THIS_MODULE;
 	alg->cra_init = caam_hash_cra_init;
-- 
2.25.1


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

* Re: [PATCH v2] crypto: caam: fix asynchronous hash
  2024-01-18  9:25 [PATCH v2] crypto: caam: fix asynchronous hash Gaurav Jain
@ 2024-01-24 22:04 ` Eric Biggers
  2024-01-26  9:03 ` Herbert Xu
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Biggers @ 2024-01-24 22:04 UTC (permalink / raw)
  To: Gaurav Jain
  Cc: Herbert Xu, David S . Miller, Horia Geanta, Pankaj Gupta,
	Varun Sethi, Meenakshi Aggarwal, Aisheng Dong, Silvano Di Ninno,
	linux-crypto, linux-kernel, linux-imx

On Thu, Jan 18, 2024 at 02:55:57PM +0530, Gaurav Jain wrote:
> ahash_alg->setkey is updated to ahash_nosetkey in ahash.c
> so checking setkey() function to determine hmac algorithm is not valid.
> 
> to fix this added is_hmac variable in structure caam_hash_alg to determine
> whether the algorithm is hmac or not.
> 
> Fixes: 2f1f34c1bf7b ("crypto: ahash - optimize performance when wrapping shash")
> Signed-off-by: Gaurav Jain <gaurav.jain@nxp.com>
> ---
> changes in v2:
> 	- remove if condition based on crypto_hash_alg_has_setkey() funcion.
> 	- added is_hmac variable in caam_hash_alg and updated the if
> 	  condition for checking hmac algorithm.
> 
>  drivers/crypto/caam/caamalg_qi2.c | 7 +++++--
>  drivers/crypto/caam/caamhash.c    | 7 +++++--
>  2 files changed, 10 insertions(+), 4 deletions(-)

Reviewed-by: Eric Biggers <ebiggers@google.com>

- Eric

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

* Re: [PATCH v2] crypto: caam: fix asynchronous hash
  2024-01-18  9:25 [PATCH v2] crypto: caam: fix asynchronous hash Gaurav Jain
  2024-01-24 22:04 ` Eric Biggers
@ 2024-01-26  9:03 ` Herbert Xu
  1 sibling, 0 replies; 3+ messages in thread
From: Herbert Xu @ 2024-01-26  9:03 UTC (permalink / raw)
  To: Gaurav Jain
  Cc: David S . Miller, Eric Biggers, Horia Geanta, Pankaj Gupta,
	Varun Sethi, Meenakshi Aggarwal, Aisheng Dong, Silvano Di Ninno,
	linux-crypto, linux-kernel, linux-imx

On Thu, Jan 18, 2024 at 02:55:57PM +0530, Gaurav Jain wrote:
> ahash_alg->setkey is updated to ahash_nosetkey in ahash.c
> so checking setkey() function to determine hmac algorithm is not valid.
> 
> to fix this added is_hmac variable in structure caam_hash_alg to determine
> whether the algorithm is hmac or not.
> 
> Fixes: 2f1f34c1bf7b ("crypto: ahash - optimize performance when wrapping shash")
> Signed-off-by: Gaurav Jain <gaurav.jain@nxp.com>
> ---
> changes in v2:
> 	- remove if condition based on crypto_hash_alg_has_setkey() funcion.
> 	- added is_hmac variable in caam_hash_alg and updated the if
> 	  condition for checking hmac algorithm.
> 
>  drivers/crypto/caam/caamalg_qi2.c | 7 +++++--
>  drivers/crypto/caam/caamhash.c    | 7 +++++--
>  2 files changed, 10 insertions(+), 4 deletions(-)

Patch 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] 3+ messages in thread

end of thread, other threads:[~2024-01-26  9:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-18  9:25 [PATCH v2] crypto: caam: fix asynchronous hash Gaurav Jain
2024-01-24 22:04 ` Eric Biggers
2024-01-26  9:03 ` 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).