]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Implement std::random_device::entropy() for other sources
authorJonathan Wakely <jwakely@redhat.com>
Tue, 19 Oct 2021 11:31:06 +0000 (12:31 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Tue, 19 Oct 2021 16:27:06 +0000 (17:27 +0100)
commit58f339fc5eaae7db9526f81ab91f282ad4a9b8cc
tree3c6974aae38d7c6d988ac5625bc143db6147405d
parent3cfbe5dc08b574bccc398256946cc03e2a767329
libstdc++: Implement std::random_device::entropy() for other sources

Currently this function only returns a non-zero value for /dev/random
and /dev/urandom. When a hardware instruction such as RDRAND is in use
it should (in theory) be perfectly random and produce 32 bits of entropy
in each 32-bit result. Add a helper function to identify the source of
randomness from the _M_func and _M_file data members, and return a
suitable value when RDRAND or RDSEED is being used.

libstdc++-v3/ChangeLog:

* src/c++11/random.cc (which_source): New helper function.
(random_device::_M_getentropy()): Use which_source and return
suitable values for sources other than device files.
* testsuite/26_numerics/random/random_device/entropy.cc: New test.
libstdc++-v3/src/c++11/random.cc
libstdc++-v3/testsuite/26_numerics/random/random_device/entropy.cc [new file with mode: 0644]