1
2
3
4
5
6
7 package unix
8
9 import (
10 "syscall"
11 "unsafe"
12 )
13
14 const (
15 _CTL_KERN = 1
16
17 _KERN_ARND = 81
18 )
19
20 func GetEntropy(p []byte) error {
21 mib := [2]uint32{_CTL_KERN, _KERN_ARND}
22 n := uintptr(len(p))
23 _, _, errno := syscall.Syscall6(
24 syscall.SYS___SYSCTL,
25 uintptr(unsafe.Pointer(&mib[0])),
26 uintptr(len(mib)),
27 uintptr(unsafe.Pointer(&p[0])),
28 uintptr(unsafe.Pointer(&n)),
29 uintptr(unsafe.Pointer(nil)),
30 0)
31 if errno != 0 {
32 return syscall.Errno(errno)
33 }
34 if n != uintptr(len(p)) {
35 return syscall.EINVAL
36 }
37 return nil
38 }
39
View as plain text