mirror of
https://github.com/golang/go
synced 2024-11-20 11:04:56 -07:00
crypto/rand: enable rand.Reader on plan9
R=golang-dev, rsc CC=golang-dev https://golang.org/cl/6297044
This commit is contained in:
parent
fe80cf0f15
commit
3476c23124
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user