[kaffe] CVS kaffe (guilhem): VMSecureRandom fix.

Kaffe CVS cvs-commits at kaffe.org
Tue Apr 18 03:28:20 PDT 2006


PatchSet 7233 
Date: 2006/04/18 10:18:07
Author: guilhem
Branch: HEAD
Tag: (none) 
Log:
VMSecureRandom fix.

Members: 
	ChangeLog:1.4739->1.4740 
	libraries/clib/management/Classpath.c:1.9->1.10 
	libraries/javalib/vmspecific/java/security/VMSecureRandom.java:1.1->1.2 
	libraries/javalib/vmspecific/org/kaffe/security/LameRandomness.java:1.1->1.2 
	libraries/javalib/vmspecific/org/kaffe/security/Randomness.java:1.1->1.2 
	libraries/javalib/vmspecific/org/kaffe/security/UnixRandomness.java:1.1->1.2 
	libraries/javalib/vmspecific/org/kaffe/security/provider/SHA1PRNG.java:1.1->1.2 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.4739 kaffe/ChangeLog:1.4740
--- kaffe/ChangeLog:1.4739	Tue Apr 18 10:06:37 2006
+++ kaffe/ChangeLog	Tue Apr 18 10:18:07 2006
@@ -1,5 +1,17 @@
 2006-04-18  Guilhem Lavaux  <guilhem at kaffe.org>
 
+	* libraries/clib/management/Classpath.c: Renamed addClasspath and
+	prependClasspath.
+
+	* libraries/javalib/vmspecific/java/security/VMSecureRandom.java,
+	libraries/javalib/vmspecific/org/kaffe/security/LameRandomness.java,
+	libraries/javalib/vmspecific/org/kaffe/security/Randomness.java,
+	libraries/javalib/vmspecific/org/kaffe/security/UnixRandomness.java,
+	libraries/javalib/vmspecific/org/kaffe/security/provider/SHA1PRNG.java:
+	Make use of /dev/urandom if it is available.
+
+2006-04-18  Guilhem Lavaux  <guilhem at kaffe.org>
+
 	* kaffe/kaffevm/findInJar.c,
 	kaffe/kaffevm/support.h
 	(KaffeVM_addClasspath, KaffeVM_prependClasspath): Renamed to
Index: kaffe/libraries/clib/management/Classpath.c
diff -u kaffe/libraries/clib/management/Classpath.c:1.9 kaffe/libraries/clib/management/Classpath.c:1.10
--- kaffe/libraries/clib/management/Classpath.c:1.9	Wed Oct 19 20:10:38 2005
+++ kaffe/libraries/clib/management/Classpath.c	Tue Apr 18 10:18:13 2006
@@ -25,7 +25,7 @@
 	char *s;
 
 	s = checkPtr(stringJava2C(str));
-	addClasspath(s);
+	KaffeVM_addClasspath(s);
 	gc_free(s);
 }
 
@@ -38,7 +38,7 @@
 	char *s;
 
 	s = checkPtr(stringJava2C(str));
-	prependClasspath(s);
+	KaffeVM_prependClasspath(s);
 	gc_free(s);
 }
 
Index: kaffe/libraries/javalib/vmspecific/java/security/VMSecureRandom.java
diff -u kaffe/libraries/javalib/vmspecific/java/security/VMSecureRandom.java:1.1 kaffe/libraries/javalib/vmspecific/java/security/VMSecureRandom.java:1.2
--- kaffe/libraries/javalib/vmspecific/java/security/VMSecureRandom.java:1.1	Mon Apr 17 17:58:15 2006
+++ kaffe/libraries/javalib/vmspecific/java/security/VMSecureRandom.java	Tue Apr 18 10:18:13 2006
@@ -41,6 +41,8 @@
 import gnu.classpath.SystemProperties;
 import gnu.java.security.action.GetSecurityPropertyAction;
 
