/** Unused, see AsyncFortunaStandalone */ public void fillBlock() { //long start = System.currentTimeMillis(); if (pool0Count >= MIN_POOL_SIZE && System.currentTimeMillis() - lastReseed > 100) { reseedCount++; //byte[] seed = new byte[0]; for (int i = 0; i < NUM_POOLS; i++) { if (reseedCount % (1 << i) == 0) { generator.addRandomBytes(pools[i].digest()); } } lastReseed = System.currentTimeMillis(); } generator.nextBytes(buffer); //long now = System.currentTimeMillis(); //long diff = now-lastRefill; //lastRefill = now; //long refillTime = now-start; //System.out.println("Refilling " + (++refillCount) + " after " + diff + " for the PRNG took " + refillTime); }
@Override public final void nextBytes(byte[] out, int offset, int length) { if (!seeded) throw new IllegalStateException("generator not seeded"); int count = 0; do { int amount = Math.min(LIMIT, length - count); super.nextBytes(out, offset+count, amount); count += amount; for (int i = 0; i < key.length; i += counter.length) { //fillBlock(); // inlined CryptixRijndael_Algorithm.blockEncrypt(counter, buffer, 0, 0, cryptixKey); incrementCounter(); int l = Math.min(key.length - i, 16);//cipher.currentBlockSize()); System.arraycopy(buffer, 0, key, i, l); } resetKey(); } while (count < length); //fillBlock(); // inlined CryptixRijndael_Algorithm.blockEncrypt(counter, buffer, 0, 0, cryptixKey); incrementCounter(); ndx = 0; }
private void doFill(byte buf[]) { //long start = System.currentTimeMillis(); if (pool0Count >= MIN_POOL_SIZE && System.currentTimeMillis() - lastReseed > 100) { reseedCount++; //byte[] seed = new byte[0]; for (int i = 0; i < NUM_POOLS; i++) { if (reseedCount % (1 << i) == 0) { generator.addRandomBytes(pools[i].digest()); } } lastReseed = System.currentTimeMillis(); } generator.nextBytes(buf); //long now = System.currentTimeMillis(); //long diff = now-lastRefill; //lastRefill = now; //long refillTime = now-start; //System.out.println("Refilling " + (++refillCount) + " after " + diff + " for the PRNG took " + refillTime); }
public void setup(Map<String, byte[]> attributes) { seeded = false; Arrays.fill(key, (byte) 0); Arrays.fill(counter, (byte) 0); byte[] seed = attributes.get(SEED); if (seed != null) addRandomBytes(seed); }
@Override public final void addRandomByte(byte b) { addRandomBytes(new byte[] { b }); }
public void setup(Map<String, byte[]> attributes) { lastReseed = 0; reseedCount = 0; pool = 0; pool0Count = 0; generator.init(attributes); }
public FortunaStandalone() { super("Fortuna i2p"); generator = new Generator(); pools = new MessageDigest[NUM_POOLS]; for (int i = 0; i < NUM_POOLS; i++) pools[i] = SHA256Generator.getDigestInstance(); lastReseed = 0; pool = 0; pool0Count = 0; allocBuffer(); }
private void writeObject(ObjectOutputStream out) throws IOException { byte[] seed = new byte[SEED_FILE_SIZE]; generator.nextBytes(seed); out.write(seed); }
public final void fillBlock() { ////i2p: this is not being checked as a microoptimization //if (!seeded) // throw new IllegalStateException("generator not seeded"); CryptixRijndael_Algorithm.blockEncrypt(counter, buffer, 0, 0, cryptixKey); incrementCounter(); }
@Override public final byte nextByte() { byte[] b = new byte[1]; nextBytes(b, 0, 1); return b[0]; }
private void readObject(ObjectInputStream in) throws IOException { byte[] seed = new byte[SEED_FILE_SIZE]; in.readFully(seed); generator.addRandomBytes(seed); }
@Override public final void addRandomBytes(byte[] seed, int offset, int length) { hash.update(key, 0, key.length); hash.update(seed, offset, length); byte[] newkey = hash.digest(); System.arraycopy(newkey, 0, key, 0, Math.min(key.length, newkey.length)); //hash.doFinal(key, 0); resetKey(); incrementCounter(); seeded = true; }