From bc885f5f2733a38e7ded135b820f01080470efd5 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 9 Jan 2017 19:12:28 -0800 Subject: [PATCH] brontide: modify key rotation to match test vectors in spec This commit modifies our key rotation slightly to match the test vectors within the BOLT08 specifications. Before this commit, we were rotating one message before the rest of the implementers. This implementation divergence was possibly due to the section of the spec describing the rotations being a bit ambiguous. A future PR to the lightning-rfc repo will make the spec more explicit to avoid situations like this in the future. --- brontide/noise.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/brontide/noise.go b/brontide/noise.go index fc925ba81..ba34b4f23 100644 --- a/brontide/noise.go +++ b/brontide/noise.go @@ -87,7 +87,7 @@ func (c *cipherState) Encrypt(associatedData, cipherText, plainText []byte) []by defer func() { c.nonce++ - if c.nonce > keyRotationInterval { + if c.nonce == keyRotationInterval { c.rotateKey() } }() @@ -105,7 +105,7 @@ func (c *cipherState) Decrypt(associatedData, plainText, cipherText []byte) ([]b defer func() { c.nonce++ - if c.nonce > keyRotationInterval { + if c.nonce == keyRotationInterval { c.rotateKey() } }()