mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Fill siphash salt directly with random data
Expanding less random data with MT is not needed when it succeeded.
This commit is contained in:
parent
54e31f4a5f
commit
499de0a0f6
Notes:
git
2020-01-10 10:29:17 +09:00
1 changed files with 6 additions and 0 deletions
6
random.c
6
random.c
|
@ -454,6 +454,7 @@ ruby_fill_random_bytes(void *seed, size_t size, int need_secure)
|
||||||
|
|
||||||
#define fill_random_bytes ruby_fill_random_bytes
|
#define fill_random_bytes ruby_fill_random_bytes
|
||||||
|
|
||||||
|
/* cnt must be 4 or more */
|
||||||
static void
|
static void
|
||||||
fill_random_seed(uint32_t *seed, size_t cnt)
|
fill_random_seed(uint32_t *seed, size_t cnt)
|
||||||
{
|
{
|
||||||
|
@ -1466,7 +1467,12 @@ rb_memhash(const void *ptr, long len)
|
||||||
void
|
void
|
||||||
Init_RandomSeedCore(void)
|
Init_RandomSeedCore(void)
|
||||||
{
|
{
|
||||||
|
if (!fill_random_bytes(&hash_salt, sizeof(hash_salt), FALSE)) return;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
If failed to fill siphash's salt with random data, expand less random
|
||||||
|
data with MT.
|
||||||
|
|
||||||
Don't reuse this MT for Random::DEFAULT. Random::DEFAULT::seed shouldn't
|
Don't reuse this MT for Random::DEFAULT. Random::DEFAULT::seed shouldn't
|
||||||
provide a hint that an attacker guess siphash's seed.
|
provide a hint that an attacker guess siphash's seed.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Reference in a new issue