[pgpool-hackers: 4593] Re: Shuffle random functions and use better random numbers
Martijn van Duren
pgpool at list.imperialat.at
Thu May 15 00:26:53 JST 2025
On Mon, 2025-05-12 at 10:51 +0900, Tatsuo Ishii wrote:
> > Hello all,
> >
> > After my previous string diff, this is the final linker warning on
> > OpenBSD:
> > ld: warning: pool_pg_utils.c(protocol/pool_pg_utils.o:(select_load_balancing_node)): warning: random() may return deterministic values, is that what you want?
> >
> > Fumbling around in cryptography/random numbers is never a good idea,
> > unless you know what you're doing.
>
> > So I fully expect this diff to be
> > just a conversation starter.
>
> Thanks for the patches. After reading them. I visited PostgreSQL
> source code and found followings.
>
> - Our PostmasterRandmon() was imported from PostgreSQL long time ago
> (2016). In the same year PostgreSQL replaced PostmasterRandmon()
> with pg_strong_random().(src/port/pg_strong_random.c.
> pg_strong_random() looks better than PostmasterRandmon(), since it's
> more secure and portable. Moreover no initialization is necessary.
>
> - PostgreSQL introduced Pseudo-Random Number Generator in 2021
> (src/common/pg_prng.c). In the commet:
>
> * Pseudo-Random Number Generator
> *
> * We use Blackman and Vigna's xoroshiro128** 1.0 algorithm
> * to have a small, fast PRNG suitable for generating reasonably
> * good-quality 64-bit data. This should not be considered
> * cryptographically strong, however.
> *
> * About these generators: https://prng.di.unimi.it/
> * See also https://en.wikipedia.org/wiki/List_of_random_number_generators
>
> This is used for SQL functions in PostgreSQL. Looks pretty portable
> and maybe faster than standard random() function in some
> platforms. One bonus is, your select_rand_weight() is already
> implemneted in it: pg_prng_double().
>
> Probably we should import pg_strong_random.c and pg_prng.c, then
> change pgpool to use pg_strong_random() for generating salts,
> pg_prng_double() for generating random number between 0 and 1.0.
>
> What do you think?
I'm definitely not opposed to this approach. I've given a shot at
importing these two files, but there's quite a bit of postgres
specifics in there. I could probably make it work, but it'll probably
be in such a convoluted way that it's going to need a full rewrite
anyway.
Some nitpicking could be done over some of the internals, but I
don't mind this color bikeshed.
> --
> Tatsuo Ishii
> SRA OSS K.K.
> English: http://www.sraoss.co.jp/index_en/
> Japanese:http://www.sraoss.co.jp
More information about the pgpool-hackers
mailing list