github.com/likebike/go--@v0.0.0-20190911215757-0bd925d16e96/go/src/crypto/rand/rand_openbsd.go (about)

     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 rand
     6  
     7  import (
     8  	"internal/syscall/unix"
     9  )
    10  
    11  func init() {
    12  	altGetRandom = getRandomOpenBSD
    13  }
    14  
    15  func getRandomOpenBSD(p []byte) (ok bool) {
    16  	// getentropy(2) returns a maximum of 256 bytes per call
    17  	for i := 0; i < len(p); i += 256 {
    18  		end := i + 256
    19  		if len(p) < end {
    20  			end = len(p)
    21  		}
    22  		err := unix.GetEntropy(p[i:end])
    23  		if err != nil {
    24  			return false
    25  		}
    26  	}
    27  	return true
    28  }