1 // Copyright 2016 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4 5 package sysrand
6 7 import "internal/syscall/unix"
8 9 func read(b []byte) error {
10 for len(b) > 0 {
11 size := len(b)
12 // "Returns independent uniformly distributed bytes at random each time,
13 // as many as requested up to 256, derived from the system entropy pool;
14 // see rnd(4)." -- man sysctl(7)
15 if size > 256 {
16 size = 256
17 }
18 if err := unix.Arandom(b[:size]); err != nil {
19 return err
20 }
21 b = b[size:]
22 }
23 return nil
24 }
25