[Webfunds-commits] java/webfunds/utils SecureRandomHack.java
Jeroen C. van Gelderen
gelderen@cypherpunks.ai
Wed, 31 May 2000 21:03:35 -0400 (AST)
gelderen 00/05/31 21:03:35
Modified: webfunds/utils SecureRandomHack.java
Log:
My approach didn't work, we can only return quickly initialized
SecureRandom instances so do so now.
Revision Changes Path
1.2 +10 -35 java/webfunds/utils/SecureRandomHack.java
Index: SecureRandomHack.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/utils/SecureRandomHack.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SecureRandomHack.java 2000/06/01 00:31:19 1.1
+++ SecureRandomHack.java 2000/06/01 01:03:35 1.2
@@ -1,4 +1,4 @@
-/* $Id: SecureRandomHack.java,v 1.1 2000/06/01 00:31:19 gelderen Exp $
+/* $Id: SecureRandomHack.java,v 1.2 2000/06/01 01:03:35 gelderen Exp $
*
* Copyright (c) 2000 Systemics Inc. on behalf of
* The WebFunds Development Team. All rights reserved.
@@ -22,7 +22,7 @@
* This will only improve speed on UN*X, Windows and Mac don't have
* a /dev/random nor something equivalent.
*
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
* @author Jeroen C. van Gelderen (gelderen@systemics.com)
*/
public final class SecureRandomHack
@@ -39,30 +39,18 @@
private SecureRandomHack() {}
- /**
- * Initialize the SecureRandom PRNG as quickly as possible so that
- * future invocations of the SecureRandom ctor complete quickly.
- *
- * This method should be called before any SecureRandom ctor is
- * called and will block until a seed has been generated.
+ /**
+ * Get a SecureRandom object that has been initialized a quickly as
+ * possible. On Mac and Windows this uses the default SecureRandom
+ * emtpy constructor but on UNIX it quickly initialized from /dev/random.
*/
- public static void initialize()
+ public static SecureRandom getInstance()
{
byte[] seed = getSeedFast();
- if( seed == null )
- {
- System.out.println("got it slow...");
- seed = getSeedSlow();
- }
+ if( seed != null )
+ return new SecureRandom(seed);
else
- {
- System.out.println("got it fast");
- }
-
- // Initialize PRNG and request some random bytes to
- // thwart lazy initialization on some JDKs.
- SecureRandom dummy = new SecureRandom(seed);
- dummy.nextBytes(seed);
+ return new SecureRandom();
}
@@ -96,18 +84,5 @@
System.out.println("Ignoring exception: " + e);
return null;
}
- }
-
-
- /**
- * Obtain a seed trough Sun's SecureRandom implementation which is very
- * slow and potentially not very secure. It's all Windows and Mac users
- * are gonna get however.
- *
- * @return 20-byte seed
- */
- private static byte[] getSeedSlow()
- {
- return SecureRandom.getSeed(SEED_LEN);
}
}