All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] crypto: omap-sham driver fixes
@ 2011-04-20 10:34 Dmitry Kasatkin
  2011-04-20 10:34 ` [PATCH 1/4] crypto: omap-sham - fix concurrent sha1 calculations Dmitry Kasatkin
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Dmitry Kasatkin @ 2011-04-20 10:34 UTC (permalink / raw)
  To: herbert; +Cc: linux-crypto, linux-omap

Hi,

Here is few patches with couple of important fixes...

Regards,
Dmitry

Dmitry Kasatkin (3):
  crypto: omap-sham - remove debug print
  crypto: omap-sham - enable driver for EMU chips
  crypto: omap-sham - hmac calculation bug fix for sha1 base hash

Markku Kylanpaa (1):
  crypto: omap-sham - fix concurrent sha1 calculations

 drivers/crypto/omap-sham.c |   78 +++++++++++++++++++-------------------------
 1 files changed, 34 insertions(+), 44 deletions(-)

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

* [PATCH 1/4] crypto: omap-sham - fix concurrent sha1 calculations
  2011-04-20 10:34 [PATCH 0/4] crypto: omap-sham driver fixes Dmitry Kasatkin
@ 2011-04-20 10:34 ` Dmitry Kasatkin
  2011-04-20 10:34 ` [PATCH 2/4] crypto: omap-sham - remove debug print Dmitry Kasatkin
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Dmitry Kasatkin @ 2011-04-20 10:34 UTC (permalink / raw)
  To: herbert; +Cc: linux-crypto, linux-omap, Markku Kylanpaa

From: Markku Kylanpaa <ext-markku.kylanpaa@nokia.com>

SHA1 accelerator can also be busy. Add -EBUSY status return option and
return busy status from omap_sham_finup().

Signed-off-by: Markku Kylanpaa <ext-markku.kylanpaa@nokia.com>
---
 drivers/crypto/omap-sham.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/crypto/omap-sham.c b/drivers/crypto/omap-sham.c
index 465cde3..e36032b 100644
--- a/drivers/crypto/omap-sham.c
+++ b/drivers/crypto/omap-sham.c
@@ -835,7 +835,7 @@ static int omap_sham_finup(struct ahash_request *req)
 	ctx->flags |= FLAGS_FINUP;
 
 	err1 = omap_sham_update(req);
-	if (err1 == -EINPROGRESS)
+	if (err1 == -EINPROGRESS || err1 == -EBUSY)
 		return err1;
 	/*
 	 * final() has to be always called to cleanup resources
-- 
1.7.1

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

* [PATCH 2/4] crypto: omap-sham - remove debug print
  2011-04-20 10:34 [PATCH 0/4] crypto: omap-sham driver fixes Dmitry Kasatkin
  2011-04-20 10:34 ` [PATCH 1/4] crypto: omap-sham - fix concurrent sha1 calculations Dmitry Kasatkin
@ 2011-04-20 10:34 ` Dmitry Kasatkin
  2011-04-20 10:34 ` [PATCH 3/4] crypto: omap-sham - enable driver for EMU chips Dmitry Kasatkin
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Dmitry Kasatkin @ 2011-04-20 10:34 UTC (permalink / raw)
  To: herbert; +Cc: linux-crypto, linux-omap

Signed-off-by: Dmitry Kasatkin <dmitry.kasatkin@nokia.com>
---
 drivers/crypto/omap-sham.c |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)

diff --git a/drivers/crypto/omap-sham.c b/drivers/crypto/omap-sham.c
index e36032b..50aca41 100644
--- a/drivers/crypto/omap-sham.c
+++ b/drivers/crypto/omap-sham.c
@@ -890,8 +890,6 @@ static int omap_sham_cra_init_alg(struct crypto_tfm *tfm, const char *alg_base)
 	struct omap_sham_ctx *tctx = crypto_tfm_ctx(tfm);
 	const char *alg_name = crypto_tfm_alg_name(tfm);
 
-	pr_info("enter\n");
-
 	/* Allocate a fallback and abort if it failed. */
 	tctx->fallback = crypto_alloc_shash(alg_name, 0,
 					    CRYPTO_ALG_NEED_FALLBACK);
-- 
1.7.1


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

