Commit 3476c231 authored by Markus Sonderegger's avatar Markus Sonderegger Committed by Russ Cox

crypto/rand: enable rand.Reader on plan9

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6297044
parent fe80cf0f
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build darwin freebsd linux netbsd openbsd
// +build darwin freebsd linux netbsd openbsd plan9
// Unix cryptographically secure pseudorandom number
// generator.
......@@ -15,6 +15,7 @@ import (
"crypto/cipher"
"io"
"os"
"runtime"
"sync"
"time"
)
......@@ -22,7 +23,13 @@ import (
// Easy implementation: read from /dev/urandom.
// This is sufficient on Linux, OS X, and FreeBSD.
func init() { Reader = &devReader{name: "/dev/urandom"} }
func init() {
if runtime.GOOS == "plan9" {
Reader = newReader(nil)
} else {
Reader = &devReader{name: "/dev/urandom"}
}
}
// A devReader satisfies reads by reading the file named name.
type devReader struct {
......@@ -39,14 +46,17 @@ func (r *devReader) Read(b []byte) (n int, err error) {
if f == nil {
return 0, err
}
r.f = bufio.NewReader(f)
if runtime.GOOS == "plan9" {
r.f = f
} else {
r.f = bufio.NewReader(f)
}
}
return r.f.Read(b)
}
// Alternate pseudo-random implementation for use on
// systems without a reliable /dev/urandom. So far we
// haven't needed it.
// systems without a reliable /dev/urandom.
// newReader returns a new pseudorandom generator that
// seeds itself by reading from entropy. If entropy == nil,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment