mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-25 14:52:17 +00:00
safer PRNG seeding: hash concatenation of fresh seedBytes with current seedBytes
This commit is contained in:
parent
aefb6c58b6
commit
3477dd7a90
@ -4,6 +4,7 @@ import (
|
|||||||
"crypto/aes"
|
"crypto/aes"
|
||||||
"crypto/cipher"
|
"crypto/cipher"
|
||||||
crand "crypto/rand"
|
crand "crypto/rand"
|
||||||
|
"crypto/sha256"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"io"
|
"io"
|
||||||
"sync"
|
"sync"
|
||||||
@ -72,8 +73,12 @@ type randInfo struct {
|
|||||||
func (ri *randInfo) MixEntropy(seedBytes []byte) {
|
func (ri *randInfo) MixEntropy(seedBytes []byte) {
|
||||||
ri.mtx.Lock()
|
ri.mtx.Lock()
|
||||||
defer ri.mtx.Unlock()
|
defer ri.mtx.Unlock()
|
||||||
// Make new ri.seedBytes
|
// Make new ri.seedBytes using passed seedBytes and current ri.seedBytes:
|
||||||
hashBytes := Sha256(seedBytes)
|
// ri.seedBytes = sha256( seedBytes || ri.seedBytes )
|
||||||
|
h := sha256.New()
|
||||||
|
h.Write(seedBytes)
|
||||||
|
h.Write(ri.seedBytes[:])
|
||||||
|
hashBytes := h.Sum(nil)
|
||||||
hashBytes32 := [32]byte{}
|
hashBytes32 := [32]byte{}
|
||||||
copy(hashBytes32[:], hashBytes)
|
copy(hashBytes32[:], hashBytes)
|
||||||
ri.seedBytes = xorBytes32(ri.seedBytes, hashBytes32)
|
ri.seedBytes = xorBytes32(ri.seedBytes, hashBytes32)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user