mirror of
https://github.com/postgres/postgres.git
synced 2025-07-31 22:04:40 +03:00
Revert "Replace PostmasterRandom() with a stronger way of generating randomness."
This reverts commit 9e083fd468
. That was a
few bricks shy of a load:
* Query cancel stopped working
* Buildfarm member pademelon stopped working, because the box doesn't have
/dev/urandom nor /dev/random.
This clearly needs some more discussion, and a quite different patch, so
revert for now.
This commit is contained in:
@ -626,6 +626,8 @@ static time_t check_time = 0;
|
||||
static void
|
||||
system_reseed(void)
|
||||
{
|
||||
uint8 buf[1024];
|
||||
int n;
|
||||
time_t t;
|
||||
int skip = 1;
|
||||
|
||||
@ -640,34 +642,24 @@ system_reseed(void)
|
||||
else if (check_time == 0 ||
|
||||
(t - check_time) > SYSTEM_RESEED_CHECK_TIME)
|
||||
{
|
||||
uint8 buf;
|
||||
|
||||
check_time = t;
|
||||
|
||||
/* roll dice */
|
||||
px_get_random_bytes(&buf, 1);
|
||||
skip = (buf >= SYSTEM_RESEED_CHANCE);
|
||||
|
||||
/* clear 1 byte */
|
||||
px_memset(&buf, 0, sizeof(buf));
|
||||
px_get_random_bytes(buf, 1);
|
||||
skip = buf[0] >= SYSTEM_RESEED_CHANCE;
|
||||
}
|
||||
if (!skip)
|
||||
{
|
||||
/*
|
||||
* fortuna_add_entropy passes the input to SHA-256, so there's no
|
||||
* point in giving it more than 256 bits of input to begin with.
|
||||
*/
|
||||
uint8 buf[32];
|
||||
/* clear 1 byte */
|
||||
px_memset(buf, 0, sizeof(buf));
|
||||
|
||||
if (!pg_strong_random(buf, sizeof(buf)))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INTERNAL_ERROR),
|
||||
errmsg("could not acquire random data")));
|
||||
fortuna_add_entropy(buf, sizeof(buf));
|
||||
if (skip)
|
||||
return;
|
||||
|
||||
seed_time = t;
|
||||
px_memset(buf, 0, sizeof(buf));
|
||||
}
|
||||
n = px_acquire_system_randomness(buf);
|
||||
if (n > 0)
|
||||
fortuna_add_entropy(buf, n);
|
||||
|
||||
seed_time = t;
|
||||
px_memset(buf, 0, sizeof(buf));
|
||||
}
|
||||
|
||||
int
|
||||
|
Reference in New Issue
Block a user