Retro68/gcc/libgo/go/crypto/rand/rand_windows.go

33 lines
680 B
Go
Raw Normal View History

// Copyright 2010 The Go Authors. All rights reserved.
2012-03-27 23:13:14 +00:00
// 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
// generator.
package rand
import (
"internal/syscall/windows"
2012-03-27 23:13:14 +00:00
"os"
)
func init() { Reader = &rngReader{} }
type rngReader struct{}
2012-03-27 23:13:14 +00:00
func (r *rngReader) Read(b []byte) (n int, err error) {
// RtlGenRandom only accepts 2**32-1 bytes at a time, so truncate.
inputLen := uint32(len(b))
2014-09-21 17:33:12 +00:00
if inputLen == 0 {
2014-09-21 17:33:12 +00:00
return 0, nil
}
err = windows.RtlGenRandom(b)
2012-03-27 23:13:14 +00:00
if err != nil {
return 0, os.NewSyscallError("RtlGenRandom", err)
2012-03-27 23:13:14 +00:00
}
return int(inputLen), nil
2012-03-27 23:13:14 +00:00
}