Skip to content

Commit

Permalink
better mem layout
Browse files Browse the repository at this point in the history
  • Loading branch information
jrick committed Jun 12, 2024
1 parent 1a595c6 commit d79856a
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions peer/internal/uprng/uprng.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ const (
// incrementing ChaCha20 nonce.
type nonce struct {
limbs [3]uint32
bytes []byte
}

func newNonce() *nonce {
return &nonce{bytes: make([]byte, chacha20.NonceSize)}
bytes [chacha20.NonceSize]byte
}

func (n *nonce) inc() {
Expand All @@ -56,14 +52,13 @@ type prng struct {
read int
t time.Time
key []byte
nonce *nonce
nonce nonce
mu sync.Mutex
}

func newPRNG() *prng {
p := &prng{
nonce: newNonce(),
key: make([]byte, chacha20.KeySize),
key: make([]byte, chacha20.KeySize),
}
p.seed()
return p
Expand All @@ -82,7 +77,7 @@ func (p *prng) seed() {
}

// never errors with correct key and nonce sizes
cipher, _ := chacha20.NewUnauthenticatedCipher(p.key, p.nonce.bytes)
cipher, _ := chacha20.NewUnauthenticatedCipher(p.key, p.nonce.bytes[:])
p.nonce.inc()

p.cipher = cipher
Expand Down

0 comments on commit d79856a

Please sign in to comment.