Skip to contentSkip to conversation

crypto: eseqiv - fix IV generation for sync algorithms

PATCH Applied Steffen Klassert 2 participants 4 messages Apr 14, 2009 – Apr 15, 2009 Crypto API

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: eseqiv - fix IV generation for sync algorithms

If crypto_ablkcipher_encrypt() returns synchronous, eseqiv_complete2() is called even if req->giv is already the pointer to the generated IV. The generated IV is overwritten with some random data in this case. This patch fixes this by calling eseqiv_complete2() just in the case where an asynchronous algorithm would call eseqiv_complete() as the complete function.

---
 crypto/eseqiv.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
crypto/eseqiv.c +2 -1
index 2a342c8..2fa53b0 100644
@@ -153,7 +153,8 @@ static int eseqiv_givencrypt(struct skcipher_givcrypt_request *req)
 	if (err)
 		goto out;
 
-	eseqiv_complete2(req);
+	if (complete == eseqiv_complete)
+		eseqiv_complete2(req);
 
 out:
 	return err;
Signature · 1 line
1.5.4.2
maintainer
#1 lore raw
Quoted 8 lines · Steffen Klassert

If crypto_ablkcipher_encrypt() returns synchronous, eseqiv_complete2() is called even if req->giv is already the pointer to the generated IV. The generated IV is overwritten with some random data in this case. This patch fixes this by calling eseqiv_complete2() just in the case where an asynchronous algorithm would call eseqiv_complete() as the complete function.

Well caught! Clearly no one has ever tried this before :)

crypto/eseqiv.c static int eseqiv_givencrypt(struct skcipher_givcrypt_request *req) · line 157

Quoted 11 lines
crypto/eseqiv.c +2 -1
index 2a342c8..2fa53b0 100644
@@ -153,7 +153,8 @@ static int eseqiv_givencrypt(struct skcipher_givcrypt_request *req)
 	if (err)
 		goto out;
 
-	eseqiv_complete2(req);
+	if (complete == eseqiv_complete)
+		eseqiv_complete2(req);

Being paranoid it may just be possible for our caller (or one if its ancestors) to be eseqiv, in which case this test will give a false positive.

So how about doing what seqiv does and check

	if (giv != req->giv)

Thanks,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
#2 lore raw
Quoted 3 lines · Herbert Xu

Well caught! Clearly no one has ever tried this before :)

I thought so :)

Quoted 5 lines

So how about doing what seqiv does and check

	if (giv != req->giv)

Yes, that's probaply the better check.
An updated patch is below.

crypto: eseqiv - fix IV generation for sync algorithms

If crypto_ablkcipher_encrypt() returns synchronous, eseqiv_complete2() is called even if req->giv is already the pointer to the generated IV. The generated IV is overwritten with some random data in this case. This patch fixes this by calling eseqiv_complete2() just if the generated IV has to be copied to req->giv.

---
 crypto/eseqiv.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
crypto/eseqiv.c +2 -1
index 2a342c8..3ca3b66 100644
@@ -153,7 +153,8 @@ static int eseqiv_givencrypt(struct skcipher_givcrypt_request *req)
 	if (err)
 		goto out;
 
-	eseqiv_complete2(req);
+	if (giv != req->giv)
+		eseqiv_complete2(req);
 
 out:
 	return err;
Signature · 1 line
1.5.4.2
maintainer Applied
#3 lore raw
Quoted 2 lines · Steffen Klassert

crypto: eseqiv - fix IV generation for sync algorithms

Applied to crypt-2.6. Thanks a lot!

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt