Skip to content

Commit

Permalink
make the security guarantees more wish-washy
Browse files Browse the repository at this point in the history
  • Loading branch information
jrick committed Jun 12, 2024
1 parent 53f96d8 commit b6bc033
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions peer/internal/uprng/uprng.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
var Reader io.Reader

func init() {
Reader = new(prng)
Reader = newPRNG()
}

const (
Expand All @@ -39,19 +39,26 @@ type prng struct {
mu sync.Mutex
}

func newPRNG() *prng {
p := new(prng)
p.seed()
return p
}

// seed reseeds the prng with kernel and existing cipher entropy, if the
// cipher has been originally seeded.
// Panics only during intial seeding if a crypto/rand read errors.
func (p *prng) seed() {
_, err := cryptorand.Read(key)
if err != nil {
if err != nil && p.cipher == nil {
panic(err)
}
if p.cipher != nil {
p.cipher.XORKeyStream(key, key)
}

cipher, err := chacha20.NewUnauthenticatedCipher(key, nonce)
if err != nil {
panic(err)
}
// never errors with correct key and nonce sizes
cipher, _ := chacha20.NewUnauthenticatedCipher(key, nonce)

for i := range key {
key[i] = 0
Expand Down

0 comments on commit b6bc033

Please sign in to comment.