Patch: FYI: bug fix from classpath

Tom Tromey tromey@redhat.com
Tue Feb 11 00:07:00 GMT 2003


I'm checking this in to 3.3 and 3.4.

This is a fix from Classpath.  It fixes a Mauve failure.

Tom

Index: ChangeLog
from  Raif S. Naffah  <raif@fl.net.au>

	* gnu/java/security/provider/SHA1PRNG.java (ensureIsSeeded): new 
	method used to ensure seeding has occurred and that a specific 
	seed can be set and used.

Index: gnu/java/security/provider/SHA1PRNG.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/security/provider/SHA1PRNG.java,v
retrieving revision 1.4
diff -u -r1.4 SHA1PRNG.java
--- gnu/java/security/provider/SHA1PRNG.java 22 Jan 2002 22:40:02 -0000 1.4
+++ gnu/java/security/provider/SHA1PRNG.java 11 Feb 2003 00:06:17 -0000
@@ -1,5 +1,5 @@
 /* SHA1PRNG.java --- Secure Random SPI SHA1PRNG
-   Copyright (C) 1999, 2001 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2001, 2003 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -51,27 +51,22 @@
   byte data[];
   int seedpos;
   int datapos;
+  private boolean seeded = false; // set to true when we seed this
 
   public SHA1PRNG()
   {
     try {
       digest = MessageDigest.getInstance("SHA");
     } catch ( NoSuchAlgorithmException nsae) {
-      System.out.println("Failed to find SHA Message Digest: " + nsae);
-      nsae.printStackTrace();
+//      System.out.println("Failed to find SHA Message Digest: " + nsae);
+//      nsae.printStackTrace();
+      throw new InternalError ("no SHA implementation found");
     }
 
     seed = new byte[20];
     seedpos = 0;
     data = new byte[40];
-    datapos = 0;
-
-    new Random().nextBytes(seed);
-
-    byte digestdata[];
-    digestdata = digest.digest( data );
-    System.arraycopy( digestdata, 0, data, 0, 20);
-
+    datapos = 20;  // try to force hashing a first block
   }
 
   public void engineSetSeed(byte[] seed)
@@ -84,6 +79,7 @@
 
   public void engineNextBytes(byte[] bytes)
   {
+    ensureIsSeeded ();
     int loc = 0;
     while (loc < bytes.length)
       {
@@ -113,4 +109,18 @@
     engineNextBytes( tmp );
     return tmp;
   }
+
+  private void ensureIsSeeded()
+  {
+    if (!seeded)
+      {
+        new Random(0L).nextBytes(seed);
+
+        byte[] digestdata = digest.digest(data);
+        System.arraycopy(digestdata, 0, data, 0, 20);
+
+        seeded = true;
+      }
+  }
+
 }



More information about the Java-patches mailing list