linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] qce crypto fixes for tcrypto failures
@ 2020-06-22  6:15 Sivaprakash Murugesan
  2020-06-22  6:15 ` [PATCH 1/3] crypto: qce: support zero length test vectors Sivaprakash Murugesan
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Sivaprakash Murugesan @ 2020-06-22  6:15 UTC (permalink / raw)
  To: herbert, davem, stanimir.varbanov, ardb, sivaprak, cotequeiroz,
	ebiggers, horia.geanta, linux-crypto, linux-kernel

while running tcrypto test cases on qce crypto engine few failures are
noticed, this is mainly because of the updates on tcrypto driver and
not testing qce reqgularly with mainline tcrypto driver.

This series tries to address few of the errors while running tcrypto on
qce.

Sivaprakash Murugesan (3):
  crypto: qce: support zero length test vectors
  crypto: qce: re-initialize context on import
  crypto: qce: sha: Do not modify scatterlist passed along with request

 drivers/crypto/Kconfig      |  2 ++
 drivers/crypto/qce/common.h |  2 ++
 drivers/crypto/qce/sha.c    | 36 +++++++++++++++++++++++++++++-------
 3 files changed, 33 insertions(+), 7 deletions(-)

-- 
2.7.4


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

* [PATCH 1/3] crypto: qce: support zero length test vectors
  2020-06-22  6:15 [PATCH 0/3] qce crypto fixes for tcrypto failures Sivaprakash Murugesan
@ 2020-06-22  6:15 ` Sivaprakash Murugesan
  2020-06-22  6:15 ` [PATCH 2/3] crypto: qce: re-initialize context on import Sivaprakash Murugesan
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Sivaprakash Murugesan @ 2020-06-22  6:15 UTC (permalink / raw)
  To: herbert, davem, stanimir.varbanov, ardb, sivaprak, cotequeiroz,
	ebiggers, horia.geanta, linux-crypto, linux-kernel

crypto test module passes zero length vectors as test input to sha-1 and
sha-256. To provide correct output for these vectors, hash zero support
has been added as in other crypto drivers.

Signed-off-by: Sivaprakash Murugesan <sivaprak@codeaurora.org>
---
 drivers/crypto/Kconfig      |  2 ++
 drivers/crypto/qce/common.h |  2 ++
 drivers/crypto/qce/sha.c    | 18 +++++++++++++++++-
 3 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/drivers/crypto/Kconfig b/drivers/crypto/Kconfig
index 802b9ada4e9e..7bc58bf99703 100644
--- a/drivers/crypto/Kconfig
+++ b/drivers/crypto/Kconfig
@@ -624,6 +624,8 @@ config CRYPTO_DEV_QCE_SKCIPHER
 config CRYPTO_DEV_QCE_SHA
 	bool
 	depends on CRYPTO_DEV_QCE
+	select CRYPTO_SHA1
+	select CRYPTO_SHA256
 
 choice
 	prompt "Algorithms enabled for QCE acceleration"
diff --git a/drivers/crypto/qce/common.h b/drivers/crypto/qce/common.h
index 9f989cba0f1b..85ba16418a04 100644
--- a/drivers/crypto/qce/common.h
+++ b/drivers/crypto/qce/common.h
@@ -87,6 +87,8 @@ struct qce_alg_template {
 		struct ahash_alg ahash;
 	} alg;
 	struct qce_device *qce;
+	const u8 *hash_zero;
+	const u32 digest_size;
 };
 
 void qce_cpu_to_be32p_array(__be32 *dst, const u8 *src, unsigned int len);
diff --git a/drivers/crypto/qce/sha.c b/drivers/crypto/qce/sha.c
index 1ab62e7d5f3c..ed82520203f9 100644
--- a/drivers/crypto/qce/sha.c
+++ b/drivers/crypto/qce/sha.c
@@ -305,8 +305,12 @@ static int qce_ahash_final(struct ahash_request *req)
 	struct qce_alg_template *tmpl = to_ahash_tmpl(req->base.tfm);
 	struct qce_device *qce = tmpl->qce;
 
-	if (!rctx->buflen)
+	if (!rctx->buflen) {
+		if (tmpl->hash_zero)
+			memcpy(req->result, tmpl->hash_zero,
+					tmpl->alg.ahash.halg.digestsize);
 		return 0;
+	}
 
 	rctx->last_blk = true;
 
@@ -338,6 +342,13 @@ static int qce_ahash_digest(struct ahash_request *req)
 	rctx->first_blk = true;
 	rctx->last_blk = true;
 
+	if (!rctx->nbytes_orig) {
+		if (tmpl->hash_zero)
+			memcpy(req->result, tmpl->hash_zero,
+					tmpl->alg.ahash.halg.digestsize);
+		return 0;
+	}
+
 	return qce->async_req_enqueue(tmpl->qce, &req->base);
 }
 
@@ -490,6 +501,11 @@ static int qce_ahash_register_one(const struct qce_ahash_def *def,
 	alg->halg.digestsize = def->digestsize;
 	alg->halg.statesize = def->statesize;
 
+	if (IS_SHA1(def->flags))
+		tmpl->hash_zero = sha1_zero_message_hash;
+	else if (IS_SHA256(def->flags))
+		tmpl->hash_zero = sha256_zero_message_hash;
+
 	base = &alg->halg.base;
 	base->cra_blocksize = def->blocksize;
 	base->cra_priority = 300;
-- 
2.7.4


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

* [PATCH 2/3] crypto: qce: re-initialize context on import
  2020-06-22  6:15 [PATCH 0/3] qce crypto fixes for tcrypto failures Sivaprakash Murugesan
  2020-06-22  6:15 ` [PATCH 1/3] crypto: qce: support zero length test vectors Sivaprakash Murugesan
