|
|
@@ -21,6 +21,7 @@ import (
|
|
|
type secureSource struct {
|
|
|
rd io.Reader
|
|
|
mut sync.Mutex
|
|
|
+ buf [8]byte
|
|
|
}
|
|
|
|
|
|
func newSecureSource() *secureSource {
|
|
|
@@ -47,18 +48,15 @@ func (s *secureSource) Read(p []byte) (int, error) {
|
|
|
}
|
|
|
|
|
|
func (s *secureSource) Uint64() uint64 {
|
|
|
- var buf [8]byte
|
|
|
-
|
|
|
// Read eight bytes of entropy from the buffered, secure random number
|
|
|
// generator. The buffered reader isn't concurrency safe, so we lock
|
|
|
// around that.
|
|
|
s.mut.Lock()
|
|
|
- _, err := io.ReadFull(s.rd, buf[:])
|
|
|
- s.mut.Unlock()
|
|
|
+ defer s.mut.Unlock()
|
|
|
+
|
|
|
+ _, err := io.ReadFull(s.rd, s.buf[:])
|
|
|
if err != nil {
|
|
|
panic("randomness failure: " + err.Error())
|
|
|
}
|
|
|
-
|
|
|
- // Grab those bytes as an uint64
|
|
|
- return binary.BigEndian.Uint64(buf[:])
|
|
|
+ return binary.LittleEndian.Uint64(s.buf[:])
|
|
|
}
|