Skip to content

Commit 371dfed

Browse files
committed
update definition of minOnionErrorLength
1 parent ca23184 commit 371dfed

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

crypto.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ func (p *PrivKeyECDH) PubKey() *btcec.PublicKey {
6161
// k is our private key, and P is the public key, we perform the following
6262
// operation:
6363
//
64-
// sx := k*P
65-
// s := sha256(sx.SerializeCompressed())
64+
// sx := k*P
65+
// s := sha256(sx.SerializeCompressed())
6666
//
6767
// NOTE: This is part of the SingleKeyECDH interface.
6868
func (p *PrivKeyECDH) ECDH(pub *btcec.PublicKey) ([32]byte, error) {
@@ -237,8 +237,8 @@ func onionEncrypt(sharedSecret *Hash256, data []byte) []byte {
237237

238238
// minOnionErrorLength is the minimally expected length of the onion error
239239
// 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
240+
// bytes.
241+
const minOnionErrorLength = 2 + 2 + 256
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
@@ -249,10 +249,10 @@ const minOnionErrorLength = 2 + 2 + 256 + sha256.Size
249249
func (o *OnionErrorDecrypter) DecryptError(encryptedData []byte) (
250250
*DecryptedError, error) {
251251

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

obfuscation_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package sphinx
22

33
import (
44
"bytes"
5-
"crypto/sha256"
65
"encoding/hex"
76
"reflect"
87
"testing"
@@ -28,7 +27,7 @@ func TestOnionFailure(t *testing.T) {
2827
// able to receive the error not only from last hop.
2928
errorPath := paymentPath[:len(paymentPath)-1]
3029

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

0 commit comments

Comments
 (0)