From d79856af24451b37b789cf5e608caac499de1a0c Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Wed, 12 Jun 2024 19:50:37 +0000 Subject: [PATCH] better mem layout --- peer/internal/uprng/uprng.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/peer/internal/uprng/uprng.go b/peer/internal/uprng/uprng.go index f858d32a1..8bd386b4e 100644 --- a/peer/internal/uprng/uprng.go +++ b/peer/internal/uprng/uprng.go @@ -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() { @@ -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 @@ -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