aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/runtime2.go
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2014-12-09 14:40:40 -0800
committerKeith Randall <khr@golang.org>2014-12-10 21:15:35 +0000
commit6820be25da81c1e647e3b807b70a5daf579bb6cf (patch)
tree9547e6336f3c72dc2511f56547daf74fe7fbb4cb /src/runtime/runtime2.go
parentb796cbc40657e0891a43bffab0ffb92ce656d8f1 (diff)
downloadgo-6820be25da81c1e647e3b807b70a5daf579bb6cf.tar.xz
runtime: clean up & go-ify the hash function seeder
Change-Id: I0e95f8a5962c547da20e19a356ae1cf8375c9107 Reviewed-on: https://go-review.googlesource.com/1270 Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/runtime/runtime2.go')
-rw-r--r--src/runtime/runtime2.go31
1 files changed, 24 insertions, 7 deletions
diff --git a/src/runtime/runtime2.go b/src/runtime/runtime2.go
index d18178d093..e0d23e722f 100644
--- a/src/runtime/runtime2.go
+++ b/src/runtime/runtime2.go
@@ -475,15 +475,32 @@ const (
_Structrnd = regSize
)
-var startup_random_data *byte
-var startup_random_data_len uint32
+// startup_random_data holds random bytes initialized at startup. These come from
+// the ELF AT_RANDOM auxiliary vector (vdso_linux_amd64.go or os_linux_386.go).
+var startupRandomData []byte
-var invalidptr int32
+// extendRandom extends the random numbers in r[:n] to the whole slice r.
+// Treats n<0 as n==0.
+func extendRandom(r []byte, n int) {
+ if n < 0 {
+ n = 0
+ }
+ for n < len(r) {
+ // Extend random bits using hash function & time seed
+ w := n
+ if w > 16 {
+ w = 16
+ }
+ h := memhash(unsafe.Pointer(&r[n-w]), uintptr(w), uintptr(nanotime()))
+ for i := 0; i < ptrSize && n < len(r); i++ {
+ r[n] = byte(h)
+ n++
+ h >>= 8
+ }
+ }
+}
-const (
- // hashinit wants this many random bytes
- _HashRandomBytes = 32
-)
+var invalidptr int32
/*
* deferred subroutine calls