* [PATCH 3/4] crypto: omap-sham - enable driver for EMU chips
  2011-04-20 10:34 [PATCH 0/4] crypto: omap-sham driver fixes Dmitry Kasatkin
  2011-04-20 10:34 ` [PATCH 1/4] crypto: omap-sham - fix concurrent sha1 calculations Dmitry Kasatkin
  2011-04-20 10:34 ` [PATCH 2/4] crypto: omap-sham - remove debug print Dmitry Kasatkin
@ 2011-04-20 10:34 ` Dmitry Kasatkin
  2011-04-20 10:34 ` [PATCH 4/4] crypto: omap-sham - hmac calculation bug fix for sha1 base hash Dmitry Kasatkin
  2011-04-26  6:36 ` [PATCH 0/4] crypto: omap-sham driver fixes Herbert Xu
  4 siblings, 0 replies; 8+ messages in thread
From: Dmitry Kasatkin @ 2011-04-20 10:34 UTC (permalink / raw)
  To: herbert; +Cc: linux-crypto, linux-omap

EMU chips also have crypto HW as HS chips.

Signed-off-by: Dmitry Kasatkin <dmitry.kasatkin@nokia.com>
---
 drivers/crypto/omap-sham.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/drivers/crypto/omap-sham.c b/drivers/crypto/omap-sham.c
index 50aca41..f5c01dc 100644
--- a/drivers/crypto/omap-sham.c
+++ b/drivers/crypto/omap-sham.c
@@ -1295,7 +1295,8 @@ static int __init omap_sham_mod_init(void)
 	pr_info("loading %s driver\n", "omap-sham");
 
 	if (!cpu_class_is_omap2() ||
-		omap_type() != OMAP2_DEVICE_TYPE_SEC) {
+		(omap_type() != OMAP2_DEVICE_TYPE_SEC &&
+			omap_type() != OMAP2_DEVICE_TYPE_EMU)) {
 		pr_err("Unsupported cpu\n");
 		return -ENODEV;
 	}
-- 
1.7.1

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

* [PATCH 4/4] crypto: omap-sham - hmac calculation bug fix for sha1 base hash
  2011-04-20 10:34 [PATCH 0/4] crypto: omap-sham driver fixes Dmitry Kasatkin
                   ` (2 preceding siblings ...)
  2011-04-20 10:34 ` [PATCH 3/4] crypto: omap-sham - enable driver for EMU chips Dmitry Kasatkin
@ 2011-04-20 10:34 ` Dmitry Kasatkin
  2011-04-26  6:36 ` [PATCH 0/4] crypto: omap-sham driver fixes Herbert Xu
  4 siblings, 0 replies; 8+ messages in thread
From: Dmitry Kasatkin @ 2011-04-20 10:34 UTC (permalink / raw)
  To: herbert; +Cc: linux-crypto, linux-omap

This patch fixes 2 hmac inter-dependent bugs.

1. "omap-sham: hash-in-progress is stored in hw format" commit introduced
optimization where temporary hash had been stored in OMAP specific format
(big endian).
For SHA1 it is different to real hash format, which is little endian.
Final HMAC value was calculated using incorrect hash.
Because CONFIG_CRYPTO_MANAGER_TESTS was disabled this error remained
unnoticed. After enabling this option, bug has been found.

2. HMAC was calculated using temporrary hash value.
For a single-request updates, temporary hash was the final one and
HMAC result was correct. But in fact only the final hash had to be used.
All crypto tests for HMAC produces only single request and
could not catch the problem. This problem is fixed here.

Signed-off-by: Dmitry Kasatkin <dmitry.kasatkin@nokia.com>
---
 drivers/crypto/omap-sham.c |   71 +++++++++++++++++++------------------------
 1 files changed, 31 insertions(+), 40 deletions(-)

diff --git a/drivers/crypto/omap-sham.c b/drivers/crypto/omap-sham.c
index f5c01dc..ba8f1ea 100644
--- a/drivers/crypto/omap-sham.c
+++ b/drivers/crypto/omap-sham.c
@@ -78,7 +78,6 @@
 #define FLAGS_SHA1		0x0010
 #define FLAGS_DMA_ACTIVE	0x0020
 #define FLAGS_OUTPUT_READY	0x0040
-#define FLAGS_CLEAN		0x0080
 #define FLAGS_INIT		0x0100
 #define FLAGS_CPU		0x0200
 #define FLAGS_HMAC		0x0400
@@ -511,26 +510,6 @@ static int omap_sham_update_dma_stop(struct omap_sham_dev *dd)
 	return 0;
 }
 
-static void omap_sham_cleanup(struct ahash_request *req)
-{
-	struct omap_sham_reqctx *ctx = ahash_request_ctx(req);
-	struct omap_sham_dev *dd = ctx->dd;
-	unsigned long flags;
-
-	spin_lock_irqsave(&dd->lock, flags);
-	if (ctx->flags & FLAGS_CLEAN) {
-		spin_unlock_irqrestore(&dd->lock, flags);
-		return;
-	}
-	ctx->flags |= FLAGS_CLEAN;
-	spin_unlock_irqrestore(&dd->lock, flags);
-
-	if (ctx->digcnt)
-		omap_sham_copy_ready_hash(req);
-
-	dev_dbg(dd->dev, "digcnt: %d, bufcnt: %d\n", ctx->digcnt, ctx->bufcnt);
-}
-
 static int omap_sham_init(struct ahash_request *req)
 {
 	struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
@@ -618,9 +597,8 @@ static int omap_sham_final_req(struct omap_sham_dev *dd)
 	return err;
 }
 
-static int omap_sham_finish_req_hmac(struct ahash_request *req)
+static int omap_sham_finish_hmac(struct ahash_request *req)
 {
-	struct omap_sham_reqctx *ctx = ahash_request_ctx(req);
 	struct omap_sham_ctx *tctx = crypto_tfm_ctx(req->base.tfm);
 	struct omap_sham_hmac_ctx *bctx = tctx->base;
 	int bs = crypto_shash_blocksize(bctx->shash);
@@ -635,7 +613,24 @@ static int omap_sham_finish_req_hmac(struct ahash_request *req)
 
 	return crypto_shash_init(&desc.shash) ?:
 	       crypto_shash_update(&desc.shash, bctx->opad, bs) ?:
-	       crypto_shash_finup(&desc.shash, ctx->digest, ds, ctx->digest);
+	       crypto_shash_finup(&desc.shash, req->result, ds, req->result);
+}
+
+static int omap_sham_finish(struct ahash_request *req)
+{
+	struct omap_sham_reqctx *ctx = ahash_request_ctx(req);
+	struct omap_sham_dev *dd = ctx->dd;
+	int err = 0;
+
+	if (ctx->digcnt) {
+		omap_sham_copy_ready_hash(req);
+		if (ctx->flags & FLAGS_HMAC)
+			err = omap_sham_finish_hmac(req);
+	}
+
+	dev_dbg(dd->dev, "digcnt: %d, bufcnt: %d\n", ctx->digcnt, ctx->bufcnt);
+
+	return err;
 }
 
 static void omap_sham_finish_req(struct ahash_request *req, int err)
@@ -645,15 +640,12 @@ static void omap_sham_finish_req(struct ahash_request *req, int err)
 
 	if (!err) {
 		omap_sham_copy_hash(ctx->dd->req, 1);
-		if (ctx->flags & FLAGS_HMAC)
-			err = omap_sham_finish_req_hmac(req);
+		if (ctx->flags & FLAGS_FINAL)
+			err = omap_sham_finish(req);
 	} else {
 		ctx->flags |= FLAGS_ERROR;
 	}
 
-	if ((ctx->flags & FLAGS_FINAL) || err)
-		omap_sham_cleanup(req);
-
 	clk_disable(dd->iclk);
 	dd->flags &= ~FLAGS_BUSY;
 
@@ -809,22 +801,21 @@ static int omap_sham_final_shash(struct ahash_request *req)
 static int omap_sham_final(struct ahash_request *req)
 {
 	struct omap_sham_reqctx *ctx = ahash_request_ctx(req);
-	int err = 0;
 
 	ctx->flags |= FLAGS_FINUP;
 
-	if (!(ctx->flags & FLAGS_ERROR)) {
-		/* OMAP HW accel works only with buffers >= 9 */
-		/* HMAC is always >= 9 because of ipad */
-		if ((ctx->digcnt + ctx->bufcnt) < 9)
-			err = omap_sham_final_shash(req);
-		else if (ctx->bufcnt)
-			return omap_sham_enqueue(req, OP_FINAL);
-	}
+	if (ctx->flags & FLAGS_ERROR)
+		return 0; /* uncompleted hash is not needed */
 
-	omap_sham_cleanup(req);
+	/* OMAP HW accel works only with buffers >= 9 */
+	/* HMAC is always >= 9 because ipad == block size */
+	if ((ctx->digcnt + ctx->bufcnt) < 9)
+		return omap_sham_final_shash(req);
+	else if (ctx->bufcnt)
+		return omap_sham_enqueue(req, OP_FINAL);
 
-	return err;
+	/* copy ready hash (+ finalize hmac) */
+	return omap_sham_finish(req);
 }
 
 static int omap_sham_finup(struct ahash_request *req)
-- 
1.7.1


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

* Re: [PATCH 0/4] crypto: omap-sham driver fixes
  2011-04-20 10:34 [PATCH 0/4] crypto: omap-sham driver fixes Dmitry Kasatkin
                   ` (3 preceding siblings ...)
  2011-04-20 10:34 ` [PATCH 4/4] crypto: omap-sham - hmac calculation bug fix for sha1 base hash Dmitry Kasatkin
@ 2011-04-26  6:36 ` Herbert Xu
  2011-04-26  7:18     ` Dmitry Kasatkin
  4 siblings, 1 reply; 8+ messages in thread
From: Herbert Xu @ 2011-04-26  6:36 UTC (permalink / raw)
  To: Dmitry Kasatkin; +Cc: linux-crypto, linux-omap

On Wed, Apr 20, 2011 at 01:34:54PM +0300, Dmitry Kasatkin wrote:
> Hi,
> 
> Here is few patches with couple of important fixes...

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

* Re: [PATCH 0/4] crypto: omap-sham driver fixes
  2011-04-26  6:36 ` [PATCH 0/4] crypto: omap-sham driver fixes Herbert Xu
