[cp-patches] PATCH: fix Fortuna

Casey Marshall csm at gnu.org
Wed Apr 12 18:07:58 UTC 2006


Hi.

I was playing with the Fortuna PRNG a little, and found a bug where  
it would not initialize its block when `setup' is called (the  
Generator PRNG also has this problem). As a consequence, the first  
block you get out of the PRNG is all zeros. This patch fixes that  
problem.

2006-04-12  Casey Marshall  <csm at gnu.org>

	* gnu/javax/crypto/prng/Fortuna.java (setup): call `fillBlock.'
	(Generator.setup): call `fillBlock.'

Committed.

-------------- next part --------------
Index: gnu/javax/crypto/prng/Fortuna.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/javax/crypto/prng/Fortuna.java,v
retrieving revision 1.1
diff -u -B -b -r1.1 Fortuna.java
--- gnu/javax/crypto/prng/Fortuna.java	26 Jan 2006 02:25:09 -0000	1.1
+++ gnu/javax/crypto/prng/Fortuna.java	12 Apr 2006 18:00:39 -0000
@@ -142,6 +142,14 @@
     pool = 0;
     pool0Count = 0;
     generator.init(attributes);
+    try
+      {
+        fillBlock ();
+      }
+    catch (LimitReachedException shouldNotHappen)
+      {
+        throw new RuntimeException (shouldNotHappen);
+      }
   }
 
   public void fillBlock() throws LimitReachedException
@@ -324,6 +332,7 @@
       byte[] seed = (byte[]) attributes.get(SEED);
       if (seed != null)
         addRandomBytes(seed);
+      fillBlock ();
     }
 
     /**


More information about the Classpath-patches mailing list