Remove possibility of using same seeds
This commit is contained in:
parent
1e827d4cb5
commit
c63552eab1
4
random.c
4
random.c
@ -583,7 +583,7 @@ ruby_fill_random_bytes(void *seed, size_t size, int need_secure)
|
|||||||
static void
|
static void
|
||||||
fill_random_seed(uint32_t *seed, size_t cnt)
|
fill_random_seed(uint32_t *seed, size_t cnt)
|
||||||
{
|
{
|
||||||
static int n = 0;
|
static rb_atomic_t n = 0;
|
||||||
#if defined HAVE_CLOCK_GETTIME
|
#if defined HAVE_CLOCK_GETTIME
|
||||||
struct timespec tv;
|
struct timespec tv;
|
||||||
#elif defined HAVE_GETTIMEOFDAY
|
#elif defined HAVE_GETTIMEOFDAY
|
||||||
@ -606,7 +606,7 @@ fill_random_seed(uint32_t *seed, size_t cnt)
|
|||||||
#if SIZEOF_TIME_T > SIZEOF_INT
|
#if SIZEOF_TIME_T > SIZEOF_INT
|
||||||
seed[0] ^= (uint32_t)((time_t)tv.tv_sec >> SIZEOF_INT * CHAR_BIT);
|
seed[0] ^= (uint32_t)((time_t)tv.tv_sec >> SIZEOF_INT * CHAR_BIT);
|
||||||
#endif
|
#endif
|
||||||
seed[2] ^= getpid() ^ (n++ << 16);
|
seed[2] ^= getpid() ^ (ATOMIC_FETCH_ADD(n, 1) << 16);
|
||||||
seed[3] ^= (uint32_t)(VALUE)&seed;
|
seed[3] ^= (uint32_t)(VALUE)&seed;
|
||||||
#if SIZEOF_VOIDP > SIZEOF_INT
|
#if SIZEOF_VOIDP > SIZEOF_INT
|
||||||
seed[2] ^= (uint32_t)((VALUE)&seed >> SIZEOF_INT * CHAR_BIT);
|
seed[2] ^= (uint32_t)((VALUE)&seed >> SIZEOF_INT * CHAR_BIT);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user