Bug 24642 - Failure to produce random values.
Summary: Failure to produce random values.
Status: RESOLVED FIXED
Alias: None
Product: classpath
Classification: Unclassified
Component: classpath (show other bugs)
Version: 0.20
: P3 normal
Target Milestone: 0.91
Assignee: Casey Marshall
URL:
Keywords:
: 27111 (view as bug list)
Depends on: 24481
Blocks:
  Show dependency treegraph
 
Reported: 2005-11-02 19:38 UTC by bensmyth
Modified: 2006-04-14 20:01 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-01-12 17:49:14


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description bensmyth 2005-11-02 19:38:37 UTC
The following code should produce random numbers between 0..2^5-1:

import java.math.BigInteger;
import java.security.SecureRandom;
 
class RndTest {
   public static void main(String[] args) {
      SecureRandom rnd = new SecureRandom();
      for (int i = 0; i < 10; i++)
         System.out.print(new BigInteger(5,rnd) + " ");
   }
}

[ben@localhost junit]$ java -version
java version "1.4.2"
gij (GNU libgcj) version 4.0.0 20050519 (Red Hat 4.0.0-8)
[ben@localhost src]$ java RndTest
0 31 12 21 21 16 8 24 15 20
[ben@localhost src]$ java RndTest
0 31 12 21 21 16 8 24 15 20
[ben@localhost src]$ java -Djava.security.egd=file:/dev/random RndTest
0 31 12 21 21 16 8 24 15 20


[brh@jupiter ~]$ java -version
java version "1.4.2"
gij (GNU libgcj) version 4.0.1 20050727 (Red Hat 4.0.1-5)

Copyright (C) 2005 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
[brh@jupiter ~]$ java RndTest
0 31 12 21 21 16 8 24 15 20
[brh@jupiter ~]$ java RndTest
0 31 12 21 21 16 8 24 15 20 



In addition the following fails (one would expect an 8):
import java.math.BigInteger;
import java.security.SecureRandom;

public class BigIntTest {
   public static void main(String[] args) {
      System.out.println(BigInteger.probablePrime(8,new SecureRandom()).bitLength());
   }
}

[ben@localhost junit]$ java -version
java version "1.4.2"
gij (GNU libgcj) version 4.0.0 20050519 (Red Hat 4.0.0-8)
[ben@localhost ~]$ java BigIntTest
2
[ben@localhost ~]$ java BigIntTest
2



See also: http://forums.java.sun.com/thread.jspa?messageID=3960085
Comment 1 Andrew Pinski 2005-11-02 19:43:21 UTC
This is related to PR 24481.
Comment 2 Audrius Meškauskas 2006-01-12 17:49:14 UTC
Confirmed for the GNU Classpath CVS version as of Thu Jan 12 18:47:25 CET 2006. On each start, we print the same sequence of numbers, when Sun's jre each time prints the different sequence of numbers.
Comment 3 Casey Marshall 2006-04-12 20:17:57 UTC
*** Bug 27111 has been marked as a duplicate of this bug. ***
Comment 4 Casey Marshall 2006-04-12 20:18:35 UTC
Testing a patch.
Comment 5 cvs-commit@developer.classpath.org 2006-04-14 18:34:50 UTC
Subject: Bug 24642

CVSROOT:	/cvsroot/classpath
Module name:	classpath
Branch: 	
Changes by:	Casey Marshall <rsdio@savannah.gnu.org>	06/04/14 18:33:43

Modified files:
	.              : ChangeLog NEWS 
	java/security  : SecureRandom.java 
Added files:
	vm/reference/java/security: VMSecureRandom.java 

Log message:
	2006-04-14  Casey Marshall  <csm@gnu.org>
	
	Fixes PR classpath/24642
	* NEWS: add note about SecureRandom changes, and addition of
	VMSecureRandom.
	* java/security/SecureRandom.java (isSeeded): new field.
	(setSeed, setSeed): set `isSeeded' to `true.'
	(nextBytes): seed this instance if `isSeeded' is false.
	(getSeed): call `generateSeed.'
	(SECURERANDOM_SOURCE, JAVA_SECURITY_EGD, logger): new constants.
	(generateSeed, generateSeed): new methods.
	* vm/reference/java/security/VMSecureRandom.java: new file.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/classpath/classpath/ChangeLog.diff?tr1=1.7110&tr2=1.7111&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/classpath/classpath/NEWS.diff?tr1=1.131&tr2=1.132&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/classpath/classpath/java/security/SecureRandom.java.diff?tr1=1.21&tr2=1.22&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/classpath/classpath/vm/reference/java/security/VMSecureRandom.java?rev=1.1



Comment 6 Casey Marshall 2006-04-14 20:01:36 UTC
Fixed in CVS.