Skip to content

Commit

Permalink
brontide: replace aead/chacha20 with x/crypto/chacha20poly1305
Browse files Browse the repository at this point in the history
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 lightningnetwork#146.
  • Loading branch information
Roasbeef committed Mar 16, 2017
1 parent f217093 commit 9234956
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions brontide/noise.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import:
- nacl/secretbox
- ripemd160
- scrypt
- chacha20poly1305
- package: golang.org/x/net
subpackages:
- context
Expand All @@ -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
Expand Down

0 comments on commit 9234956

Please sign in to comment.