]> Cypherpunks repositories - gostls13.git/commitdiff
crypto/rand: Added read buffer to speed up requests for small amounts of bytes.
authorAlbert Strasheim <fullung@gmail.com>
Thu, 17 Feb 2011 20:14:41 +0000 (15:14 -0500)
committerAdam Langley <agl@golang.org>
Thu, 17 Feb 2011 20:14:41 +0000 (15:14 -0500)
R=agl1, rsc
CC=golang-dev
https://golang.org/cl/4170056

src/pkg/crypto/rand/rand_unix.go

index 900b57330571ad28ef7b34fb45b49ccbd45e8dd0..66b72c07662f78915d3dd0b0d96f26c5883b7dcf 100644 (file)
@@ -8,6 +8,7 @@
 package rand
 
 import (
+       "bufio"
        "crypto/aes"
        "io"
        "os"
@@ -23,7 +24,7 @@ func init() { Reader = &devReader{name: "/dev/urandom"} }
 // A devReader satisfies reads by reading the file named name.
 type devReader struct {
        name string
-       f    *os.File
+       f    io.Reader
        mu   sync.Mutex
 }
 
@@ -35,7 +36,7 @@ func (r *devReader) Read(b []byte) (n int, err os.Error) {
                if f == nil {
                        return 0, err
                }
-               r.f = f
+               r.f = bufio.NewReader(f)
        }
        return r.f.Read(b)
 }