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.
5
// Windows cryptographically secure pseudorandom number
16
// Implemented by using Windows CryptoAPI 2.0.
18
func init() { Reader = &rngReader{} }
20
// A rngReader satisfies reads by reading from the Windows CryptGenRandom API.
21
type rngReader struct {
26
func (r *rngReader) Read(b []byte) (n int, err os.Error) {
29
const provType = syscall.PROV_RSA_FULL
30
const flags = syscall.CRYPT_VERIFYCONTEXT | syscall.CRYPT_SILENT
31
errno := syscall.CryptAcquireContext(&r.prov, nil, nil, provType, flags)
34
return 0, os.NewSyscallError("CryptAcquireContext", errno)
38
errno := syscall.CryptGenRandom(r.prov, uint32(len(b)), &b[0])
40
return 0, os.NewSyscallError("CryptGenRandom", errno)