multi: use btcd's btcec/v2 and btcutil modules

This commit was previously split into the following parts to ease
review:
 - 2d746f68: replace imports
 - 4008f0fd: use ecdsa.Signature
 - 849e33d1: remove btcec.S256()
 - b8f6ebbd: use v2 library correctly
 - fa80bca9: bump go modules
This commit is contained in:
Oliver Gugger
2022-02-23 14:48:00 +01:00
parent 8ee9fc837b
commit 7dfe4018ce
350 changed files with 2421 additions and 1289 deletions

View File

@@ -7,7 +7,7 @@ import (
"net"
"time"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/tor"

View File

@@ -10,7 +10,7 @@ import (
"math"
"time"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/lightningnetwork/lnd/keychain"
"golang.org/x/crypto/chacha20poly1305"
"golang.org/x/crypto/hkdf"
@@ -63,7 +63,7 @@ var (
// ephemeralGen is the default ephemeral key generator, used to derive a
// unique ephemeral key for each brontide handshake.
ephemeralGen = func() (*btcec.PrivateKey, error) {
return btcec.NewPrivateKey(btcec.S256())
return btcec.NewPrivateKey()
}
)
@@ -500,7 +500,7 @@ func (b *Machine) RecvActOne(actOne [ActOneSize]byte) error {
copy(p[:], actOne[34:])
// e
b.remoteEphemeral, err = btcec.ParsePubKey(e[:], btcec.S256())
b.remoteEphemeral, err = btcec.ParsePubKey(e[:])
if err != nil {
return err
}
@@ -578,7 +578,7 @@ func (b *Machine) RecvActTwo(actTwo [ActTwoSize]byte) error {
copy(p[:], actTwo[34:])
// e
b.remoteEphemeral, err = btcec.ParsePubKey(e[:], btcec.S256())
b.remoteEphemeral, err = btcec.ParsePubKey(e[:])
if err != nil {
return err
}
@@ -654,7 +654,7 @@ func (b *Machine) RecvActThree(actThree [ActThreeSize]byte) error {
if err != nil {
return err
}
b.remoteStatic, err = btcec.ParsePubKey(remotePub, btcec.S256())
b.remoteStatic, err = btcec.ParsePubKey(remotePub)
if err != nil {
return err
}
@@ -890,23 +890,3 @@ func (b *Machine) ReadBody(r io.Reader, buf []byte) ([]byte, error) {
// buffer to decode the plaintext.
return b.recvCipher.Decrypt(nil, buf[:0], buf)
}
// SetCurveToNil sets the 'Curve' parameter to nil on the handshakeState keys.
// This allows us to log the Machine object without spammy log messages.
func (b *Machine) SetCurveToNil() {
if b.localStatic != nil {
b.localStatic.PubKey().Curve = nil
}
if b.localEphemeral != nil {
b.localEphemeral.PubKey().Curve = nil
}
if b.remoteStatic != nil {
b.remoteStatic.Curve = nil
}
if b.remoteEphemeral != nil {
b.remoteEphemeral.Curve = nil
}
}

View File

@@ -10,7 +10,7 @@ import (
"testing"
"testing/iotest"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/tor"
@@ -23,7 +23,7 @@ type maybeNetConn struct {
func makeListener() (*Listener, *lnwire.NetAddress, error) {
// First, generate the long-term private keys for the brontide listener.
localPriv, err := btcec.NewPrivateKey(btcec.S256())
localPriv, err := btcec.NewPrivateKey()
if err != nil {
return nil, nil, err
}
@@ -56,7 +56,7 @@ func establishTestConnection() (net.Conn, net.Conn, func(), error) {
// Nos, generate the long-term private keys remote end of the connection
// within our test.
remotePriv, err := btcec.NewPrivateKey(btcec.S256())
remotePriv, err := btcec.NewPrivateKey()
if err != nil {
return nil, nil, nil, err
}
@@ -193,7 +193,7 @@ func TestConcurrentHandshakes(t *testing.T) {
// Now, construct a new private key and use the brontide dialer to
// connect to the listener.
remotePriv, err := btcec.NewPrivateKey(btcec.S256())
remotePriv, err := btcec.NewPrivateKey()
if err != nil {
t.Fatalf("unable to generate private key: %v", err)
}
@@ -326,7 +326,7 @@ func TestBolt0008TestVectors(t *testing.T) {
t.Fatalf("unable to decode hex: %v", err)
}
initiatorPriv, _ := btcec.PrivKeyFromBytes(
btcec.S256(), initiatorKeyBytes,
initiatorKeyBytes,
)
initiatorKeyECDH := &keychain.PrivKeyECDH{PrivKey: initiatorPriv}
@@ -337,7 +337,7 @@ func TestBolt0008TestVectors(t *testing.T) {
t.Fatalf("unable to decode hex: %v", err)
}
responderPriv, responderPub := btcec.PrivKeyFromBytes(
btcec.S256(), responderKeyBytes,
responderKeyBytes,
)
responderKeyECDH := &keychain.PrivKeyECDH{PrivKey: responderPriv}
@@ -353,7 +353,7 @@ func TestBolt0008TestVectors(t *testing.T) {
return nil, err
}
priv, _ := btcec.PrivKeyFromBytes(btcec.S256(), eBytes)
priv, _ := btcec.PrivKeyFromBytes(eBytes)
return priv, nil
})
responderEphemeral := EphemeralGenerator(func() (*btcec.PrivateKey, error) {
@@ -364,7 +364,7 @@ func TestBolt0008TestVectors(t *testing.T) {
return nil, err
}
priv, _ := btcec.PrivKeyFromBytes(btcec.S256(), eBytes)
priv, _ := btcec.PrivKeyFromBytes(eBytes)
return priv, nil
})