Skip to content

Commit ca23184

Browse files
authored
Merge pull request #59 from joostjager/relax-failure-len-check
crypto: relax failure message length check
2 parents b62f49f + d83e7f0 commit ca23184

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

crypto.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,10 @@ func onionEncrypt(sharedSecret *Hash256, data []byte) []byte {
235235
return p
236236
}
237237

238-
// onionErrorLength is the expected length of the onion error message.
239-
// Including padding, all messages on the wire should be 256 bytes. We then add
240-
// the size of the sha256 HMAC as well.
241-
const onionErrorLength = 2 + 2 + 256 + sha256.Size
238+
// minOnionErrorLength is the minimally expected length of the onion error
239+
// message. Including padding, all messages on the wire should be at least 256
240+
// bytes. We then add the size of the sha256 HMAC as well.
241+
const minOnionErrorLength = 2 + 2 + 256 + sha256.Size
242242

243243
// DecryptError attempts to decrypt the passed encrypted error response. The
244244
// onion failure is encrypted in backward manner, starting from the node where
@@ -250,9 +250,9 @@ func (o *OnionErrorDecrypter) DecryptError(encryptedData []byte) (
250250
*DecryptedError, error) {
251251

252252
// Ensure the error message length is as expected.
253-
if len(encryptedData) != onionErrorLength {
253+
if len(encryptedData) < minOnionErrorLength {
254254
return nil, fmt.Errorf("invalid error length: "+
255-
"expected %v got %v", onionErrorLength,
255+
"expected at least %v got %v", minOnionErrorLength,
256256
len(encryptedData))
257257
}
258258

obfuscation_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestOnionFailure(t *testing.T) {
2828
// able to receive the error not only from last hop.
2929
errorPath := paymentPath[:len(paymentPath)-1]
3030

31-
failureData := bytes.Repeat([]byte{'A'}, onionErrorLength-sha256.Size)
31+
failureData := bytes.Repeat([]byte{'A'}, minOnionErrorLength-sha256.Size)
3232
sharedSecrets, err := generateSharedSecrets(paymentPath, sessionKey)
3333
if err != nil {
3434
t.Fatalf("Unexpected error while generating secrets: %v", err)

0 commit comments

Comments
 (0)