All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] crypto/chacha20: fix handling of chunked input
@ 2017-08-14 13:28 Ard Biesheuvel
  2017-08-14 13:28 ` [PATCH 2/2] crypto: testmgr - add chunked test cases for chacha20 Ard Biesheuvel
  2017-08-22  7:58 ` [PATCH 1/2] crypto/chacha20: fix handling of chunked input Herbert Xu
  0 siblings, 2 replies; 4+ messages in thread
From: Ard Biesheuvel @ 2017-08-14 13:28 UTC (permalink / raw)
  To: linux-crypto; +Cc: herbert, steffen.klassert, tobias, martin, Ard Biesheuvel

Commit 9ae433bc79f9 ("crypto: chacha20 - convert generic and x86 versions
to skcipher") ported the existing chacha20 code to use the new skcipher
API, and introduced a bug along the way. Unfortunately, the tcrypt tests
did not catch the error, and it was only found recently by Tobias.

Stefan kindly diagnosed the error, and proposed a fix which is similar
to the one below, with the exception that 'walk.stride' is used rather
than the hardcoded block size. This does not actually matter in this
case, but it's a better example of how to use the skcipher walk API.

Fixes: 9ae433bc79f9 ("crypto: chacha20 - convert generic and x86 ...")
Cc: <stable@vger.kernel.org> # v4.11+
Cc: Steffen Klassert <steffen.klassert@secunet.com>
Reported-by: Tobias Brunner <tobias@strongswan.org>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 crypto/chacha20_generic.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/crypto/chacha20_generic.c b/crypto/chacha20_generic.c
index 8b3c04d625c3..4a45fa4890c0 100644
--- a/crypto/chacha20_generic.c
+++ b/crypto/chacha20_generic.c
@@ -91,9 +91,14 @@ int crypto_chacha20_crypt(struct skcipher_request *req)
 	crypto_chacha20_init(state, ctx, walk.iv);
 
 	while (walk.nbytes > 0) {
+		unsigned int nbytes = walk.nbytes;
+
+		if (nbytes < walk.total)
+			nbytes = round_down(nbytes, walk.stride);
+
 		chacha20_docrypt(state, walk.dst.virt.addr, walk.src.virt.addr,
-				 walk.nbytes);
-		err = skcipher_walk_done(&walk, 0);
+				 nbytes);
+		err = skcipher_walk_done(&walk, walk.nbytes - nbytes);
 	}
 
 	return err;
-- 
2.11.0

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

* [PATCH 2/2] crypto: testmgr - add chunked test cases for chacha20
  2017-08-14 13:28 [PATCH 1/2] crypto/chacha20: fix handling of chunked input Ard Biesheuvel
@ 2017-08-14 13:28 ` Ard Biesheuvel
  2017-08-22  7:58   ` Herbert Xu
  2017-08-22  7:58 ` [PATCH 1/2] crypto/chacha20: fix handling of chunked input Herbert Xu
  1 sibling, 1 reply; 4+ messages in thread
From: Ard Biesheuvel @ 2017-08-14 13:28 UTC (permalink / raw)
  To: linux-crypto; +Cc: herbert, steffen.klassert, tobias, martin, Ard Biesheuvel

We failed to catch a bug in the chacha20 code after porting it to the
skcipher API. We would have caught it if any chunked tests had been
defined, so define some now so we will catch future regressions.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 crypto/testmgr.h | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/crypto/testmgr.h b/crypto/testmgr.h
index 6ceb0e2758bb..d54971d2d1c8 100644
--- a/crypto/testmgr.h
+++ b/crypto/testmgr.h
@@ -32675,6 +32675,10 @@ static const struct cipher_testvec chacha20_enc_tv_template[] = {
 			  "\x5b\x86\x2f\x37\x30\xe3\x7c\xfd"
 			  "\xc4\xfd\x80\x6c\x22\xf2\x21",
 		.rlen	= 375,
+		.also_non_np = 1,
+		.np	= 3,
+		.tap	= { 375 - 20, 4, 16 },
+
 	}, { /* RFC7539 A.2. Test Vector #3 */
 		.key	= "\x1c\x92\x40\xa5\xeb\x55\xd3\x8a"
 			  "\xf3\x33\x88\x86\x04\xf6\xb5\xf0"
@@ -33049,6 +33053,9 @@ static const struct cipher_testvec chacha20_enc_tv_template[] = {
 			  "\xa1\xed\xad\xd5\x76\xfa\x24\x8f"
 			  "\x98",
 		.rlen	= 1281,
+		.also_non_np = 1,
+		.np	= 3,
+		.tap	= { 1200, 1, 80 },
 	},
 };
 
-- 
2.11.0

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

* Re: [PATCH 1/2] crypto/chacha20: fix handling of chunked input
  2017-08-14 13:28 [PATCH 1/2] crypto/chacha20: fix handling of chunked input Ard Biesheuvel
  2017-08-14 13:28 ` [PATCH 2/2] crypto: testmgr - add chunked test cases for chacha20 Ard Biesheuvel
@ 2017-08-22  7:58 ` Herbert Xu
  1 sibling, 0 replies; 4+ messages in thread
From: Herbert Xu @ 2017-08-22  7:58 UTC (permalink / raw)
  To: Ard Biesheuvel; +Cc: linux-crypto, steffen.klassert, tobias, martin

On Mon, Aug 14, 2017 at 02:28:14PM +0100, Ard Biesheuvel wrote:
> Commit 9ae433bc79f9 ("crypto: chacha20 - convert generic and x86 versions
> to skcipher") ported the existing chacha20 code to use the new skcipher
> API, and introduced a bug along the way. Unfortunately, the tcrypt tests
> did not catch the error, and it was only found recently by Tobias.
> 
> Stefan kindly diagnosed the error, and proposed a fix which is similar
> to the one below, with the exception that 'walk.stride' is used rather
> than the hardcoded block size. This does not actually matter in this
> case, but it's a better example of how to use the skcipher walk API.
> 
> Fixes: 9ae433bc79f9 ("crypto: chacha20 - convert generic and x86 ...")
> Cc: <stable@vger.kernel.org> # v4.11+
> Cc: Steffen Klassert <steffen.klassert@secunet.com>
> Reported-by: Tobias Brunner <tobias@strongswan.org>
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

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

* Re: [PATCH 2/2] crypto: testmgr - add chunked test cases for chacha20
  2017-08-14 13:28 ` [PATCH 2/2] crypto: testmgr - add chunked test cases for chacha20 Ard Biesheuvel
@ 2017-08-22  7:58   ` Herbert Xu
  0 siblings, 0 replies; 4+ messages in thread
From: Herbert Xu @ 2017-08-22  7:58 UTC (permalink / raw)
  To: Ard Biesheuvel; +Cc: linux-crypto, steffen.klassert, tobias, martin

On Mon, Aug 14, 2017 at 02:28:15PM +0100, Ard Biesheuvel wrote:
> We failed to catch a bug in the chacha20 code after porting it to the
> skcipher API. We would have caught it if any chunked tests had been
> defined, so define some now so we will catch future regressions.
> 
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

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

end of thread, other threads:[~2017-08-22  7:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-14 13:28 [PATCH 1/2] crypto/chacha20: fix handling of chunked input Ard Biesheuvel
2017-08-14 13:28 ` [PATCH 2/2] crypto: testmgr - add chunked test cases for chacha20 Ard Biesheuvel
2017-08-22  7:58   ` Herbert Xu
2017-08-22  7:58 ` [PATCH 1/2] crypto/chacha20: fix handling of chunked input Herbert Xu

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.