lnd/brontide
Olaoluwa Osuntokun 8c6dbc9ffa
brontide: when decrypting re-use the allocated ciphertext buf
In this commit, we implement a simple optimization that dramatically
reduces the number of allocations we need to make when we decrypt a new
message. Before this commit, we would pass in a `nil` value to the
`Decrypt` method which meant that it would always allocate a new
buffers.

Rather than force this behavior, in this commit, we pass in the
ciphertext buffer (with a length of zero), such that the decryption
operation will simply copy the plaintext bytes over the cipher text in
place. This works as the cipher text is always larger than the
plaintext, since the plaintext doesn't have a MAC attached.

The amount the perf increase, amount of allocations, and amount of bytes
allocated are pretty nice:
```
benchmark                        old ns/op     new ns/op     delta
BenchmarkReadHeaderAndBody-8     88652         75896         -14.39%

benchmark                        old allocs     new allocs     delta
BenchmarkReadHeaderAndBody-8     6              4              -33.33%

benchmark                        old bytes     new bytes     delta
BenchmarkReadHeaderAndBody-8     65664         128           -99.81%
```

Here old is without this change, and new with it.
2021-08-27 16:57:12 -07:00
..
bench_test.go brontide: add new benchmark to measure allocs for header+body decrypt 2021-08-27 16:57:09 -07:00
conn.go brontide: fix typo 2020-12-04 23:07:53 +08:00
listener.go brontide: fix typo 2020-12-04 23:07:53 +08:00
noise_test.go
noise.go brontide: when decrypting re-use the allocated ciphertext buf 2021-08-27 16:57:12 -07:00
README.md multi: unify code blocks in READMEs 2021-01-22 09:14:11 +01:00

brontide

Build Status MIT licensed GoDoc

The brontide package implements a secure crypto messaging protocol based off of the Noise Protocol Framework. The package exposes the raw state machine that handles the handshake and subsequent message encryption/decryption scheme. Additionally, the package exposes a net.Conn and a net.Listener interface implementation which allows the encrypted transport to be seamlessly integrated into a codebase.

The secure messaging scheme implemented within this package is described in detail in BOLT #8 of the Lightning Network specifications.

This package has intentionally been designed so it can be used as a standalone package for any projects needing secure encrypted+authenticated communications between network enabled programs.

Installation and Updating

⛰  go get -u github.com/lightningnetwork/lnd/brontide