From 4b304adf2a858388f48f0bec0df37472c5016071 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 22 Oct 2015 13:20:52 -0700 Subject: [PATCH] expand filler bytes to full size, avoids panic --- sphinx.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sphinx.go b/sphinx.go index e7eb0d0b4..65f0cd9ea 100644 --- a/sphinx.go +++ b/sphinx.go @@ -204,9 +204,10 @@ func NewMixHeader(dest LightningAddress, identifier [securityParameter]byte, // "filler" bytes produced by this function at the last hop. Using this // methodology, the size of the mix header stays constant at each hop. func generateHeaderPadding(numHops int, sharedSecrets [][sharedSecretSize]byte) []byte { - var filler []byte + fillerSize := (2*(numMaxHops-1) + 3) * securityParameter + filler := make([]byte, fillerSize) + for i := 1; i < numHops; i++ { - slice := (2*(numMaxHops-1) + 3) * securityParameter padding := bytes.Repeat([]byte{0}, 2*securityParameter) var tempBuf bytes.Buffer @@ -216,7 +217,7 @@ func generateHeaderPadding(numHops int, sharedSecrets [][sharedSecretSize]byte) streamBytes := generateCipherStream(generateKey("rho", sharedSecrets[i-1]), numStreamBytes) - xor(filler, tempBuf.Bytes(), streamBytes[slice:]) + xor(filler, tempBuf.Bytes(), streamBytes[fillerSize:]) } return filler