Skip to content

Commit 5435509

Browse files
authored
Merge pull request #68 from gijswijs/onion-messaging
Onion messaging support
2 parents 1780f00 + cce9f53 commit 5435509

File tree

12 files changed

+1339
-179
lines changed

12 files changed

+1339
-179
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
vendor/
22
.idea
3+
.aider*

.golangci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ linters:
5252
# Checks the number of statements in a function.
5353
statements: 50
5454

55+
tagliatelle:
56+
case:
57+
rules:
58+
json: snake
59+
5560
wsl_v5:
5661
# We adopt a more relaxed cuddling rule by enabling
5762
# `allow-whole-block`. This allows a variable declaration to be

cmd/main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ func main() {
7070
"data.",
7171
Value: defaultHopDataPath,
7272
},
73+
cli.IntFlag{
74+
Name: "payload-size",
75+
Usage: "The size for a payload for a " +
76+
"single hop. Defaults to the " +
77+
"max routing payload size",
78+
Value: sphinx.MaxRoutingPayloadSize,
79+
},
7380
},
7481
},
7582
{
@@ -203,8 +210,10 @@ func generate(ctx *cli.Context) error {
203210
return fmt.Errorf("could not peel onion spec: %v", err)
204211
}
205212

213+
payloadSize := ctx.Int("payload-size")
206214
msg, err := sphinx.NewOnionPacket(
207215
path, sessionKey, assocData, sphinx.DeterministicPacketFiller,
216+
sphinx.WithMaxPayloadSize(payloadSize),
208217
)
209218
if err != nil {
210219
return fmt.Errorf("error creating message: %v", err)

error.go

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,56 @@
11
package sphinx
22

3-
import "fmt"
3+
import "errors"
44

55
var (
66
// ErrReplayedPacket is an error returned when a packet is rejected
77
// during processing due to being an attempted replay or probing
88
// attempt.
9-
ErrReplayedPacket = fmt.Errorf("sphinx packet replay attempted")
9+
ErrReplayedPacket = errors.New("sphinx packet replay attempted")
1010

1111
// ErrInvalidOnionVersion is returned during decoding of the onion
1212
// packet, when the received packet has an unknown version byte.
13-
ErrInvalidOnionVersion = fmt.Errorf("invalid onion packet version")
13+
ErrInvalidOnionVersion = errors.New("invalid onion packet version")
1414

15-
// ErrInvalidOnionHMAC is returned during onion parsing process, when received
16-
// mac does not corresponds to the generated one.
17-
ErrInvalidOnionHMAC = fmt.Errorf("invalid mismatched mac")
15+
// ErrInvalidOnionHMAC is returned during onion parsing process, when
16+
// received mac does not corresponds to the generated one.
17+
ErrInvalidOnionHMAC = errors.New("invalid mismatched mac")
1818

1919
// ErrInvalidOnionKey is returned during onion parsing process, when
2020
// onion key is invalid.
21-
ErrInvalidOnionKey = fmt.Errorf("invalid onion key: pubkey isn't on " +
21+
ErrInvalidOnionKey = errors.New("invalid onion key: pubkey isn't on " +
2222
"secp256k1 curve")
2323

24-
// ErrLogEntryNotFound is an error returned when a packet lookup in a replay
25-
// log fails because it is missing.
26-
ErrLogEntryNotFound = fmt.Errorf("sphinx packet is not in log")
24+
// ErrLogEntryNotFound is an error returned when a packet lookup in a
25+
// replay log fails because it is missing.
26+
ErrLogEntryNotFound = errors.New("sphinx packet is not in log")
27+
28+
// ErrPayloadSizeExceeded is returned when the payload size exceeds the
29+
// configured payload size of the onion packet.
30+
ErrPayloadSizeExceeded = errors.New("max payload size exceeded")
31+
32+
// ErrSharedSecretDerivation is returned when we fail to derive the
33+
// shared secret for a hop.
34+
ErrSharedSecretDerivation = errors.New("error generating shared secret")
35+
36+
// ErrMissingHMAC is returned when the onion packet is too small to
37+
// contain a valid HMAC.
38+
ErrMissingHMAC = errors.New("onion packet is too small, missing HMAC")
39+
40+
// ErrNegativeRoutingInfoSize is returned when a negative routing info
41+
// size is specified in the Sphinx configuration.
42+
ErrNegativeRoutingInfoSize = errors.New("routing info size must be " +
43+
"non-negative")
44+
45+
// ErrNegativePayloadSize is returned when a negative payload size is
46+
// specified in the Sphinx configuration.
47+
ErrNegativePayloadSize = errors.New("payload size must be " +
48+
"non-negative")
49+
50+
// ErrZeroHops is returned when attempting to create a route with zero
51+
// hops.
52+
ErrZeroHops = errors.New("route of length zero passed in")
53+
54+
// ErrIOReadFull is returned when an io read full operation fails.
55+
ErrIOReadFull = errors.New("io read full error")
2756
)

go.mod

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,25 @@ module github.com/lightningnetwork/lightning-onion
22

33
require (
44
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da
5-
github.com/btcsuite/btcd v0.22.0-beta.0.20220207191057-4dc4ff7963b4
6-
github.com/btcsuite/btcd/btcec/v2 v2.1.0
7-
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f
5+
github.com/btcsuite/btcd v0.24.3-0.20250318170759-4f4ea81776d6
6+
github.com/btcsuite/btcd/btcec/v2 v2.3.4
7+
github.com/btcsuite/btclog v0.0.0-20241003133417-09c4e92e319c
88
github.com/davecgh/go-spew v1.1.1
9-
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1
10-
github.com/stretchr/testify v1.8.2
11-
github.com/urfave/cli v1.22.5
12-
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
9+
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0
10+
github.com/stretchr/testify v1.10.0
11+
github.com/urfave/cli v1.22.9
12+
golang.org/x/crypto v0.33.0
1313
)
1414

1515
require (
16-
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d // indirect
16+
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 // indirect
17+
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
18+
github.com/kr/pretty v0.3.1 // indirect
1719
github.com/pmezard/go-difflib v1.0.0 // indirect
18-
github.com/russross/blackfriday/v2 v2.0.1 // indirect
19-
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
20-
golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed // indirect
20+
github.com/rogpeppe/go-internal v1.13.1 // indirect
21+
github.com/russross/blackfriday/v2 v2.1.0 // indirect
22+
golang.org/x/sys v0.30.0 // indirect
23+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
2124
gopkg.in/yaml.v3 v3.0.1 // indirect
2225
)
2326

go.sum

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,50 @@
11
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
22
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da h1:KjTM2ks9d14ZYCvmHS9iAKVt9AyzRSqNU1qabPih5BY=
33
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da/go.mod h1:eHEWzANqSiWQsof+nXEI9bUVUyV6F53Fp89EuCh2EAA=
4-
github.com/btcsuite/btcd v0.22.0-beta.0.20220207191057-4dc4ff7963b4 h1:CEGr/598C/0LZQUoioaT6sdGGcJgu4+ck0PDeJ/QkKs=
5-
github.com/btcsuite/btcd v0.22.0-beta.0.20220207191057-4dc4ff7963b4/go.mod h1:7alexyj/lHlOtr2PJK7L/+HDJZpcGDn/pAU98r7DY08=
6-
github.com/btcsuite/btcd/btcec/v2 v2.1.0 h1:Whmbo9yShKKG+WrUfYGFfgj77vYBiwhwBSJnM66TMKI=
7-
github.com/btcsuite/btcd/btcec/v2 v2.1.0/go.mod h1:2VzYrv4Gm4apmbVVsSq5bqf1Ec8v56E48Vt0Y/umPgA=
8-
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f h1:bAs4lUbRJpnnkd9VhRV3jjAVU7DJVjMaK+IsvSeZvFo=
9-
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA=
10-
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
4+
github.com/btcsuite/btcd v0.24.3-0.20250318170759-4f4ea81776d6 h1:8n9k3I7e8DkpdQ5YAP4j8ly/LSsbe6qX9vmVbrUGvVw=
5+
github.com/btcsuite/btcd v0.24.3-0.20250318170759-4f4ea81776d6/go.mod h1:OmM4kFtB0klaG/ZqT86rQiyw/1iyXlJgc3UHClPhhbs=
6+
github.com/btcsuite/btcd/btcec/v2 v2.3.4 h1:3EJjcN70HCu/mwqlUsGK8GcNVyLVxFDlWurTXGPFfiQ=
7+
github.com/btcsuite/btcd/btcec/v2 v2.3.4/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
8+
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 h1:59Kx4K6lzOW5w6nFlA0v5+lk/6sjybR934QNHSJZPTQ=
9+
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
10+
github.com/btcsuite/btclog v0.0.0-20241003133417-09c4e92e319c h1:4HxD1lBUGUddhzgaNgrCPsFWd7cGYNpeFUgd9ZIgyM0=
11+
github.com/btcsuite/btclog v0.0.0-20241003133417-09c4e92e319c/go.mod h1:w7xnGOhwT3lmrS4H3b/D1XAXxvh+tbhUm8xeHN2y3TQ=
1112
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
12-
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
13+
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
14+
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
15+
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
1316
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
1417
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
15-
github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc=
16-
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 h1:YLtO71vCjJRCBcrPMtQ9nqBsqpA1m5sE92cU+pd5Mcc=
17-
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeCxkaw7y45JueMRL4DIyJDKs=
18+
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnNEcHYvcCuK6dPZSg=
19+
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
20+
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
21+
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
22+
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
23+
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
24+
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
25+
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
26+
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
27+
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
1828
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1929
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
20-
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
30+
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
31+
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
32+
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
2133
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
22-
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
34+
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
35+
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
2336
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
24-
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
25-
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
26-
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
27-
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
28-
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
29-
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
30-
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
31-
github.com/urfave/cli v1.22.5 h1:lNq9sAHXK2qfdI8W+GRItjCEkI+2oR4d+MEHy1CKXoU=
32-
github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
33-
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
34-
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
35-
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
36-
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
37-
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
38-
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
39-
golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed h1:J22ig1FUekjjkmZUM7pTKixYm8DvrYsvrBZdunYeIuQ=
40-
golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
41-
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
42-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
37+
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
38+
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
39+
github.com/urfave/cli v1.22.9 h1:cv3/KhXGBGjEXLC4bH0sLuJ9BewaAbpk5oyMOveu4pw=
40+
github.com/urfave/cli v1.22.9/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
41+
golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus=
42+
golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M=
43+
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
44+
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
4345
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
46+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
47+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
4448
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
45-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
4649
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
4750
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

packetfiller.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,17 @@ import (
1212
// in order to ensure we don't leak information on the true route length to the
1313
// receiver. The packet filler may also use the session key to generate a set
1414
// of filler bytes if it wishes to be deterministic.
15-
type PacketFiller func(*btcec.PrivateKey, *[routingInfoSize]byte) error
15+
type PacketFiller func(*btcec.PrivateKey, []byte) error
1616

1717
// RandPacketFiller is a packet filler that reads a set of random bytes from a
1818
// CSPRNG.
19-
func RandPacketFiller(_ *btcec.PrivateKey, mixHeader *[routingInfoSize]byte) error {
19+
func RandPacketFiller(_ *btcec.PrivateKey, mixHeader []byte) error {
2020
// Read out random bytes to fill out the rest of the starting packet
2121
// after the hop payload for the final node. This mitigates a privacy
2222
// leak that may reveal a lower bound on the true path length to the
2323
// receiver.
24-
if _, err := rand.Read(mixHeader[:]); err != nil {
24+
_, err := rand.Read(mixHeader)
25+
if err != nil {
2526
return err
2627
}
2728

@@ -31,15 +32,15 @@ func RandPacketFiller(_ *btcec.PrivateKey, mixHeader *[routingInfoSize]byte) err
3132
// BlankPacketFiller is a packet filler that doesn't attempt to fill out the
3233
// packet at all. It should ONLY be used for generating test vectors or other
3334
// instances that required deterministic packet generation.
34-
func BlankPacketFiller(_ *btcec.PrivateKey, _ *[routingInfoSize]byte) error {
35+
func BlankPacketFiller(_ *btcec.PrivateKey, _ []byte) error {
3536
return nil
3637
}
3738

3839
// DeterministicPacketFiller is a packet filler that generates a deterministic
3940
// set of filler bytes by using chacha20 with a key derived from the session
4041
// key.
4142
func DeterministicPacketFiller(sessionKey *btcec.PrivateKey,
42-
mixHeader *[routingInfoSize]byte) error {
43+
mixHeader []byte) error {
4344

4445
// First, we'll generate a new key that'll be used to generate some
4546
// random bytes for our padding purposes. To derive this new key, we
@@ -55,7 +56,8 @@ func DeterministicPacketFiller(sessionKey *btcec.PrivateKey,
5556
if err != nil {
5657
return err
5758
}
58-
padCipher.XORKeyStream(mixHeader[:], mixHeader[:])
59+
60+
padCipher.XORKeyStream(mixHeader, mixHeader)
5961

6062
return nil
6163
}

0 commit comments

Comments
 (0)