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>
This commit is contained in:
Keith Randall 2014-12-09 14:40:40 -08:00
parent b796cbc406
commit 6820be25da
13 changed files with 59 additions and 113 deletions

View file

@ -475,16 +475,33 @@ 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
// 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
}
}
}
var invalidptr int32
const (
// hashinit wants this many random bytes
_HashRandomBytes = 32
)
/*
* deferred subroutine calls
*/