示例#1
0
void pseudorand_init(void)
{
	unsigned char seedbuf[16];

	/* PRNG */
	if (RAND_bytes(seedbuf, sizeof(seedbuf)) != 1)
		errx(1, "Could not seed PRNG: %s",
		     ERR_error_string(ERR_get_error(), NULL));

	isaac64_init(&isaac64_initted, seedbuf, sizeof(seedbuf));
	/* We use a pointer so we will crash if unused before init */
	isaac64 = &isaac64_initted;
}
示例#2
0
static PyObject *
random_seed(RandomObject *self, PyObject *args)
{
    PyObject *arg = NULL;
    u8 seed[KEY_BYTES + IV_BYTES + 4];

    if (!PyArg_UnpackTuple(args, "seed", 0, 1, &arg))
        return NULL;

    if (extract_seed(arg, seed, sizeof(seed)) != 0) {
        return NULL;
    }

    isaac64_init(&self->context, seed, sizeof(seed));
    Py_INCREF(Py_None);
    return Py_None;
}
示例#3
0
文件: run64.c 项目: HSchroeder/ccan
int main(int _argc,const char *_argv[]){
  isaac64_ctx isaac64;
  int         i;
  int         j;

  /*This is how many tests you plan to run.*/
  plan_tests(2);
  isaac64_init(&isaac64,NULL,0);
  for(j=0;j<ISAAC64_SZ;j++)isaac64_next_uint64(&isaac64);
  for(i=0;i<2;i++){
    int nmatches;
    nmatches=0;
    for(j=0;j<ISAAC64_SZ;j++){
      nmatches+=isaac64_next_uint64(&isaac64)==STATEVEC64[(i+1)*ISAAC64_SZ-j-1];
    }
    ok1(nmatches==ISAAC64_SZ);
  }
  /*TODO: We should test the random float/double routines, but they are not
     guaranteed to return the same values on all platforms, because the number
     of bits in the mantissa may be different.
    Perhaps some simple statistical tests would suffice.*/
  return exit_status();
}