Remove 2 allocs by using buffer for keystream

This commit is contained in:
Jonathan Rudenberg 2014-07-03 22:46:30 -07:00
parent 908c2ac8a2
commit 6650461c89
No known key found for this signature in database
GPG Key ID: E38D8C6BAA8C49AA

View File

@ -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 {