According to the spec, an implementation of CipherSpi should reset itself in 'doFinal' once the last block (if any) is processed.

This patch resets the cipher in 'engineDoFinal.'

2005-10-02  Casey Marshall  <[EMAIL PROTECTED]>

    * source/gnu/crypto/jce/cipher/CipherAdapter.java
    (engineInit): call 'reset.'
    (engineDoFinal): call 'reset.'
    (reset): new method.

Committed,

Index: source/gnu/crypto/jce/cipher/CipherAdapter.java
===================================================================
RCS file: 
/cvsroot/gnu-crypto/gnu-crypto/source/gnu/crypto/jce/cipher/CipherAdapter.java,v
retrieving revision 1.3
diff -u -B -b -r1.3 CipherAdapter.java
--- source/gnu/crypto/jce/cipher/CipherAdapter.java     28 Sep 2003 00:10:35 
-0000      1.3
+++ source/gnu/crypto/jce/cipher/CipherAdapter.java     2 Oct 2005 20:33:29 
-0000
@@ -243,14 +243,7 @@
          System.arraycopy(kbb, 0, kb, 0, keyLen);
       }
       attributes.put(IBlockCipher.KEY_MATERIAL, kb);
-      mode.reset();
-      mode.init(attributes);
-      if (pad != null) {
-         pad.reset();
-         pad.init(blockLen);
-      }
-      partBlock = new byte[blockLen];
-      partLen = 0;
+      reset ();
    }
 
    protected void
@@ -409,6 +402,17 @@
          }
          result = buf;
       }
+
+      try
+        {
+          reset ();
+        }
+      catch (InvalidKeyException ike)
+        {
+          // Should not happen; if we initialized it with the current
+          // parameters before, we should be able to do it again.
+          throw new Error (ike);
+        }
       return result;
    }
 
@@ -422,5 +426,17 @@
       }
       System.arraycopy(buf, 0, out, outOff, buf.length);
       return buf.length;
+   }
+
+   private void reset () throws InvalidKeyException
+   {
+      mode.reset();
+      mode.init(attributes);
+      if (pad != null) {
+         pad.reset();
+         pad.init(blockLen);
+      }
+      partBlock = new byte[blockLen];
+      partLen = 0;
    }
 }
_______________________________________________
gnu-crypto-discuss mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/gnu-crypto-discuss

Reply via email to