]> Cypherpunks repositories - gostls13.git/commit
crypto/rand: batch and buffer calls to getrandom/getentropy
authorJason A. Donenfeld <Jason@zx2c4.com>
Fri, 10 Dec 2021 16:23:08 +0000 (17:23 +0100)
committerGopher Robot <gobot@golang.org>
Tue, 19 Apr 2022 22:44:58 +0000 (22:44 +0000)
commitd68a8d0f27bb3599b49cacd119d7ac3202248050
treef90a6e4dbf765217913e339223bcb29b09a23617
parente858c14f916d424b33ad7e2450895b3117a5f727
crypto/rand: batch and buffer calls to getrandom/getentropy

We're using bufio to batch reads of /dev/urandom to 4k, but we weren't
doing the same on newer platforms with getrandom/getentropy. Since the
overhead is the same for these -- one syscall -- we should batch reads
of these into the same 4k buffer. While we're at it, we can simplify a
lot of the constant dispersal.

This also adds a new test case to make sure the buffering works as
desired.

Change-Id: I7297d4aa795c00712e6484b841cef8650c2be4ef
Reviewed-on: https://go-review.googlesource.com/c/go/+/370894
Reviewed-by: Filippo Valsorda <valsorda@google.com>
Run-TryBot: Jason Donenfeld <Jason@zx2c4.com>
Auto-Submit: Jason Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
src/crypto/rand/rand_batched_test.go
src/crypto/rand/rand_dragonfly.go [deleted file]
src/crypto/rand/rand_freebsd.go [deleted file]
src/crypto/rand/rand_getentropy.go
src/crypto/rand/rand_getrandom.go [moved from src/crypto/rand/rand_batched.go with 56% similarity]
src/crypto/rand/rand_linux.go [deleted file]
src/crypto/rand/rand_solaris.go [deleted file]
src/crypto/rand/rand_unix.go