brontide: replace aead/chacha20 with x/crypto/chacha20poly1305

This commit replaces aead’s chacha20 library with the official golang
implementation. We should see a bit of a performance increase on amd64
as the assembly for the library uses the SIMD AVX2 instructions in the
inner loop. In the future assembly will be written for other platforms,
so we’ll see a performance increase across the board.

Fixes #146.
This commit is contained in:
Olaoluwa Osuntokun
2017-03-15 19:03:19 -07:00
parent f217093c00
commit 9234956a34
2 changed files with 6 additions and 3 deletions

View File

@@ -9,9 +9,9 @@ import (
"io"
"math"
"golang.org/x/crypto/chacha20poly1305"
"golang.org/x/crypto/hkdf"
"github.com/aead/chacha20"
"github.com/roasbeef/btcd/btcec"
)
@@ -122,7 +122,10 @@ func (c *cipherState) Decrypt(associatedData, plainText, cipherText []byte) ([]b
func (c *cipherState) InitializeKey(key [32]byte) {
c.secretKey = key
c.nonce = 0
c.cipher = chacha20.NewChaCha20Poly1305(&c.secretKey)
// Safe to ignore the error here as our key is properly sized
// (32-bytes).
c.cipher, _ = chacha20poly1305.New(c.secretKey[:])
}
// InitializeKeyWithSalt is identical to InitializeKey however it also sets the