/* Initialize RNG with some real entropy from some external source */ public virtual void seed(int rawlen, sbyte[] raw) { // initialise from at least 128 byte string of raw random entropy int i; sbyte[] digest; sbyte[] b = new sbyte[4]; HASH sh = new HASH(); pool_ptr = 0; for (i = 0; i < NK; i++) { ira[i] = 0; } if (rawlen > 0) { for (i = 0; i < rawlen; i++) { sh.process(raw[i]); } digest = sh.hash(); /* initialise PRNG from distilled randomness */ for (i = 0; i < 8; i++) { b[0] = digest[4 * i]; b[1] = digest[4 * i + 1]; b[2] = digest[4 * i + 2]; b[3] = digest[4 * i + 3]; sirand(pack(b)); } } fill_pool(); }
private void fill_pool() { HASH sh = new HASH(); for (int i = 0; i < 128; i++) { sh.process(sbrand()); } pool = sh.hash(); pool_ptr = 0; }