Пример #1
0
/* Fill BUFFER with LENGTH bytes of random at quality LEVEL.  The
   function either succeeds or terminates the process in case of a
   fatal error. */
static void
get_random (void *buffer, size_t length, int level)
{
    int rc;

    gcry_assert (buffer);

    read_cb_buffer = buffer;
    read_cb_size   = length;
    read_cb_len    = 0;

#if USE_RNDLINUX
    rc = _gcry_rndlinux_gather_random (read_cb, 0, length, level);
#elif USE_RNDUNIX
    rc = _gcry_rndunix_gather_random (read_cb, 0, length, level);
#elif USE_RNDW32
    do
    {
        rc = _gcry_rndw32_gather_random (read_cb, 0, length, level);
    }
    while (rc >= 0 && read_cb_len < read_cb_size);
#else
    rc = -1;
#endif

    if (rc < 0 || read_cb_len != read_cb_size)
    {
        log_fatal ("error reading random from system RNG (rc=%d)\n", rc);
    }
}
Пример #2
0
/* Try to close the FDs of the random gather module.  This is
   currently only implemented for rndlinux. */
void
_gcry_rngsystem_close_fds (void)
{
  lock_rng ();
#if USE_RNDLINUX
  _gcry_rndlinux_gather_random (NULL, 0, 0, 0);
#endif
  unlock_rng ();
}
Пример #3
0
/* Try to close the FDs of the random gather module.  This is
   currently only implemented for rndlinux. */
void
_gcry_rngcsprng_close_fds (void)
{
  lock_pool ();
#if USE_RNDLINUX
  _gcry_rndlinux_gather_random (NULL, 0, 0, 0);
  pool_filled = 0; /* Force re-open on next use.  */
#endif
  unlock_pool ();
}