OSDN Git Service

2003-02-13 Casey Marshall <rsdio@metastatic.org>
authortromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 13 Feb 2003 17:00:22 +0000 (17:00 +0000)
committertromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 13 Feb 2003 17:00:22 +0000 (17:00 +0000)
PR libgcj/9271:
* java/security/SecureRandom.java (next): Avoid bias in results.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@62851 138bc75d-0d04-0410-961f-82ee72b054a4

libjava/ChangeLog
libjava/java/security/SecureRandom.java

index 15391fc..2f79625 100644 (file)
@@ -1,3 +1,8 @@
+2003-02-13  Casey Marshall  <rsdio@metastatic.org>
+
+       PR libgcj/9271:
+       * java/security/SecureRandom.java (next): Avoid bias in results.
+
 2003-02-13  Michael  <konqueror@gmx.de>
 
        * gnu/java/nio/FileChannelImpl.java
index a0b7f95..d9ac153 100644 (file)
@@ -1,5 +1,5 @@
 /* SecureRandom.java --- Secure Random class implmentation
-   Copyright (C) 1999, 2001, 2002 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2001, 2002, 2003 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -36,6 +36,7 @@ obligated to do so.  If you do not wish to do so, delete this
 exception statement from your version. */
 
 package java.security;
+
 import java.io.Serializable;
 import java.util.Random;
 import java.util.Enumeration;
@@ -358,9 +359,10 @@ public class SecureRandom extends Random
     int ret = 0;
 
     for (int i = 0; i < tmp.length; i++)
-      ret |= tmp[i] << (8 * i);
+      ret |= (tmp[i] & 0xFF) << (8 * i);
 
-    return ret;
+    long mask = (1L << numBits) - 1;
+    return (int) (ret & mask);
   }
 
   /**