/* Initialize this random subsystem. If FULL is false, this function merely calls the basic initialization of the module and does not do anything more. Doing this is not really required but when running in a threaded environment we might get a race condition otherwise. */ void _gcry_random_initialize (int full) { static int nonce_initialized; int err; if (!nonce_initialized) { nonce_initialized = 1; err = ath_mutex_init (&nonce_buffer_lock); if (err) log_fatal ("failed to create the nonce buffer lock: %s\n", strerror (err) ); } if (fips_mode ()) _gcry_rngfips_initialize (full); else if (rng_types.standard) _gcry_rngcsprng_initialize (full); else if (rng_types.fips) _gcry_rngfips_initialize (full); else if (rng_types.system) _gcry_rngsystem_initialize (full); else _gcry_rngcsprng_initialize (full); }
/* Public function to fill the buffer with LENGTH bytes of cryptographically strong random bytes. Level GCRY_WEAK_RANDOM is here mapped to GCRY_STRONG_RANDOM, GCRY_STRONG_RANDOM is strong enough for most usage, GCRY_VERY_STRONG_RANDOM is good for key generation stuff but may be very slow. */ void _gcry_rngsystem_randomize (void *buffer, size_t length, enum gcry_random_level level) { _gcry_rngsystem_initialize (1); /* Auto-initialize if needed. */ if (level != GCRY_VERY_STRONG_RANDOM) level = GCRY_STRONG_RANDOM; lock_rng (); get_random (buffer, length, level); unlock_rng (); }
/* Initialize this random subsystem. If FULL is false, this function merely calls the basic initialization of the module and does not do anything more. Doing this is not really required but when running in a threaded environment we might get a race condition otherwise. */ void _gcry_random_initialize (int full) { if (fips_mode ()) _gcry_rngfips_initialize (full); else if (rng_types.standard) _gcry_rngcsprng_initialize (full); else if (rng_types.fips) _gcry_rngfips_initialize (full); else if (rng_types.system) _gcry_rngsystem_initialize (full); else _gcry_rngcsprng_initialize (full); }