On Wed, 2006-07-12 at 11:44 -0700, Casey Marshall wrote:
> On Jul 10, 2006, at 6:38 PM, Matthew Wringe wrote:
>
> > 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,
> >
>
> Looks good. Please commit.
The following patch has now been commited.
Thanks,
Matt Wringe
Changelog:
2006-07-14 Matt Wringe <[EMAIL PROTECTED]>
* 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 13 Jul 2006 21:02:21 -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.defaultBlockSize())
+ {
+ throw new InvalidAlgorithmParameterException();
+ }
+
attributes.put(IMode.IV, ((IvParameterSpec) params).getIV());
blockLen = cipher.defaultBlockSize();
attributes.put(IBlockCipher.CIPHER_BLOCK_SIZE, Integer.valueOf(blockLen));