Only perform pg_strong_random init when required
authorDaniel Gustafsson <dgustafsson@postgresql.org>
Mon, 2 Sep 2024 11:52:27 +0000 (13:52 +0200)
committerDaniel Gustafsson <dgustafsson@postgresql.org>
Mon, 2 Sep 2024 11:52:27 +0000 (13:52 +0200)
commitc3333dbc0c0f53452abfccf6c2dd5a86728a19dc
tree3eb2c8a63ae7f3a2e43eaeb6c52e8058df8795b4
parenta70e01d4306fdbcd5fbedb4ca97e5c21c995da60
Only perform pg_strong_random init when required

The random number generator in OpenSSL 1.1.1 was redesigned to provide
fork safety by default, thus removing the need for calling RAND_poll
after forking to ensure that two processes cannot share the same state.
Since we now support 1.1.0 as the minumum version, and 1.1.0 is being
increasingly phased out from production use, only perform the RAND_poll
initialization for installations running 1.1.0 by checking the OpenSSL
version number.

LibreSSL changed random number generator when forking OpenSSL and has
provided fork safety since version 2.0.2.

This removes the overhead of initializing the RNG for strong random
for the vast majority of users for whom it is no longer required.

Reviewed-by: Jacob Champion <jacob.champion@enterprisedb.com>
Reviewed-by: Peter Eisentraut <peter@eisentraut.org>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/CA+hUKGKh7QrYzu=8yWEUJvXtMVm_CNWH1L_TLWCbZMwbi1XP2Q@mail.gmail.com
src/port/pg_strong_random.c