[th/random-utils] glib-aux: rework random number utils
Heavily inspired by systemd ([1]).
We now also have nm_random_get_bytes{,_full}()
and
nm_random_get_crypto_bytes()
, like systemd's random_bytes()
and crypto_random_bytes()
, respectively.
Differences:
- instead of systemd's
random_bytes()
, ournm_random_get_bytes_full()
also estimates whether the output is of high quality. The caller may find that interesting. Due to that, we will first try to callgetrandom(GRND_NONBLOCK)
beforegetrandom(GRND_INSECURE)
. That is reversed from systemd'srandom_bytes()
, because we want to find out whether we can get good random numbers. In most cases, kernel should have entropy already, and it makes no difference.
Otherwise, heavily rework the code. It should be easy to understand and correct.