@Override public int acceptEntropy(EntropySource source, long data, int entropyGuess) { return acceptEntropy(source, data, entropyGuess, 1.0); }
@Override public int acceptTimerEntropy(EntropySource timer, double bias) { long now = System.currentTimeMillis(); return acceptEntropy(timer, now - timer.lastVal, 32, bias); }
protected void readStartupEntropy(EntropySource startupEntropy) { // Consume the current time acceptEntropy(startupEntropy, System.currentTimeMillis(), 0); acceptEntropy(startupEntropy, System.nanoTime(), 0); // Free memory acceptEntropy(startupEntropy, Runtime.getRuntime().freeMemory(), 0); // Total memory acceptEntropy(startupEntropy, Runtime.getRuntime().totalMemory(), 0); }
@Override public int acceptEntropyBytes(EntropySource source, byte[] buf, int offset, int length, double bias) { int totalRealEntropy = 0; for(int i = 0; i < length; i += 8) { long thingy = 0; int bytes = 0; for(int j = 0; j < Math.min(length, i + 8); j++) { thingy = (thingy << 8) + (buf[j] & 0xFF); bytes++; } totalRealEntropy += acceptEntropy(source, thingy, bytes * 8, bias); } return totalRealEntropy; }
/** * Seed handling */ private void read_seed(File filename) { FileInputStream fis = null; BufferedInputStream bis = null; DataInputStream dis = null; try { fis = new FileInputStream(filename); bis = new BufferedInputStream(fis); dis = new DataInputStream(bis); EntropySource seedFile = new EntropySource(); for(int i = 0; i < 32; i++) acceptEntropy(seedFile, dis.readLong(), 64); dis.close(); } catch(EOFException f) { // Okay. } catch(IOException e) { Logger.error(this, "IOE trying to read the seedfile from disk : " + e.getMessage()); } finally { Closer.close(dis); Closer.close(bis); Closer.close(fis); } fast_pool_reseed(); } private long timeLastWroteSeed = -1;
long start = System.currentTimeMillis(); for(int i = 0; i < 100000; i++) r.acceptEntropy(t, System.currentTimeMillis(), 32); System.err.println( (double) (System.currentTimeMillis() - start) / 100000);