Support getrandom() for pg_strong_random() source - Mailing list pgsql-hackers

From Masahiko Sawada
Subject Support getrandom() for pg_strong_random() source
Date
Msg-id CAD21AoAjb2TP+Uj-fOr7s1cjv2Eq65BaUYi8xNMumcAXiYFM9Q@mail.gmail.com
Whole thread Raw
Responses Re: Support getrandom() for pg_strong_random() source
List pgsql-hackers
Hi all,

Currently we have three options for pg_strong_random() sources:

1. OpenSSL's RAND_bytes()
2. Windows' CryptGenRandom() function
3. /dev/urandom

The patch supports the getrandom() function as a new source of
pg_strong_random(). The getrandom() function uses the same source as
the /dev/urandom device but it seems much faster than opening,
reading, and closing /dev/urandom. Here is the execution time of
generating 1 million UUIDv4 data measured on my environment:

HEAD(/dev/urandom): 1863.064 ms
Patched(getrandom()): 516.627 ms

I guess that while OpenSSL's RAND_bytes() should still be prioritized
where available it might be a good idea to support getrandom() for
builds where RAND_bytes() is not available.

Feedback is very welcome.

Regards,

-- 
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com

Attachment

pgsql-hackers by date:

Previous
From: Amit Langote
Date:
Subject: Re: generic plans and "initial" pruning
Next
From: Vik Fearing
Date:
Subject: Re: CAST(... ON DEFAULT) - WIP build on top of Error-Safe User Functions