int strong_rng(csprng *rng) { int r; r=rng->pool[rng->pool_ptr++]; if (rng->pool_ptr>=MR_HASH_BYTES) fill_pool(rng); return r; }
/* SU= 8 */ int RAND_byte(csprng *rng) { int r; r=rng->pool[rng->pool_ptr++]; if (rng->pool_ptr>=32) fill_pool(rng); return (r&0xff); }
/* Initialize RNG with some real entropy from some external source */ void MCL_RAND_seed(csprng *rng,int rawlen,char *raw) { /* initialise from at least 128 byte string of raw * * random (keyboard?) input, and 32-bit time-of-day */ int i; char digest[32]; uchar b[4]; mcl_hash256 sh; rng->pool_ptr=0; for (i=0;i<NK;i++) rng->ira[i]=0; if (rawlen>0) { MCL_HASH256_init(&sh); for (i=0;i<rawlen;i++) MCL_HASH256_process(&sh,raw[i]); MCL_HASH256_hash(&sh,digest); /* 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]; // printf("%08x\n",pack(b)); sirand(rng,pack(b)); } } fill_pool(rng); }
void fill_pool(file_pool_t pool, command_t c) { if(c->input) pool_add_read(pool, c->input); if(c->output) pool_add_write(pool, c->output); if(c->type == SIMPLE_COMMAND) { int count = 1; while( (c->u.word)[count] ) pool_add_read(pool, (c->u.word)[count++]); } else if(c->type == SUBSHELL_COMMAND) fill_pool(pool, c->u.subshell_command); else { fill_pool(pool, c->u.command[0]); fill_pool(pool, c->u.command[1]); } return; }
/* Initialize RNG with some real entropy from some external source */ void RAND_seed(csprng *rng, char *digest) { /* initialise from at least 128 byte string of raw * * random (keyboard?) input, and 32-bit time-of-day */ int i; uchar b[4]; rng->pool_ptr=0; for (i=0; i<NK; i++) rng->ira[i]=0; /* 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]; // printf("%08x\n",pack(b)); sirand(rng,pack(b)); } fill_pool(rng); }
void strong_init(csprng *rng,int rawlen,char *raw,mr_unsign32 tod) { /* initialise from at least 128 byte string of raw * * random (keyboard?) input, and 32-bit time-of-day */ int i; mr_unsign32 hash[MR_HASH_BYTES/4]; sha sh; rng->pool_ptr=0; for (i=0;i<NK;i++) rng->ira[i]=0; if (rawlen>0) { shs_init(&sh); for (i=0;i<rawlen;i++) shs_process(&sh,raw[i]); shs_hash(&sh,(char *)hash); /* initialise PRNG from distilled randomness */ for (i=0;i<MR_HASH_BYTES/4;i++) sirand(rng,hash[i]); } sirand(rng,tod); fill_pool(rng); }