Browse Source

safer PRNG seeding: hash concatenation of fresh seedBytes with current seedBytes

pull/1782/head
Liamsi 6 years ago
parent
commit
3477dd7a90
1 changed files with 7 additions and 2 deletions
  1. +7
    -2
      random.go

+ 7
- 2
random.go View File

@ -4,6 +4,7 @@ import (
"crypto/aes"
"crypto/cipher"
crand "crypto/rand"
"crypto/sha256"
"encoding/hex"
"io"
"sync"
@ -72,8 +73,12 @@ type randInfo struct {
func (ri *randInfo) MixEntropy(seedBytes []byte) {
ri.mtx.Lock()
defer ri.mtx.Unlock()
// Make new ri.seedBytes
hashBytes := Sha256(seedBytes)
// Make new ri.seedBytes using passed seedBytes and current ri.seedBytes:
// ri.seedBytes = sha256( seedBytes || ri.seedBytes )
h := sha256.New()
h.Write(seedBytes)
h.Write(ri.seedBytes[:])
hashBytes := h.Sum(nil)
hashBytes32 := [32]byte{}
copy(hashBytes32[:], hashBytes)
ri.seedBytes = xorBytes32(ri.seedBytes, hashBytes32)


Loading…
Cancel
Save