Example #1
0
static int
arc4_seed(void)
{
	int ok = 0;
	/* We try every method that might work, and don't give up even if one
	 * does seem to work.  There's no real harm in over-seeding, and if
	 * one of these sources turns out to be broken, that would be bad. */
#ifdef TRY_SEED_WIN32
	if (0 == arc4_seed_win32())
		ok = 1;
#endif
#ifdef TRY_SEED_URANDOM
	if (0 == arc4_seed_urandom())
		ok = 1;
#endif
#ifdef TRY_SEED_PROC_SYS_KERNEL_RANDOM_UUID
	if (0 == arc4_seed_proc_sys_kernel_random_uuid())
		ok = 1;
#endif
#ifdef TRY_SEED_SYSCTL_LINUX
	/* Apparently Linux is deprecating sysctl, and spewing warning
	 * messages when you try to use it. */
	if (!ok && 0 == arc4_seed_sysctl_linux())
		ok = 1;
#endif
#ifdef TRY_SEED_SYSCTL_BSD
	if (0 == arc4_seed_sysctl_bsd())
		ok = 1;
#endif
	return ok ? 0 : -1;
}
Example #2
0
static void arc4_seed( void )
{
   int ok = 0;

   /*
    * We try every method that might work, and don't give up even if one
    * does seem to work. There's no real harm in over-seeding, and if
    * one of these sources turns out to be broken, that would be bad.
    */

#if defined( TRY_SEED_MS_CRYPTOAPI )
   if( arc4_seed_win() == 0 )
      ok = 1;
#endif

#if defined( TRY_SEED_URANDOM )
   if( arc4_seed_urandom() == 0 )
      ok = 1;
#endif

#if defined( TRY_SEED_PROC_SYS_KERNEL_RANDOM_UUID )
   if( arc4_seed_proc_sys_kernel_random_uuid() == 0 )
      ok = 1;
#endif

#if defined( TRY_SEED_SYSCTL_LINUX )
   /*
    * Apparently Linux is deprecating sysctl, and spewing warning
    * messages when you try to use it. To avoid dmesg spamming,
    * only try this if no previous method worked.
    */
   if( ! ok && arc4_seed_sysctl_linux() == 0 )
      ok = 1;
#endif

#if defined( TRY_SEED_SYSCTL_BSD )
   if( arc4_seed_sysctl_bsd() == 0 )
      ok = 1;
#endif

   /*
    * If nothing else worked or there is no specific seeding
    * method for the current platform, fall back to rand().
    * In case an existing platform-specific method had a
    * (transient) failure, it will be re-tried at the next
    * seeding cycle.
    */
   if( ! ok )
      arc4_seed_rand();
}