PatchSet 5591 
Date: 2005/02/23 19:02:35
Author: robilad
Branch: HEAD
Tag: (none) 
Log:
Small fixlets for SHA1PRNG

2005-02-23  Dalibor Topic  <[EMAIL PROTECTED]>

* test/regression/SecureRandomTest.java (SecureRandomTest):
Improved error message slightly.

* libraries/javalib/gnu/java/security/provider/SHA1PRNG.java
(SEED_SIZE, DATA_SIZE): new constants.  Use them instead of
magic numbers.
(SHA1PRNG) Added documentation.

Members: 
        ChangeLog:1.3635->1.3636 
        libraries/javalib/gnu/java/security/provider/SHA1PRNG.java:1.1->1.2 
        test/regression/SecureRandomTest.java:1.1->1.2 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.3635 kaffe/ChangeLog:1.3636
--- kaffe/ChangeLog:1.3635      Tue Feb 22 11:05:52 2005
+++ kaffe/ChangeLog     Wed Feb 23 19:02:35 2005
@@ -1,3 +1,13 @@
+2005-02-23  Dalibor Topic  <[EMAIL PROTECTED]>
+
+       * test/regression/SecureRandomTest.java (SecureRandomTest): 
+       Improved error message slightly.
+
+       * libraries/javalib/gnu/java/security/provider/SHA1PRNG.java 
+       (SEED_SIZE, DATA_SIZE): new constants.  Use them instead of
+       magic numbers.
+       (SHA1PRNG) Added documentation.
+
 2005-02-22  Dalibor Topic  <[EMAIL PROTECTED]>
 
        Resynced with GNU Classpath.
Index: kaffe/libraries/javalib/gnu/java/security/provider/SHA1PRNG.java
diff -u kaffe/libraries/javalib/gnu/java/security/provider/SHA1PRNG.java:1.1 
kaffe/libraries/javalib/gnu/java/security/provider/SHA1PRNG.java:1.2
--- kaffe/libraries/javalib/gnu/java/security/provider/SHA1PRNG.java:1.1        
Thu Sep 23 00:22:02 2004
+++ kaffe/libraries/javalib/gnu/java/security/provider/SHA1PRNG.java    Wed Feb 
23 19:02:39 2005
@@ -52,7 +52,18 @@
   int seedpos;
   int datapos;
   private boolean seeded = false; // set to true when we seed this
-
+  /**
+   * The size of seed.
+   */
+  private static final int SEED_SIZE = 20;
+  /**
+   * The size of data.
+   */
+  private static final int DATA_SIZE = 40;
+
+  /**
+   * Create a new SHA-1 pseudo-random number generator.
+   */
   public SHA1PRNG()
   {
     try {
@@ -63,17 +74,17 @@
       throw new InternalError ("no SHA implementation found");
     }
 
-    seed = new byte[20];
+    seed = new byte[SEED_SIZE];
     seedpos = 0;
-    data = new byte[40];
-    datapos = 20;  // try to force hashing a first block
+    data = new byte[DATA_SIZE];
+    datapos = SEED_SIZE;  // try to force hashing a first block
   }
 
   public void engineSetSeed(byte[] seed)
   {
     for(int i = 0; i < seed.length; i++)
-      this.seed[seedpos++ % 20] ^= seed[i];
-    seedpos %= 20;
+      this.seed[seedpos++ % SEED_SIZE] ^= seed[i];
+    seedpos %= SEED_SIZE;
 
   }
 
@@ -83,7 +94,7 @@
     int loc = 0;
     while (loc < bytes.length)
       {
-       int copy = Math.min (bytes.length - loc, 20 - datapos);
+       int copy = Math.min (bytes.length - loc, SEED_SIZE - datapos);
 
        if (copy > 0)
          {
@@ -94,9 +105,9 @@
        else
          {
            // No data ready for copying, so refill our buffer.
-           System.arraycopy( seed, 0, data, 20, 20);
+           System.arraycopy( seed, 0, data, SEED_SIZE, SEED_SIZE);
            byte[] digestdata = digest.digest( data );
-           System.arraycopy( digestdata, 0, data, 0, 20);
+           System.arraycopy( digestdata, 0, data, 0, SEED_SIZE);
            datapos = 0;
          }
       }
@@ -117,7 +128,7 @@
         new Random(0L).nextBytes(seed);
 
         byte[] digestdata = digest.digest(data);
-        System.arraycopy(digestdata, 0, data, 0, 20);
+        System.arraycopy(digestdata, 0, data, 0, SEED_SIZE);
 
         seeded = true;
       }
Index: kaffe/test/regression/SecureRandomTest.java
diff -u kaffe/test/regression/SecureRandomTest.java:1.1 
kaffe/test/regression/SecureRandomTest.java:1.2
--- kaffe/test/regression/SecureRandomTest.java:1.1     Fri Feb 21 09:51:11 2003
+++ kaffe/test/regression/SecureRandomTest.java Wed Feb 23 19:02:39 2005
@@ -48,8 +48,9 @@
            }
            if( match )
            {
-               throw new Error("The \"secure\" random isn't! "
-                               + toPlainString(data, Integer.MAX_VALUE));
+               throw new Error("The \"secure\" random isn't! : lpc=  " + lpc 
+                               + " lpc2 = " + lpc2 
+                               + " data = " + toPlainString(data, 
Integer.MAX_VALUE));
            }
        }
     }

_______________________________________________
kaffe mailing list
[email protected]
http://kaffe.org/cgi-bin/mailman/listinfo/kaffe

Reply via email to