diff options
Diffstat (limited to 'src/pkg/crypto/rand/rand_unix.go')
-rw-r--r-- | src/pkg/crypto/rand/rand_unix.go | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/pkg/crypto/rand/rand_unix.go b/src/pkg/crypto/rand/rand_unix.go index 3a06aa8b1..5eb4cda2b 100644 --- a/src/pkg/crypto/rand/rand_unix.go +++ b/src/pkg/crypto/rand/rand_unix.go @@ -2,6 +2,8 @@ // 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 + // Unix cryptographically secure pseudorandom number // generator. @@ -10,6 +12,7 @@ package rand import ( "bufio" "crypto/aes" + "crypto/cipher" "io" "os" "sync" @@ -28,7 +31,7 @@ type devReader struct { mu sync.Mutex } -func (r *devReader) Read(b []byte) (n int, err os.Error) { +func (r *devReader) Read(b []byte) (n int, err error) { r.mu.Lock() defer r.mu.Unlock() if r.f == nil { @@ -64,12 +67,12 @@ func newReader(entropy io.Reader) io.Reader { type reader struct { mu sync.Mutex budget int // number of bytes that can be generated - cipher *aes.Cipher + cipher cipher.Block entropy io.Reader time, seed, dst, key [aes.BlockSize]byte } -func (r *reader) Read(b []byte) (n int, err os.Error) { +func (r *reader) Read(b []byte) (n int, err error) { r.mu.Lock() defer r.mu.Unlock() n = len(b) @@ -98,7 +101,7 @@ func (r *reader) Read(b []byte) (n int, err os.Error) { // t = encrypt(time) // dst = encrypt(t^seed) // seed = encrypt(t^dst) - ns := time.Nanoseconds() + ns := time.Now().UnixNano() r.time[0] = byte(ns >> 56) r.time[1] = byte(ns >> 48) r.time[2] = byte(ns >> 40) |