I started to geek out and I wanted to see how https://golang.org/src/crypto/rand/rand_unix.go works on the inside.
I wanted to see when it generates rands from dev/random
(more secure) and when it generates from dev/urandom
(less security)
It looks like if rand_batched.go
is initialized (this initializes altGetRandom) and GOOS
is not plan9 (then r.name = urandomDevice
it will return the length of the random array and not the content (which is surprising, why the length?)
see line 57:
if altGetRandom != nil && r.name == urandomDevice && altGetRandom(b) {
return len(b), nil
}
else it will simply return the content of the array which will be based on dev/random only if GOOS=plan9.
So why should it ever return len(b)
? Also it looks to me that most of the time it will use dev/urandom
which is suboptimal... am I wrong (guess so because of docs, but help me understand)?
Aucun commentaire:
Enregistrer un commentaire