@@ -117,7 +117,7 @@ type OnionPacket struct {
117117// generateSharedSecrets by the given nodes pubkeys, generates the shared
118118// secrets.
119119func generateSharedSecrets (paymentPath []* btcec.PublicKey ,
120- sessionKey * btcec.PrivateKey ) []Hash256 {
120+ sessionKey * btcec.PrivateKey ) ( []Hash256 , error ) {
121121
122122 // Each hop performs ECDH with our ephemeral key pair to arrive at a
123123 // shared secret. Additionally, each hop randomizes the group element
@@ -131,8 +131,14 @@ func generateSharedSecrets(paymentPath []*btcec.PublicKey,
131131 // Within the loop each new triplet will be computed recursively based
132132 // off of the blinding factor of the last hop.
133133 lastEphemeralPubKey := sessionKey .PubKey ()
134- hopSharedSecrets [0 ] = generateSharedSecret (paymentPath [0 ], sessionKey )
135- lastBlindingFactor := computeBlindingFactor (lastEphemeralPubKey , hopSharedSecrets [0 ][:])
134+ sharedSecret , err := generateSharedSecret (paymentPath [0 ], sessionKey )
135+ if err != nil {
136+ return nil , err
137+ }
138+ hopSharedSecrets [0 ] = sharedSecret
139+ lastBlindingFactor := computeBlindingFactor (
140+ lastEphemeralPubKey , hopSharedSecrets [0 ][:],
141+ )
136142
137143 // The cached blinding factor will contain the running product of the
138144 // session private key x and blinding factors b_i, computed as
@@ -184,7 +190,7 @@ func generateSharedSecrets(paymentPath []*btcec.PublicKey,
184190 )
185191 }
186192
187- return hopSharedSecrets
193+ return hopSharedSecrets , nil
188194}
189195
190196// NewOnionPacket creates a new onion packet which is capable of obliviously
@@ -211,9 +217,12 @@ func NewOnionPacket(paymentPath *PaymentPath, sessionKey *btcec.PrivateKey,
211217 return nil , fmt .Errorf ("packet filler must be specified" )
212218 }
213219
214- hopSharedSecrets := generateSharedSecrets (
220+ hopSharedSecrets , err := generateSharedSecrets (
215221 paymentPath .NodeKeys (), sessionKey ,
216222 )
223+ if err != nil {
224+ return nil , fmt .Errorf ("error generating shared secret: %v" , err )
225+ }
217226
218227 // Generate the padding, called "filler strings" in the paper.
219228 filler := generateHeaderPadding ("rho" , paymentPath , hopSharedSecrets )
0 commit comments