From 9234956a342a3f7a812e03f3d42ca1679ef9683d Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 15 Mar 2017 19:03:19 -0700 Subject: [PATCH] brontide: replace aead/chacha20 with x/crypto/chacha20poly1305 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- brontide/noise.go | 7 +++++-- glide.yaml | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/brontide/noise.go b/brontide/noise.go index f80a1b3d0..6d6d13af0 100644 --- a/brontide/noise.go +++ b/brontide/noise.go @@ -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 diff --git a/glide.yaml b/glide.yaml index 7aa67de50..d1bb56aa7 100644 --- a/glide.yaml +++ b/glide.yaml @@ -47,6 +47,7 @@ import: - nacl/secretbox - ripemd160 - scrypt + - chacha20poly1305 - package: golang.org/x/net subpackages: - context @@ -56,7 +57,6 @@ import: version: a527838cac5e47260fb61ed155b9b24a6d6a10cc - package: github.com/grpc-ecosystem/grpc-gateway version: ^1.1.0 -- package: github.com/aead/chacha20 - package: github.com/go-errors/errors - package: github.com/tv42/zbase32 - package: github.com/awalterschulze/gographviz