77 "crypto/sha256"
88 "encoding/binary"
99 "io"
10- "io/ioutil"
1110 "math/big"
1211
1312 "github.com/aead/chacha20"
@@ -38,7 +37,7 @@ const (
3837
3938 // hopDataSize is the fixed size of hop_data. BOLT 04 currently
4039 // specifies this to be 1 byte realm, 8 byte channel_id, 8 byte amount
41- // to forward, 4 byte outgoing CLTV value, 16 bytes padding and 32
40+ // to forward, 4 byte outgoing CLTV value, 12 bytes padding and 32
4241 // bytes HMAC for a total of 65 bytes per hop.
4342 hopDataSize = (1 + addressSize + 8 + 4 + padSize + hmacSize )
4443
@@ -71,15 +70,9 @@ const (
7170// the output of a SHA256 hash.
7271type Hash256 [sha256 .Size ]byte
7372
74- var (
75- // paddingBytes are the padding bytes used to fill out the remainder of the
76- // unused portion of the per-hop payload.
77- paddingBytes [padSize ]byte
78-
79- // zeroHMAC is the special HMAC value that allows the final node to
80- // determine if it is the payment destination or not.
81- zeroHMAC [hmacSize ]byte
82- )
73+ // zeroHMAC is the special HMAC value that allows the final node to determine
74+ // if it is the payment destination or not.
75+ var zeroHMAC [hmacSize ]byte
8376
8477// OnionPacket is the onion wrapped hop-to-hop routing information necessary to
8578// propagate a message through the mix-net without intermediate nodes having
@@ -140,6 +133,13 @@ type HopData struct {
140133 // should be included in the HTLC forwarded.
141134 OutgoingCltv uint32
142135
136+ // ExtraBytes is the set of unused bytes within the onion payload. This
137+ // extra set of bytes can be utilized by higher level applications to
138+ // package additional data within the per-hop payload, or signal that a
139+ // portion of the remaining set of hops are to be consumed as Extra
140+ // Onion Blobs.
141+ ExtraBytes [padSize ]byte
142+
143143 // HMAC is an HMAC computed over the entire per-hop payload that also
144144 // includes the higher-level (optional) associated data bytes.
145145 HMAC [hmacSize ]byte
@@ -164,7 +164,7 @@ func (hd *HopData) Encode(w io.Writer) error {
164164 return err
165165 }
166166
167- if _ , err := w .Write (paddingBytes [:]); err != nil {
167+ if _ , err := w .Write (hd . ExtraBytes [:]); err != nil {
168168 return err
169169 }
170170
@@ -194,7 +194,7 @@ func (hd *HopData) Decode(r io.Reader) error {
194194 return err
195195 }
196196
197- if _ , err := io .CopyN ( ioutil . Discard , r , padSize ); err != nil {
197+ if _ , err := io .ReadFull ( r , hd . ExtraBytes [:] ); err != nil {
198198 return err
199199 }
200200
0 commit comments