Changeset 896af2c
- Timestamp:
- Jun 25, 2016 10:20:27 PM (5 years ago)
- Branches:
- master
- Children:
- 3baa08a
- Parents:
- 2c3311b
- Location:
- core/java/src/net/i2p/util
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
core/java/src/net/i2p/util/FortunaRandomSource.java
r2c3311b r896af2c 14 14 import java.io.IOException; 15 15 import java.security.SecureRandom; 16 import java.util.Random; 16 17 17 18 import net.i2p.I2PAppContext; … … 41 42 } else { 42 43 // may block forever 43 SecureRandom sr = new SecureRandom(); 44 //SecureRandom sr = new SecureRandom(); 45 // SecureRandom already failed in initSeed(), so try Random 46 Random sr = new Random(); 44 47 sr.nextBytes(seed); 45 48 _fortuna.seed(seed); -
core/java/src/net/i2p/util/RandomSource.java
r2c3311b r896af2c 196 196 if (ok) 197 197 System.arraycopy(tbuf, 0, buf, 0, buf.length); 198 else 199 System.out.println("INFO: SecureRandom init failed or took too long"); 198 // See FortunaRandomSource constructor for fallback 199 //else 200 // System.out.println("INFO: SecureRandom init failed or took too long"); 200 201 } 201 202 } catch (InterruptedException ie) {} … … 219 220 private static class SecureRandomInit implements Runnable { 220 221 private final byte[] buf; 222 private static final int SZ = 64; 221 223 222 224 public SecureRandomInit(byte[] buf) { … … 225 227 226 228 public void run() { 227 byte[] buf2 = new byte[buf.length]; 229 byte[] buf2 = new byte[SZ]; 230 // do this 64 bytes at a time, so if system is low on entropy we will 231 // hopefully get something before the timeout 228 232 try { 229 SecureRandom.getInstance("SHA1PRNG").nextBytes(buf2); 230 synchronized(buf) { 231 System.arraycopy(buf2, 0, buf, 0, buf.length); 233 SecureRandom sr = SecureRandom.getInstance("SHA1PRNG"); 234 for (int i = 0; i < buf.length; i += SZ) { 235 sr.nextBytes(buf2); 236 synchronized(buf) { 237 System.arraycopy(buf2, 0, buf, i, Math.min(SZ, buf.length - i)); 238 } 232 239 } 233 240 } catch (NoSuchAlgorithmException e) {}
Note: See TracChangeset
for help on using the changeset viewer.