| 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 unix |
| 6 | |
| 7 | import ( |
| 8 | "syscall" |
| 9 | "unsafe" |
| 10 | ) |
| 11 | |
| 12 | // getentropy(2)'s syscall number, from /usr/src/sys/kern/syscalls.master |
| 13 | const entropyTrap uintptr = 7 |
| 14 | |
| 15 | // GetEntropy calls the OpenBSD getentropy system call. |
| 16 | func GetEntropy(p []byte) error { |
| 17 | _, _, errno := syscall.Syscall(entropyTrap, |
| 18 | uintptr(unsafe.Pointer(&p[0])), |
| 19 | uintptr(len(p)), |
| 20 | 0) |
| 21 | if errno != 0 { |
| 22 | return errno |
| 23 | } |
| 24 | return nil |
| 25 | } |