@ 2020-06-22  6:15 ` Sivaprakash Murugesan
  2020-06-22  6:15 ` [PATCH 3/3] crypto: qce: sha: Do not modify scatterlist passed along with request Sivaprakash Murugesan
  2020-07-03  4:48 ` [PATCH 0/3] qce crypto fixes for tcrypto failures Herbert Xu
  3 siblings, 0 replies; 5+ messages in thread
From: Sivaprakash Murugesan @ 2020-06-22  6:15 UTC (permalink / raw)
  To: herbert, davem, stanimir.varbanov, ardb, sivaprak, cotequeiroz,
	ebiggers, horia.geanta, linux-crypto, linux-kernel

crypto testmgr deliberately corrupts the request context while passing
vectors to the import. This is to make sure that drivers do not rely on
request but they take all the necessary input from io vec passed to it.

qce casts the request context from request parameter, since it is corrupted
the sub squent hash request fails and qce hangs.

To avoid this re-initialize request context on import. The qce import
API alreasy takes care of taking the input vectors from passed io vec.

Signed-off-by: Sivaprakash Murugesan <sivaprak@codeaurora.org>
---
 drivers/crypto/qce/sha.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/crypto/qce/sha.c b/drivers/crypto/qce/sha.c
index ed82520203f9..9e54a667d72f 100644
--- a/drivers/crypto/qce/sha.c
+++ b/drivers/crypto/qce/sha.c
@@ -203,10 +203,18 @@ static int qce_import_common(struct ahash_request *req, u64 in_count,
 
 static int qce_ahash_import(struct ahash_request *req, const void *in)
 {
-	struct qce_sha_reqctx *rctx = ahash_request_ctx(req);
-	unsigned long flags = rctx->flags;
-	bool hmac = IS_SHA_HMAC(flags);
-	int ret = -EINVAL;
+	struct qce_sha_reqctx *rctx;
+	unsigned long flags;
+	bool hmac;
+	int ret;
+
+	ret = qce_ahash_init(req);
+	if (ret)
+		return ret;
+
+	rctx = ahash_request_ctx(req);
+	flags = rctx->flags;
+	hmac = IS_SHA_HMAC(flags);
 
 	if (IS_SHA1(flags) || IS_SHA1_HMAC(flags)) {
 		const struct sha1_state *state = in;
-- 
2.7.4


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

* [PATCH 3/3] crypto: qce: sha: Do not modify scatterlist passed along with request
  2020-06-22  6:15 [PATCH 0/3] qce crypto fixes for tcrypto failures Sivaprakash Murugesan
  2020-06-22  6:15 ` [PATCH 1/3] crypto: qce: support zero length test vectors Sivaprakash Murugesan
  2020-06-22  6:15 ` [PATCH 2/3] crypto: qce: re-initialize context on import Sivaprakash Murugesan
@ 2020-06-22  6:15 ` Sivaprakash Murugesan
  2020-07-03  4:48 ` [PATCH 0/3] qce crypto fixes for tcrypto failures Herbert Xu
  3 siblings, 0 replies; 5+ messages in thread
From: Sivaprakash Murugesan @ 2020-06-22  6:15 UTC (permalink / raw)
  To: herbert, davem, stanimir.varbanov, ardb, sivaprak, cotequeiroz,
	ebiggers, horia.geanta, linux-crypto, linux-kernel

Crypto test driver's test_ahash_speed calls crypto_ahash_update and
crypto_ahash_final APIs repeatedly for all the available test vector
buffer lengths.

if we mark the end for scatterlist based on the current vector size then
the subsequent vectors might fail if the later buffer lengths are higher.

To avoid this, in qce do not mark the end of scatterlist in update API,
the qce_ahash_async_req_handle API already takes care of this copying
right amount of buffer from the request scatter list.

Signed-off-by: Sivaprakash Murugesan <sivaprak@codeaurora.org>
---
 drivers/crypto/qce/sha.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/crypto/qce/sha.c b/drivers/crypto/qce/sha.c
index 9e54a667d72f..c230843e2ffb 100644
--- a/drivers/crypto/qce/sha.c
+++ b/drivers/crypto/qce/sha.c
@@ -292,8 +292,6 @@ static int qce_ahash_update(struct ahash_request *req)
 	if (!sg_last)
 		return -EINVAL;
 
-	sg_mark_end(sg_last);
-
 	if (rctx->buflen) {
 		sg_init_table(rctx->sg, 2);
 		sg_set_buf(rctx->sg, rctx->tmpbuf, rctx->buflen);
-- 
2.7.4


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

* Re: [PATCH 0/3] qce crypto fixes for tcrypto failures
  2020-06-22  6:15 [PATCH 0/3] qce crypto fixes for tcrypto failures Sivaprakash Murugesan
                   ` (2 preceding siblings ...)
  2020-06-22  6:15 ` [PATCH 3/3] crypto: qce: sha: Do not modify scatterlist passed along with request Sivaprakash Murugesan
@ 2020-07-03  4:48 ` Herbert Xu
  3 siblings, 0 replies; 5+ messages in thread
