libgcrypt/cipher (ChangeLog cipher.c)
cvs user mo
cvs at cvs.gnupg.org
Sat Mar 19 18:21:43 CET 2005
Date: Saturday, March 19, 2005 @ 18:35:27
Author: mo
Path: /cvs/libgcrypt/libgcrypt/cipher
Modified: ChangeLog cipher.c
2005-03-19 Moritz Schulte <moritz at g10code.com>
* cipher.c (do_cbc_encrypt): Be careful to not overwrite data,
which is to be used later on. This happend, in case CTS is
enabled and OUTBUF is equal to INBUF.
-----------+
ChangeLog | 6 ++++++
cipher.c | 28 +++++++++++++++++-----------
2 files changed, 23 insertions(+), 11 deletions(-)
Index: libgcrypt/cipher/ChangeLog
diff -u libgcrypt/cipher/ChangeLog:1.225 libgcrypt/cipher/ChangeLog:1.226
--- libgcrypt/cipher/ChangeLog:1.225 Fri Feb 25 11:48:10 2005
+++ libgcrypt/cipher/ChangeLog Sat Mar 19 18:35:27 2005
@@ -1,3 +1,9 @@
+2005-03-19 Moritz Schulte <moritz at g10code.com>
+
+ * cipher.c (do_cbc_encrypt): Be careful to not overwrite data,
+ which is to be used later on. This happend, in case CTS is
+ enabled and OUTBUF is equal to INBUF.
+
2005-02-25 Werner Koch <wk at g10code.com>
* pubkey.c (gcry_pk_get_keygrip): Allow for shadowed-private-key.
Index: libgcrypt/cipher/cipher.c
diff -u libgcrypt/cipher/cipher.c:1.70 libgcrypt/cipher/cipher.c:1.71
--- libgcrypt/cipher/cipher.c:1.70 Mon Aug 23 15:33:15 2004
+++ libgcrypt/cipher/cipher.c Sat Mar 19 18:35:27 2005
@@ -784,30 +784,36 @@
outbuf[i] = inbuf[i] ^ *ivp++;
c->cipher->encrypt ( &c->context.c, outbuf, outbuf );
memcpy(c->iv, outbuf, blocksize );
- inbuf += c->cipher->blocksize;
+ inbuf += blocksize;
if (!(c->flags & GCRY_CIPHER_CBC_MAC))
- outbuf += c->cipher->blocksize;
+ outbuf += blocksize;
}
if ((c->flags & GCRY_CIPHER_CBC_CTS) && nbytes > blocksize)
{
+ /* We have to be careful here, since outbuf might be equal to
+ inbuf. */
+
int restbytes;
+ byte b;
if ((nbytes % blocksize) == 0)
restbytes = blocksize;
else
restbytes = nbytes % blocksize;
- memcpy(outbuf, outbuf - c->cipher->blocksize, restbytes);
- outbuf -= c->cipher->blocksize;
-
- for(ivp=c->iv,i=0; i < restbytes; i++ )
- outbuf[i] = inbuf[i] ^ *ivp++;
- for(; i < blocksize; i++ )
- outbuf[i] = 0 ^ *ivp++;
+ outbuf -= blocksize;
+ for (ivp = c->iv, i = 0; i < restbytes; i++)
+ {
+ b = inbuf[i];
+ outbuf[blocksize + i] = outbuf[i];
+ outbuf[i] = b ^ *ivp++;
+ }
+ for (; i < blocksize; i++)
+ outbuf[i] = 0 ^ *ivp++;
- c->cipher->encrypt ( &c->context.c, outbuf, outbuf );
- memcpy(c->iv, outbuf, blocksize );
+ c->cipher->encrypt (&c->context.c, outbuf, outbuf);
+ memcpy (c->iv, outbuf, blocksize);
}
}
More information about the Gnupg-commits
mailing list