]> Cypherpunks repositories - gostls13.git/commit
crypto/rand: use arc4random(3) on macOS and iOS
authorFilippo Valsorda <filippo@golang.org>
Wed, 6 Mar 2024 23:18:02 +0000 (00:18 +0100)
committerGopher Robot <gobot@golang.org>
Tue, 19 Mar 2024 20:02:21 +0000 (20:02 +0000)
commit99522de1c38e4915e061cd2dac7d34ee888c8318
treeffa5113baa35d77f74e9f98d56a6f352b1cc0af8
parent8f7df2256e271c8d8d170791c6cd90ba9cc69f5e
crypto/rand: use arc4random(3) on macOS and iOS

It's been good since Sierra: it never fails, it's faster, it's available
on iOS (see #47812), and it still handles forks and reseeding.

On a M2 with macOS 14.3.1:

              │   sec/op    │   sec/op     vs base                │
    Read/32-8   413.7n ± 3%   249.7n ± 3%  -39.65% (p=0.000 n=10)
    Read/4K-8   7.097µ ± 6%   1.261µ ± 2%  -82.24% (p=0.000 n=10)

              │     B/s      │      B/s       vs base                 │
    Read/32-8   73.76Mi ± 3%   122.25Mi ± 3%   +65.73% (p=0.000 n=10)
    Read/4K-8   550.5Mi ± 6%   3099.0Mi ± 2%  +462.99% (p=0.000 n=10)

arc4random(3) would be a good replacement for getentropy(2) on FreeBSD
and NetBSD as well, but we don't get as easy access to libc there.

Cq-Include-Trybots: luci.golang.try:gotip-darwin-amd64-longtest,gotip-darwin-amd64-nocgo,gotip-darwin-arm64_13,gotip-darwin-amd64_11,gotip-darwin-amd64_12,gotip-darwin-amd64_13,gotip-darwin-amd64_14
Change-Id: Ia76824853be92b4d1786e23592a1d2ef24d8907d
Reviewed-on: https://go-review.googlesource.com/c/go/+/569655
Auto-Submit: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Reviewed-by: Roland Shoemaker <roland@golang.org>
Reviewed-by: Mauri de Souza Meneguzzo <mauri870@gmail.com>
src/crypto/rand/rand.go
src/crypto/rand/rand_darwin.go [new file with mode: 0644]
src/crypto/rand/rand_getentropy.go
src/crypto/rand/rand_test.go
src/internal/syscall/unix/arc4random_darwin.go [new file with mode: 0644]
src/internal/syscall/unix/asm_darwin.s
src/internal/syscall/unix/getentropy_darwin.go [deleted file]
src/internal/syscall/unix/getentropy_darwin.s [deleted file]