In this commit, we use a fixed sized buffer for the nonce when we
read/write messages. This was actually escaping to the heap. We can
avoid this by statically allocating it alongside the struct itself.
The benchmark state at this point:
```
goos: darwin
goarch: arm64
pkg: github.com/lightningnetwork/lnd/brontide
cpu: Apple M4 Max
BenchmarkWriteMessage-16 25264 47012 ns/op 4 B/op 1 allocs/op
BenchmarkWriteMessage-16 23542 46809 ns/op 4 B/op 1 allocs/op
BenchmarkWriteMessage-16 25989 47256 ns/op 4 B/op 1 allocs/op
BenchmarkWriteMessage-16 25542 46388 ns/op 4 B/op 1 allocs/op
BenchmarkWriteMessage-16 26083 46612 ns/op 4 B/op 1 allocs/op
BenchmarkWriteMessage-16 25860 46367 ns/op 4 B/op 1 allocs/op
BenchmarkWriteMessage-16 24967 46748 ns/op 4 B/op 1 allocs/op
BenchmarkWriteMessage-16 26088 46485 ns/op 4 B/op 1 allocs/op
BenchmarkWriteMessage-16 25561 46425 ns/op 4 B/op 1 allocs/op
BenchmarkWriteMessage-16 25474 47249 ns/op 4 B/op 1 allocs/op
PASS
ok github.com/lightningnetwork/lnd/brontide 16.911s
```
```
goos: darwin
goarch: arm64
pkg: github.com/lightningnetwork/lnd/brontide
cpu: Apple M4 Max
│ old.txt │ new2.txt │
│ sec/op │ sec/op vs base │
WriteMessage-16 50.34µ ± 1% 46.68µ ± 1% -7.28% (p=0.000 n=10)
│ old.txt │ new2.txt │
│ B/op │ B/op vs base │
WriteMessage-16 73788.000 ± 0% 4.000 ± 0% -99.99% (p=0.000 n=10)
│ old.txt │ new2.txt │
│ allocs/op │ allocs/op vs base │
WriteMessage-16 5.000 ± 0% 1.000 ± 0% -80.00% (p=0.000 n=10)
```
brontide
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