Replace PostmasterRandom() with a stronger way of generating randomness.

Heikki Linnakangas <heikki.linnakangas@iki.fi>

Commit: 9e083fd4683294f41544e6d0d72f6e258ff3a77c
Author: Heikki Linnakangas <heikki.linnakangas@iki.fi>
Date: 2016-10-17T08:52:50Z
Releases: 10.0
Replace PostmasterRandom() with a stronger way of generating randomness.

This adds a new routine, pg_strong_random() for generating random bytes,
for use in both frontend and backend. At the moment, it's only used in
the backend, but the upcoming SCRAM authentication patches need strong
random numbers in libpq as well.

pg_strong_random() is based on, and replaces, the existing implementation
in pgcrypto. It can acquire strong random numbers from a number of sources,
depending on what's available:
- OpenSSL RAND_bytes(), if built with OpenSSL
- On Windows, the native cryptographic functions are used
- /dev/urandom
- /dev/random

Original patch by Magnus Hagander, with further work by Michael Paquier
and me.

Discussion: <CAB7nPqRy3krN8quR9XujMVVHYtXJ0_60nqgVc6oUk8ygyVkZsA@mail.gmail.com>

Files

PathChange+/−
contrib/pgcrypto/internal.c modified +24 −16
contrib/pgcrypto/Makefile modified +1 −1
contrib/pgcrypto/random.c deleted +0 −247
src/backend/libpq/auth.c modified +23 −4
src/backend/postmaster/postmaster.c modified +41 −112
src/include/port.h modified +3 −0
src/port/Makefile modified +1 −1
src/port/pg_strong_random.c added +148 −0
src/tools/msvc/Mkvcbuild.pm modified +3 −3