| // Copyright 2010 The Go Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| // Windows cryptographically secure pseudorandom number |
| // Implemented by using Windows CryptoAPI 2.0. |
| func init() { Reader = &rngReader{} } |
| // A rngReader satisfies reads by reading from the Windows CryptGenRandom API. |
| func (r *rngReader) Read(b []byte) (n int, err error) { |
| const provType = syscall.PROV_RSA_FULL |
| const flags = syscall.CRYPT_VERIFYCONTEXT | syscall.CRYPT_SILENT |
| err := syscall.CryptAcquireContext(&r.prov, nil, nil, provType, flags) |
| return 0, os.NewSyscallError("CryptAcquireContext", err) |
| err = syscall.CryptGenRandom(r.prov, uint32(len(b)), &b[0]) |
| return 0, os.NewSyscallError("CryptGenRandom", err) |