This patch is in relation to bug 28104: Cipher.init(...) does not check
if the passed parameters are valid:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28104

The patch adds a simple test to the CipherAdapter that will throw a
InvalidAlgorithmParameterException if the IV size does not match the
block size of the cipher.

Thanks,

Matt Wringe

Changelog:

2006-07-10  Matt Wringe  <[EMAIL PROTECTED]>

 PR classpath/28104
 * gnu/javax/crypto/jce/cipher/CipherAdapter.java 
 (engineInit): Throw InvalidAlgorithmParameterException
 for invalid IVParameterSpec IV length.
Index: CipherAdapter.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/javax/crypto/jce/cipher/CipherAdapter.java,v
retrieving revision 1.7
diff -u -r1.7 CipherAdapter.java
--- CipherAdapter.java	28 Jun 2006 11:16:54 -0000	1.7
+++ CipherAdapter.java	11 Jul 2006 01:37:13 -0000
@@ -343,6 +343,12 @@
       }
     else if (params instanceof IvParameterSpec)
       {
+        // The size of the IV must match the block size
+        if (((IvParameterSpec) params).getIV().length != cipher.currentBlockSize())
+          {
+            throw new InvalidAlgorithmParameterException();
+          }
+        
         attributes.put(IMode.IV, ((IvParameterSpec) params).getIV());
         blockLen = cipher.defaultBlockSize();
         attributes.put(IBlockCipher.CIPHER_BLOCK_SIZE, Integer.valueOf(blockLen));

Reply via email to