struct randread_source *
randread_new (char const *name, size_t bytes_bound)
{
  if (bytes_bound == 0)
    return simple_new (NULL, NULL);
  else
    {
      FILE *source = NULL;
      struct randread_source *s;

      if (name)
        if (! (source = fopen_safer (name, "rb")))
          return NULL;

      s = simple_new (source, name);

      if (source)
        setvbuf (source, s->buf.c, _IOFBF, MIN (sizeof s->buf.c, bytes_bound));
      else
        {
          s->buf.isaac.buffered = 0;
          get_nonce (s->buf.isaac.state.m, sizeof s->buf.isaac.state.m,
                     bytes_bound);
          isaac_seed (&s->buf.isaac.state);
        }

      return s;
    }
}
Example #2
0
int
main (int argc, char **argv)
{
  unsigned int i;
  isaac_word r[ISAAC_WORDS];
  int iterations;

  /* Seed with zeros, and discard the first buffer of output,
     as that's what the standard programs do.  */
  static struct isaac_state s;
  isaac_seed (&s);
  isaac_refill (&s, r);

  for (i = 0; i < sizeof expected / sizeof expected[0]; i++)
    {
      isaac_refill (&s, r);
      ASSERT (memcmp (r, expected[i], sizeof r) == 0);
    }

  /* If invoked with a positive argument, run a benchmark;
     if with a negative, run a do-nothing benchmark.  */
  for (iterations = argc <= 1 ? 0 : strtol (argv[1], NULL, 10);
       iterations != 0;
       iterations += (iterations < 0 ? 1 : -1))
    if (0 <= iterations)
      isaac_refill (&s, r);

  return 0;
}
Example #3
0
extern "C" CDECL rust_vec*
rand_seed() {
    size_t size = sizeof(ub4) * RANDSIZ;
    rust_task *task = rust_get_current_task();
    rust_vec *v = (rust_vec *) task->kernel->malloc(vec_size<uint8_t>(size),
                                            "rand_seed");
    v->fill = v->alloc = size;
    isaac_seed(task->kernel, (uint8_t*) &v->data);
    return v;
}