@ 2011-04-26  7:18     ` Dmitry Kasatkin
  0 siblings, 0 replies; 8+ messages in thread
From: Dmitry Kasatkin @ 2011-04-26  7:18 UTC (permalink / raw)
  To: ext Herbert Xu; +Cc: linux-crypto, linux-omap

Thanks.

On 26/04/11 09:36, ext Herbert Xu wrote:
> On Wed, Apr 20, 2011 at 01:34:54PM +0300, Dmitry Kasatkin wrote:
>> Hi,
>>
>> Here is few patches with couple of important fixes...
> All applied.  Thanks!

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

* Re: [PATCH 0/4] crypto: omap-sham driver fixes
@ 2011-04-26  7:18     ` Dmitry Kasatkin
  0 siblings, 0 replies; 8+ messages in thread
From: Dmitry Kasatkin @ 2011-04-26  7:18 UTC (permalink / raw)
  To: ext Herbert Xu; +Cc: linux-crypto, linux-omap

Thanks.

On 26/04/11 09:36, ext Herbert Xu wrote:
> On Wed, Apr 20, 2011 at 01:34:54PM +0300, Dmitry Kasatkin wrote:
>> Hi,
>>
>> Here is few patches with couple of important fixes...
> All applied.  Thanks!

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

end of thread, other threads:[~2011-04-26  7:18 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-20 10:34 [PATCH 0/4] crypto: omap-sham driver fixes Dmitry Kasatkin
2011-04-20 10:34 ` [PATCH 1/4] crypto: omap-sham - fix concurrent sha1 calculations Dmitry Kasatkin
2011-04-20 10:34 ` [PATCH 2/4] crypto: omap-sham - remove debug print Dmitry Kasatkin
2011-04-20 10:34 ` [PATCH 3/4] crypto: omap-sham - enable driver for EMU chips Dmitry Kasatkin
2011-04-20 10:34 ` [PATCH 4/4] crypto: omap-sham - hmac calculation bug fix for sha1 base hash Dmitry Kasatkin
2011-04-26  6:36 ` [PATCH 0/4] crypto: omap-sham driver fixes Herbert Xu
2011-04-26  7:18   ` Dmitry Kasatkin
2011-04-26  7:18     ` Dmitry Kasatkin

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.