Source file src/crypto/rand/rand_windows.go
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 ) 13 14 func init() { Reader = &rngReader{} } 15 16 type rngReader struct{} 17 18 func (r *rngReader) Read(b []byte) (n int, err error) { 19 // RtlGenRandom only returns 1<<32-1 bytes at a time. We only read at 20 // most 1<<31-1 bytes at a time so that this works the same on 32-bit 21 // and 64-bit systems. 22 if err := batched(windows.RtlGenRandom, 1<<31-1)(b); err != nil { 23 return 0, err 24 } 25 return len(b), nil 26 } 27