@Override protected void engineNextBytes(byte[] bytes) { if (!mSeeded) { // Mix in the device- and invocation-specific seed. engineSetSeed(generateSeed()); } try { DataInputStream in; synchronized (sLock) { in = getUrandomInputStream(); } synchronized (in) { in.readFully(bytes); } } catch (IOException e) { throw new SecurityException("Failed to read from " + URANDOM_FILE, e); } }
@Override protected void engineSetSeed(byte[] bytes) { OutputStream out=null; try { synchronized (sLock) { out = getUrandomOutputStream(); } out.write(bytes); out.flush(); } catch (IOException e) { // On a small fraction of devices /dev/urandom is not // writable Log and ignore. Logger.getLogger(PrngFixes.class.getSimpleName()).warning( "Failed to mix seed into " + URANDOM_FILE); } finally { mSeeded = true; if (out!=null) try{ out.close();}catch (Exception ex){} } }
@Override protected byte[] engineGenerateSeed(int size) { byte[] seed = new byte[size]; engineNextBytes(seed); return seed; }