Black Lives Matter. Support the Equal Justice Initiative.

Source file src/crypto/rand/rand_windows.go

Documentation: crypto/rand

     1  // Copyright 2010 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  // Windows cryptographically secure pseudorandom number
     6  // generator.
     7  
     8  package rand
     9  
    10  import (
    11  	"internal/syscall/windows"
    12  	"os"
    13  )
    14  
    15  func init() { Reader = &rngReader{} }
    16  
    17  type rngReader struct{}
    18  
    19  func (r *rngReader) Read(b []byte) (n int, err error) {
    20  	// RtlGenRandom only accepts 2**32-1 bytes at a time, so truncate.
    21  	inputLen := uint32(len(b))
    22  
    23  	if inputLen == 0 {
    24  		return 0, nil
    25  	}
    26  
    27  	err = windows.RtlGenRandom(b)
    28  	if err != nil {
    29  		return 0, os.NewSyscallError("RtlGenRandom", err)
    30  	}
    31  	return int(inputLen), nil
    32  }
    33  

View as plain text