mimalloc/src
Jim Huang c4947c8879 Use secure random generator on macOS
The implementation of arc4random_buf differs from its documentation. It
is documented as "always successful, and no return value is reserved to
indicate an error" for the sake of FreeBSD compatibility [1]. However,
the actual implementation on macOS invokes function "ccrng_generate" [2]
without validating the error cases. It might fail silently[3], which leads
to unexpected source of entropy.

The original arc4random used the RC4 a.k.a. ARC4 algorithm, and ChaCha20
based implementation was introduced in FreeBSD 12.0. Since macOS 10.12,
it was replaced with the NIST-approved AES cipher, and it may be replaced
again in the future as cryptographic techniques advance. Therefore, we
should not assume that arc4random never fails.

On the contrary, CCRandomGenerateBytes(), part of Cryptographic Services [4],
returns cryptographically strong random bits with explicit status code.
This patch properly calls CCRandomGenerateBytes() and checks the status.

[1] https://www.freebsd.org/cgi/man.cgi?query=arc4random_buf
[2] https://opensource.apple.com/source/CommonCrypto/CommonCrypto-60178.40.2/lib/CommonRandom.c.auto.html
[3] https://opensource.apple.com/source/Libc/Libc-1439.40.11/gen/FreeBSD/arc4random.c.auto.html
[4] https://developer.apple.com/documentation/security
2021-06-25 12:37:00 +08:00
..
alloc-aligned.c Revert "make all includes relative" 2021-06-07 16:47:57 -07:00
alloc-override-osx.c fixes for M1; disable interpose use zones; fix pedantic warnings 2021-06-17 19:15:09 -07:00
alloc-override.c fixes for M1; disable interpose use zones; fix pedantic warnings 2021-06-17 19:15:09 -07:00
alloc-posix.c Revert "make all includes relative" 2021-06-07 16:47:57 -07:00
alloc.c improve warnings 2021-06-07 17:51:27 -07:00
arena.c Revert "make all includes relative" 2021-06-07 16:47:57 -07:00
bitmap.c Revert "make all includes relative" 2021-06-07 16:47:57 -07:00
bitmap.h Bump copyright date 2021-04-24 16:35:11 +00:00
heap.c Revert "make all includes relative" 2021-06-07 16:47:57 -07:00
init.c Revert "make all includes relative" 2021-06-07 16:47:57 -07:00
options.c Revert "make all includes relative" 2021-06-07 16:47:57 -07:00
os.c fix for #414 making numa node count atomic 2021-06-17 19:38:51 -07:00
page-queue.c Bump copyright date 2021-04-24 16:35:11 +00:00
page.c Revert "make all includes relative" 2021-06-07 16:47:57 -07:00
random.c Use secure random generator on macOS 2021-06-25 12:37:00 +08:00
region.c Revert "make all includes relative" 2021-06-07 16:47:57 -07:00
segment.c Revert "make all includes relative" 2021-06-07 16:47:57 -07:00
static.c Revert "make all includes relative" 2021-06-07 16:47:57 -07:00
stats.c Revert "make all includes relative" 2021-06-07 16:47:57 -07:00