From: Herbert Xu @ 2020-07-03  4:48 UTC (permalink / raw)
  To: Sivaprakash Murugesan
  Cc: davem, stanimir.varbanov, ardb, cotequeiroz, ebiggers,
	horia.geanta, linux-crypto, linux-kernel

On Mon, Jun 22, 2020 at 11:45:03AM +0530, Sivaprakash Murugesan wrote:
> while running tcrypto test cases on qce crypto engine few failures are
> noticed, this is mainly because of the updates on tcrypto driver and
> not testing qce reqgularly with mainline tcrypto driver.
> 
> This series tries to address few of the errors while running tcrypto on
> qce.
> 
> Sivaprakash Murugesan (3):
>   crypto: qce: support zero length test vectors
>   crypto: qce: re-initialize context on import
>   crypto: qce: sha: Do not modify scatterlist passed along with request
> 
>  drivers/crypto/Kconfig      |  2 ++
>  drivers/crypto/qce/common.h |  2 ++
>  drivers/crypto/qce/sha.c    | 36 +++++++++++++++++++++++++++++-------
>  3 files changed, 33 insertions(+), 7 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] 5+ messages in thread

end of thread, other threads:[~2020-07-03  4:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-22  6:15 [PATCH 0/3] qce crypto fixes for tcrypto failures Sivaprakash Murugesan
2020-06-22  6:15 ` [PATCH 1/3] crypto: qce: support zero length test vectors Sivaprakash Murugesan
2020-06-22  6:15 ` [PATCH 2/3] crypto: qce: re-initialize context on import Sivaprakash Murugesan
2020-06-22  6:15 ` [PATCH 3/3] crypto: qce: sha: Do not modify scatterlist passed along with request Sivaprakash Murugesan
2020-07-03  4:48 ` [PATCH 0/3] qce crypto fixes for tcrypto failures 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).