[all-commits] [llvm/llvm-project] d202c7: [libc++] Start using `arc4random()` to implement `...

Louis Dionne via All-commits all-commits at lists.llvm.org
Wed Jan 12 08:24:36 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: d202c76441e114f933057492f4bf15aa0d444867
      https://github.com/llvm/llvm-project/commit/d202c76441e114f933057492f4bf15aa0d444867
  Author: Louis Dionne <ldionne.2 at gmail.com>
  Date:   2022-01-12 (Wed, 12 Jan 2022)

  Changed paths:
    M libcxx/docs/ReleaseNotes.rst
    M libcxx/include/__config
    M libcxx/include/__random/random_device.h
    M libcxx/src/random.cpp
    M libcxx/test/std/numerics/rand/rand.device/ctor.pass.cpp
    M libcxx/test/std/numerics/rand/rand.device/eval.pass.cpp

  Log Message:
  -----------
  [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




More information about the All-commits mailing list