Skip to content

Commit c618cee

Browse files
committed
make tests work
1 parent 89e3025 commit c618cee

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

lndc/noise.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,10 @@ func newXKHandshakeState(initiator bool, prologue []byte,
304304
// EphemeralGenerator is a functional option that allows callers to substitute
305305
// a custom function for use when generating ephemeral keys for ActOne or
306306
// ActTwo. The function closure return by this function can be passed into
307-
// NewNoiseMachine as a function option parameter.
307+
// NewNoiseMachine(XK or XX) as a function option parameter.
308308
func EphemeralGenerator(gen func() (*koblitz.PrivateKey, error)) func(*Machine) {
309309
return func(m *Machine) {
310-
m.ephemeralGen = gen
310+
m.EphemeralGen = gen
311311
}
312312
}
313313

@@ -353,7 +353,8 @@ type Machine struct {
353353
sendCipher cipherState
354354
recvCipher cipherState
355355

356-
ephemeralGen func() (*koblitz.PrivateKey, error)
356+
EphemeralGen func() (*koblitz.PrivateKey, error)
357+
// this is exported in order for noise_test to define a static ephemeral pubkey
357358

358359
handshakeState
359360

@@ -372,7 +373,7 @@ type Machine struct {
372373
nextCipherText [math.MaxUint16 + macSize]byte
373374
}
374375

375-
// NewNoiseMachine creates a new instance of the lndc state-machine. If
376+
// NewNoiseXKMachine creates a new instance of the lndc state-machine. If
376377
// the responder (listener) is creating the object, then the remotePub should
377378
// be nil. The handshake state within lndc is initialized using the ascii
378379
// string "lightning" as the prologue. The last parameter is a set of variadic
@@ -387,7 +388,7 @@ func NewNoiseXKMachine(initiator bool, localStatic *koblitz.PrivateKey,
387388
m := &Machine{handshakeState: handshake}
388389
// With the initial base machine created, we'll assign our default
389390
// version of the ephemeral key generator.
390-
m.ephemeralGen = func() (*koblitz.PrivateKey, error) {
391+
m.EphemeralGen = func() (*koblitz.PrivateKey, error) {
391392
return koblitz.NewPrivateKey(koblitz.S256())
392393
}
393394

@@ -402,7 +403,7 @@ func NewNoiseXXMachine(initiator bool, localStatic *koblitz.PrivateKey) *Machine
402403

403404
// With the initial base machine created, we'll assign our default
404405
// version of the ephemeral key generator.
405-
m.ephemeralGen = func() (*koblitz.PrivateKey, error) {
406+
m.EphemeralGen = func() (*koblitz.PrivateKey, error) {
406407
return koblitz.NewPrivateKey(koblitz.S256())
407408
}
408409

@@ -475,7 +476,7 @@ func (b *Machine) GenActOne(remotePK [33]byte) ([]byte, error) {
475476
var err error
476477
actOne := make([]byte, ActOneSize)
477478
// Generate e
478-
b.localEphemeral, err = b.ephemeralGen()
479+
b.localEphemeral, err = b.EphemeralGen()
479480
if err != nil {
480481
return actOne, err
481482
}
@@ -544,7 +545,7 @@ func (b *Machine) GenActTwo(HandshakeVersion byte) ([]byte, error) {
544545
var err error
545546
actTwo := make([]byte, ActTwoSize)
546547
// e
547-
b.localEphemeral, err = b.ephemeralGen()
548+
b.localEphemeral, err = b.EphemeralGen()
548549
if err != nil {
549550
return actTwo, err
550551
}

lndc/noise_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ func TestBolt0008TestVectors(t *testing.T) {
310310
// EphemeralGenerator function for the state machine to ensure that the
311311
// initiator and responder both generate the ephemeral public key
312312
// defined within the test vectors.
313-
initiatorEphemeral := EphemeralGenerator(func() (*koblitz.PrivateKey, error) {
313+
initiatorEphemeral := func() (*koblitz.PrivateKey, error) {
314314
e := "121212121212121212121212121212121212121212121212121212" +
315315
"1212121212"
316316
eBytes, err := hex.DecodeString(e)
@@ -320,8 +320,8 @@ func TestBolt0008TestVectors(t *testing.T) {
320320

321321
priv, _ := koblitz.PrivKeyFromBytes(koblitz.S256(), eBytes)
322322
return priv, nil
323-
})
324-
responderEphemeral := EphemeralGenerator(func() (*koblitz.PrivateKey, error) {
323+
}
324+
responderEphemeral := func() (*koblitz.PrivateKey, error) {
325325
e := "222222222222222222222222222222222222222222222222222" +
326326
"2222222222222"
327327
eBytes, err := hex.DecodeString(e)
@@ -331,12 +331,14 @@ func TestBolt0008TestVectors(t *testing.T) {
331331

332332
priv, _ := koblitz.PrivKeyFromBytes(koblitz.S256(), eBytes)
333333
return priv, nil
334-
})
334+
}
335335

336336
// Finally, we'll create both brontide state machines, so we can begin
337337
// our test.
338-
initiator := NewNoiseMachine(true, initiatorPriv, initiatorEphemeral)
339-
responder := NewNoiseMachine(false, responderPriv, responderEphemeral)
338+
initiator := NewNoiseXXMachine(true, initiatorPriv)
339+
initiator.EphemeralGen = initiatorEphemeral // needed for locking the ephemeral key
340+
responder := NewNoiseXXMachine(false, responderPriv)
341+
responder.EphemeralGen = responderEphemeral // needed for locking the ephemeral key
340342

341343
// We'll start with the initiator generating the initial payload for
342344
// act one. This should consist of exactly 50 bytes. We'll assert that
@@ -347,9 +349,7 @@ func TestBolt0008TestVectors(t *testing.T) {
347349
if err != nil {
348350
t.Fatalf("unable to generate act one: %v", err)
349351
}
350-
expectedActOne, err := hex.DecodeString("01036360e856310ce5d294e" +
351-
"8be33fc807077dc56ac80d95d9cd4ddbd21325eff73f71432d5611e91" +
352-
"ffea67c17e8d5ae0cbb3")
352+
expectedActOne, err := hex.DecodeString("01036360e856310ce5d294e8be33fc807077dc56ac80d95d9cd4ddbd21325eff73f71432d5611e91ffea67c17e8d5ae0cbb3")
353353
if err != nil {
354354
t.Fatalf("unable to parse expected act one: %v", err)
355355
}

0 commit comments

Comments
 (0)