~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/pkg/crypto/rand/rand_unix.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-20 14:06:23 UTC
  • mfrom: (14.1.23 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130820140623-b414jfxi3m0qkmrq
Tags: 2:1.1.2-2ubuntu1
* Merge from Debian unstable (LP: #1211749, #1202027). Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - d/control,control.cross: Update Breaks/Replaces for Ubuntu
    versions to ensure smooth upgrades, regenerate control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
// Use of this source code is governed by a BSD-style
3
3
// license that can be found in the LICENSE file.
4
4
 
5
 
// +build darwin freebsd linux netbsd openbsd
 
5
// +build darwin freebsd linux netbsd openbsd plan9
6
6
 
7
7
// Unix cryptographically secure pseudorandom number
8
8
// generator.
15
15
        "crypto/cipher"
16
16
        "io"
17
17
        "os"
 
18
        "runtime"
18
19
        "sync"
19
20
        "time"
20
21
)
22
23
// Easy implementation: read from /dev/urandom.
23
24
// This is sufficient on Linux, OS X, and FreeBSD.
24
25
 
25
 
func init() { Reader = &devReader{name: "/dev/urandom"} }
 
26
func init() {
 
27
        if runtime.GOOS == "plan9" {
 
28
                Reader = newReader(nil)
 
29
        } else {
 
30
                Reader = &devReader{name: "/dev/urandom"}
 
31
        }
 
32
}
26
33
 
27
34
// A devReader satisfies reads by reading the file named name.
28
35
type devReader struct {
39
46
                if f == nil {
40
47
                        return 0, err
41
48
                }
42
 
                r.f = bufio.NewReader(f)
 
49
                if runtime.GOOS == "plan9" {
 
50
                        r.f = f
 
51
                } else {
 
52
                        r.f = bufio.NewReader(f)
 
53
                }
43
54
        }
44
55
        return r.f.Read(b)
45
56
}
46
57
 
47
58
// Alternate pseudo-random implementation for use on
48
 
// systems without a reliable /dev/urandom.  So far we
49
 
// haven't needed it.
 
59
// systems without a reliable /dev/urandom.
50
60
 
51
61
// newReader returns a new pseudorandom generator that
52
62
// seeds itself by reading from entropy.  If entropy == nil,