6705872: SecureRandom number init is taking too long on a java.io.tmpdir with a large number of files.
# HG changeset patch
# User weijun
# Date 1235886391 -28800
# Node ID b4fb73e7050eb0f5a114431b55caaf066a7ddd38
# Parent 7cbd7c9721a17e7b7cf001e9560ec6b53941a8d1
6705872: SecureRandom number init is taking too long on a java.io.tmpdir with a large number of files.
Reviewed-by: nobody
--- a/src/share/classes/sun/security/provider/SeedGenerator.java Sun Mar 01 13:46:30 2009 +0800
+++ b/src/share/classes/sun/security/provider/SeedGenerator.java Sun Mar 01 13:46:31 2009 +0800
@@ -179,11 +179,24 @@
(InetAddress.getLocalHost().toString().getBytes());
// The temporary dir
- File f = new File(p.getProperty("java.io.tmpdir"));
- String[] sa = f.list();
- for(int i = 0; i < sa.length; i++)
- md.update(sa[i].getBytes());
-
+ try {
+ java.security.SecureRandom sr =
+ java.security.SecureRandom.getInstance("Windows-PRNG", "SunMSCAPI");
+ byte[] bytes = new byte[128];
+ sr.nextBytes(bytes);
+ md.update(bytes);
+ if (debug != null) {
+ debug.println("getSystemEntropy from MSCAPI");
+ }
+ } catch (Exception e2) {
+ File f = new File(p.getProperty("java.io.tmpdir"));
+ String[] sa = f.list();
+ for(int i = 0; i < sa.length; i++)
+ md.update(sa[i].getBytes());
+ if (debug != null) {
+ debug.println("getSystemEntropy from local fs");
+ }
+ }
} catch (Exception ex) {
md.update((byte)ex.hashCode());
}