diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2016-10-18 16:28:23 +0300 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2016-10-18 16:28:23 +0300 |
commit | faae1c918e8aaae034eaf3ea103fcb6ba9adc5ab (patch) | |
tree | 4d2739ac51be02b6701d9d9c14e7e1058f8d5fe0 /contrib/pgcrypto/internal.c | |
parent | 7d3235ba42f8d5fc70c58e242702cc5e2e3549a6 (diff) | |
download | postgresql-faae1c918e8aaae034eaf3ea103fcb6ba9adc5ab.tar.gz postgresql-faae1c918e8aaae034eaf3ea103fcb6ba9adc5ab.zip |
Revert "Replace PostmasterRandom() with a stronger way of generating randomness."
This reverts commit 9e083fd4683294f41544e6d0d72f6e258ff3a77c. 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.
Diffstat (limited to 'contrib/pgcrypto/internal.c')
-rw-r--r-- | contrib/pgcrypto/internal.c | 40 |
1 files changed, 16 insertions, 24 deletions
diff --git a/contrib/pgcrypto/internal.c b/contrib/pgcrypto/internal.c index ad942f733a2..02ff976c25a 100644 --- a/contrib/pgcrypto/internal.c +++ b/contrib/pgcrypto/internal.c @@ -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)); - } - 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]; - - 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)); - - seed_time = t; - px_memset(buf, 0, sizeof(buf)); + px_get_random_bytes(buf, 1); + skip = buf[0] >= SYSTEM_RESEED_CHANCE; } + /* clear 1 byte */ + px_memset(buf, 0, sizeof(buf)); + + if (skip) + return; + + n = px_acquire_system_randomness(buf); + if (n > 0) + fortuna_add_entropy(buf, n); + + seed_time = t; + px_memset(buf, 0, sizeof(buf)); } int |