]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: don't use /dev/random on Plan 9
authorDavid du Colombier <0intro@gmail.com>
Sun, 1 Mar 2015 17:08:15 +0000 (18:08 +0100)
committerDavid du Colombier <0intro@gmail.com>
Sun, 1 Mar 2015 18:33:56 +0000 (18:33 +0000)
Plan 9 provides a /dev/random device to return a
stream of random numbers. However, the method used
to generate random numbers on Plan 9 is slow and
reading from /dev/random may block.

We don't want our Go programs to be significantly
slowed down just to slightly improve the distribution
of hash values.

So, we do the same thing as NaCl and rely exclusively
on extendRandom to generate pseudo-random numbers.

Fixes #10028.

Change-Id: I7e11a9b109c22f23608eb09c406b7c3dba31f26a
Reviewed-on: https://go-review.googlesource.com/6386
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/runtime/os1_plan9.go

index 61b0397249f0ad8cf9d98e25ee7ad8ad1fc3d59e..bba1f17e328dc7f92f981643f555468a6caa6721 100644 (file)
@@ -85,14 +85,9 @@ func crash() {
        *(*int)(nil) = 0
 }
 
-var random_dev = []byte("/dev/random\x00")
-
 //go:nosplit
 func getRandomData(r []byte) {
-       fd := open(&random_dev[0], 0 /* O_RDONLY */, 0)
-       n := read(fd, unsafe.Pointer(&r[0]), int32(len(r)))
-       close(fd)
-       extendRandom(r, int(n))
+       extendRandom(r, 0)
 }
 
 func goenvs() {