mirror of
https://github.com/logos-messaging/noise.git
synced 2026-01-05 23:53:08 +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 {
|
func (noise255) NewCipher(cv []byte) CipherContext {
|
||||||
return &noise255ctx{cv}
|
return &noise255ctx{cc: cv}
|
||||||
}
|
}
|
||||||
|
|
||||||
type noise255ctx struct {
|
type noise255ctx struct {
|
||||||
cc []byte
|
cc []byte
|
||||||
|
keystream [128]byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *noise255ctx) key() (cipher.Stream, []byte) {
|
func (n *noise255ctx) key() (cipher.Stream, []byte) {
|
||||||
@ -203,11 +204,14 @@ func (n *noise255ctx) key() (cipher.Stream, []byte) {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
keystream := make([]byte, 128)
|
for i := range n.keystream {
|
||||||
c.XORKeyStream(keystream, keystream)
|
n.keystream[i] = 0
|
||||||
|
}
|
||||||
|
|
||||||
n.cc = keystream[64:104]
|
c.XORKeyStream(n.keystream[:], n.keystream[:])
|
||||||
return c, keystream
|
|
||||||
|
n.cc = n.keystream[64:104]
|
||||||
|
return c, n.keystream[:]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *noise255ctx) mac(keystream, authtext, ciphertext []byte) [16]byte {
|
func (n *noise255ctx) mac(keystream, authtext, ciphertext []byte) [16]byte {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user