Added checks for encryption/decryption lengths that they must
[silc.git] / lib / silccrypt / silccipher.c
index 72d984b35cebbcf324ae9fac7ba17814134668ec..db4a332917d6201912ec6b2e8741db2f8c175b49 100644 (file)
@@ -315,6 +315,11 @@ bool silc_cipher_encrypt(SilcCipher cipher, const unsigned char *src,
                         unsigned char *dst, SilcUInt32 len, 
                         unsigned char *iv)
 {
+#ifdef SILC_DEBUG
+  assert((len & (cipher->cipher->block_len - 1)) == 0);
+#endif
+  if (len & (cipher->cipher->block_len - 1))
+    return FALSE;
   return cipher->cipher->encrypt(cipher->context, src, dst, len,
                                 iv ? iv : cipher->iv);
 }
@@ -325,6 +330,13 @@ bool silc_cipher_decrypt(SilcCipher cipher, const unsigned char *src,
                         unsigned char *dst, SilcUInt32 len, 
                         unsigned char *iv)
 {
+#if 0 /* Remove to 0.9.11 */
+#ifdef SILC_DEBUG
+  assert((len & (cipher->cipher->block_len - 1)) == 0);
+#endif
+  if (len & (cipher->cipher->block_len - 1))
+    return FALSE;
+#endif
   return cipher->cipher->decrypt(cipher->context, src, dst, len,
                                 iv ? iv : cipher->iv);
 }