+import org.kaffe.security.Randomness;
+import org.kaffe.security.UnixRandomness;
 import java.net.URL;
 
 /**
@@ -59,6 +61,18 @@
  */
 final class VMSecureRandom
 {
+  static private Randomness randomgen;
+
+  static
+  {
+    try
+      {
+	randomgen = new UnixRandomness();
+      }
+    catch (java.io.IOException e)
+      {	
+      }
+  }
 
   /**
    * Generate a random seed. Implementations are free to generate
@@ -77,6 +91,12 @@
     if (offset < 0 || offset + length > buffer.length)
       throw new IndexOutOfBoundsException();
 
+    if (randomgen != null)
+      {
+	randomgen.fill(buffer, offset, length);
+	return length;
+      }
+
     Spinner[] spinners = new Spinner[8];
     int n = 0x1;
     for (int i = 0; i < spinners.length; i++)
@@ -131,4 +151,4 @@
       running = false;
     }
   }
-}
\ No newline at end of file
+}
Index: kaffe/libraries/javalib/vmspecific/org/kaffe/security/LameRandomness.java
diff -u kaffe/libraries/javalib/vmspecific/org/kaffe/security/LameRandomness.java:1.1 kaffe/libraries/javalib/vmspecific/org/kaffe/security/LameRandomness.java:1.2
--- kaffe/libraries/javalib/vmspecific/org/kaffe/security/LameRandomness.java:1.1	Wed Oct 19 20:16:10 2005
+++ kaffe/libraries/javalib/vmspecific/org/kaffe/security/LameRandomness.java	Tue Apr 18 10:18:14 2006
@@ -35,7 +35,7 @@
 	 *
 	 * @see kaffe.security.Randomness#fill()
 	 */
-	public void fill(byte bits[])
+	public void fill(byte bits[], int offset, int length)
 	{
 		new Random().nextBytes(bits);
 	}
Index: kaffe/libraries/javalib/vmspecific/org/kaffe/security/Randomness.java
diff -u kaffe/libraries/javalib/vmspecific/org/kaffe/security/Randomness.java:1.1 kaffe/libraries/javalib/vmspecific/org/kaffe/security/Randomness.java:1.2
--- kaffe/libraries/javalib/vmspecific/org/kaffe/security/Randomness.java:1.1	Wed Oct 19 20:16:10 2005
+++ kaffe/libraries/javalib/vmspecific/org/kaffe/security/Randomness.java	Tue Apr 18 10:18:14 2006
@@ -31,7 +31,7 @@
 	 *
 	 * @param bits The array to fill with random bits.
 	 */
-	public abstract void fill(byte bits[]);
+	public abstract void fill(byte bits[], int offset, int length);
 
 	/**
 	 * @see java.lang.Object#toString()
Index: kaffe/libraries/javalib/vmspecific/org/kaffe/security/UnixRandomness.java
diff -u kaffe/libraries/javalib/vmspecific/org/kaffe/security/UnixRandomness.java:1.1 kaffe/libraries/javalib/vmspecific/org/kaffe/security/UnixRandomness.java:1.2
--- kaffe/libraries/javalib/vmspecific/org/kaffe/security/UnixRandomness.java:1.1	Wed Oct 19 20:16:10 2005
+++ kaffe/libraries/javalib/vmspecific/org/kaffe/security/UnixRandomness.java	Tue Apr 18 10:18:14 2006
@@ -53,11 +53,11 @@
 	 *
 	 * @see kaffe.security.Randomness#fill()
 	 */
-	public synchronized void fill(byte bits[])
+	public synchronized void fill(byte bits[], int offset, int length)
 	{
 		try
 		{
-			this.dis.readFully(bits);
+			this.dis.readFully(bits, offset, length);
 		}
 		catch(IOException e)
 		{
Index: kaffe/libraries/javalib/vmspecific/org/kaffe/security/provider/SHA1PRNG.java
diff -u kaffe/libraries/javalib/vmspecific/org/kaffe/security/provider/SHA1PRNG.java:1.1 kaffe/libraries/javalib/vmspecific/org/kaffe/security/provider/SHA1PRNG.java:1.2
--- kaffe/libraries/javalib/vmspecific/org/kaffe/security/provider/SHA1PRNG.java:1.1	Wed Oct 19 20:16:11 2005
+++ kaffe/libraries/javalib/vmspecific/org/kaffe/security/provider/SHA1PRNG.java	Tue Apr 18 10:18:17 2006
@@ -151,7 +151,7 @@
 		 * Fill the seed using the implementation specific source of
 		 * randomness.
 		 */
-		impl.fill(this.seed);
+		impl.fill(this.seed, 0, SEED_SIZE);
 		
 		try
 		{




More information about the kaffe mailing list