Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(314)

Side by Side Diff: src/pkg/crypto/rand/rand_windows.go

Issue 1773041: code review 1773041: crypto/rand for Windows
Patch Set: code review 1773041: crypto/rand for Windows Created 15 years, 3 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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 // Package rand implements a cryptographically secure
peterGo 2010/07/09 16:49:25 Redundant; we already said this in rand.go.
6 // pseudorandom number generator.
7
8 // Windows cryptographically secure pseudorandom number
9 // generator.
10
11 package rand
12
13 import (
14 "os"
15 "sync"
16 "syscall"
17 )
18
peterGo 2010/07/09 16:49:25 There's an implementation comment for Unix.
19 type rngReader struct {
peterGo 2010/07/09 16:49:25 This rates a comment in Unix.
20 prov uint32
21 mu sync.Mutex
22 }
23
24 func (r *rngReader) Read(b []byte) (n int, err os.Error) {
25 r.mu.Lock()
26 if r.prov == 0 {
brainman 2010/07/09 05:00:42 I would use once.Do(...) here instead.
peterGo 2010/07/10 02:43:00 By design, since they are solving the essentially
27 const provType = syscall.PROV_RSA_FULL
28 const flags = syscall.CRYPT_VERIFYCONTEXT | syscall.CRYPT_SILENT
29 ok, errno := syscall.CryptAcquireContext(&r.prov, nil, nil, prov Type, flags)
30 if !ok {
31 return 0, os.NewSyscallError("CryptAcquireContext", errn o)
32 }
33 }
34 r.mu.Unlock()
35 ok, errno := syscall.CryptGenRandom(r.prov, uint32(len(b)), &b[0])
36 if !ok {
37 return 0, os.NewSyscallError("CryptGenRandom", errno)
38 }
39 return len(b), nil
40 }
41
42 func init() { Reader = &rngReader{} }
peterGo 2010/07/09 16:49:25 The init() function should be in the same location
OLDNEW

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b