summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimo Schulz <twoaday@freakmail.de>2002-06-05 18:10:20 +0000
committerTimo Schulz <twoaday@freakmail.de>2002-06-05 18:10:20 +0000
commit6f755e7e69ac08f5a3f81e78eef17033935e78b5 (patch)
tree7ef1fba80bb668303e59062612a3cdafb338a016
parent0c22c33aa1c5c3f4fa87622b0441538fd09adb8d (diff)
downloadlibgcrypt-6f755e7e69ac08f5a3f81e78eef17033935e78b5.tar.gz
2002-06-05 Timo Schulz <ts@winpt.org>
* cipher.c (gcry_cipher_encrypt, gcry_cipher_decrypt): Check that the input size is a multiple of the blocksize.
-rw-r--r--cipher/ChangeLog5
-rw-r--r--cipher/cipher.c16
2 files changed, 15 insertions, 6 deletions
diff --git a/cipher/ChangeLog b/cipher/ChangeLog
index 19fbd288..f3381d9d 100644
--- a/cipher/ChangeLog
+++ b/cipher/ChangeLog
@@ -1,3 +1,8 @@
+2002-06-05 Timo Schulz <ts@winpt.org>
+
+ * cipher.c (gcry_cipher_encrypt, gcry_cipher_decrypt):
+ Check that the input size is a multiple of the blocksize.
+
2002-05-21 Werner Koch <wk@gnupg.org>
* primegen.c, elgamal.c, dsa.c (progress): Do not print anything
diff --git a/cipher/cipher.c b/cipher/cipher.c
index 2c45f4b1..a5e05068 100644
--- a/cipher/cipher.c
+++ b/cipher/cipher.c
@@ -842,9 +842,11 @@ gcry_cipher_encrypt( GCRY_CIPHER_HD h, byte *out, size_t outsize,
else {
if ( outsize < inlen )
return set_lasterr ( GCRYERR_TOO_SHORT );
- /* fixme: check that the inlength is a multipe of the blocksize
- * if a blockoriented mode is used, or modify cipher_encrypt to
- * return an error in this case */
+ if ( ( h->mode == GCRY_CIPHER_MODE_ECB ||
+ h->mode == GCRY_CIPHER_MODE_CBC ) &&
+ (inlen % h->blocksize) != 0 )
+ return set_lasterr( GCRYERR_INV_ARG );
+
rc = cipher_encrypt ( h, out, in, inlen );
}
@@ -912,9 +914,11 @@ gcry_cipher_decrypt( GCRY_CIPHER_HD h, byte *out, size_t outsize,
else {
if( outsize < inlen )
return set_lasterr( GCRYERR_TOO_SHORT );
- /* fixme: check that the inlength is a multipe of the blocksize
- * if a blockoriented mode is used, or modify cipher_encrypt to
- * return an error in this case */
+ if ( ( h->mode == GCRY_CIPHER_MODE_ECB ||
+ h->mode == GCRY_CIPHER_MODE_CBC )
+ && ( inlen % h->blocksize ) != 0 )
+ return set_lasterr( GCRYERR_INV_ARG );
+
rc = cipher_decrypt( h, out, in, inlen );
}
return rc? set_lasterr (rc):0;