mirror of
https://github.com/logos-messaging/noise.git
synced 2026-02-17 20:53:09 +00:00
Remove 2 allocs by using buffer for keystream
This commit is contained in:
parent
908c2ac8a2
commit
6650461c89
16
box/box.go
16
box/box.go
@ -187,11 +187,12 @@ func (noise255) DH(privkey, pubkey []byte) []byte {
|
||||
}
|
||||
|
||||
func (noise255) NewCipher(cv []byte) CipherContext {
|
||||
return &noise255ctx{cv}
|
||||
return &noise255ctx{cc: cv}
|
||||
}
|
||||
|
||||
type noise255ctx struct {
|
||||
cc []byte
|
||||
cc []byte
|
||||
keystream [128]byte
|
||||
}
|
||||
|
||||
func (n *noise255ctx) key() (cipher.Stream, []byte) {
|
||||
@ -203,11 +204,14 @@ func (n *noise255ctx) key() (cipher.Stream, []byte) {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
keystream := make([]byte, 128)
|
||||
c.XORKeyStream(keystream, keystream)
|
||||
for i := range n.keystream {
|
||||
n.keystream[i] = 0
|
||||
}
|
||||
|
||||
n.cc = keystream[64:104]
|
||||
return c, keystream
|
||||
c.XORKeyStream(n.keystream[:], n.keystream[:])
|
||||
|
||||
n.cc = n.keystream[64:104]
|
||||
return c, n.keystream[:]
|
||||
}
|
||||
|
||||
func (n *noise255ctx) mac(keystream, authtext, ciphertext []byte) [16]byte {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user