[libc++] Start using `arc4random()` to implement `std::random_device` on Apple
authorLouis Dionne <ldionne.2@gmail.com>
Tue, 21 Dec 2021 16:49:04 +0000 (11:49 -0500)
committerLouis Dionne <ldionne.2@gmail.com>
Wed, 12 Jan 2022 16:24:23 +0000 (11:24 -0500)
commitd202c76441e114f933057492f4bf15aa0d444867
tree0beb041d289626fd01c44ee0837bbc803c0c166b
parent6db04b97e6a2873cbf1252b7b6b7efedf3fceb4e
[libc++] Start using `arc4random()` to implement `std::random_device` on Apple

On Apple platforms, arc4random is faster than /dev/urandom, and it is
the recommended user-space RNG according to Apple's own OS folks.

This commit adds an ABI switch to guard ABI-break-protections in
std::random_device, and starts using arc4random instead of /dev/urandom
to implement std::random_device on Apple platforms.

Note that previously, `std::random_device` would allow passing a custom
token to its constructor, and that token would be interpreted as the name
of a file to read entropy from. This was implementation-defined and
undocumented. After this change, Apple platforms will be using arc4random()
instead, and any custom token passed to the constructor will be ignored.
This behavioral change will also impact other platforms that use the
arc4random() implementation, such as OpenBSD. This should be fine since
that is effectively a relaxation of the constructor's requirements.

rdar://86638350

Differential Revision: https://reviews.llvm.org/D116045
libcxx/docs/ReleaseNotes.rst
libcxx/include/__config
libcxx/include/__random/random_device.h
libcxx/src/random.cpp
libcxx/test/std/numerics/rand/rand.device/ctor.pass.cpp
libcxx/test/std/numerics/rand/rand.device/eval.pass.cpp