@@ -233,11 +233,55 @@ static void run_unit_tests(void)
233
233
assert (origin_index == 4 );
234
234
}
235
235
236
+ static void run_unit_tests_from_bolt (void ) {
237
+ struct onionreply * reply ;
238
+ u8 * oreply ;
239
+ char * s = "400f0000000000000064000c3500fd84d1fd012c8080808080808080808" ;
240
+ u8 * raw = tal_hexdata (tmpctx , s , strlen (s ));
241
+ int origin_index ;
242
+
243
+ /* Shared secrets we already have from the forward path */
244
+ char * secrets [] = {
245
+ "53eb63ea8a3fec3b3cd433b85cd62a4b145e1dda09391b348c4e1cd36a03ea66" ,
246
+ "a6519e98832a0b179f62123b3567c106db99ee37bef036e783263602f3488fae" ,
247
+ "3a6b412548762f0dbccce5c7ae7bb8147d1caf9b5471c34120b30bc9c04891cc" ,
248
+ "21e13c2d7cfe7e18836df50872466117a295783ab8aab0e7ecc8c725503ad02d" ,
249
+ "b5756b9b542727dbafc6765a49488b023a725d631af688fc031217e90770c328" ,
250
+ };
251
+ struct secret ss [] = {
252
+ secret_from_hex (secrets [0 ]),
253
+ secret_from_hex (secrets [1 ]),
254
+ secret_from_hex (secrets [2 ]),
255
+ secret_from_hex (secrets [3 ]),
256
+ secret_from_hex (secrets [4 ])
257
+ };
258
+
259
+ reply = create_onionreply (tmpctx , & ss [4 ], raw );
260
+ update_attributable_data (reply , 1 , & ss [4 ]);
261
+ reply = wrap_onionreply (tmpctx , & ss [4 ], reply );
262
+
263
+ for (int i = 3 ; i >= 0 ; i -- ) {
264
+ u32 hold_time = 5 - i ;
265
+ update_attributable_data (reply , hold_time , & ss [i ]);
266
+ reply = wrap_onionreply (tmpctx , & ss [i ], reply );
267
+
268
+ printf ("obfuscated packet %s\n" , tal_hex (tmpctx , reply -> contents ));
269
+ printf ("obfuscated hold_times %s\n" , tal_hex (tmpctx , reply -> htlc_hold_time ));
270
+ printf ("obfuscated trunHMACs %s\n" , tal_hex (tmpctx , reply -> truncated_hmac ));
271
+ }
272
+
273
+ oreply = unwrap_onionreply (tmpctx , ss , 5 , reply , & origin_index );
274
+
275
+ assert (tal_arr_eq (oreply , raw ));
276
+ assert (origin_index == 4 );
277
+ }
278
+
236
279
int main (int argc , char * * argv )
237
280
{
238
281
common_setup (argv [0 ]);
239
282
run_unit_tests ();
240
283
284
+ run_unit_tests_from_bolt ();
241
285
common_shutdown ();
242
286
return 0 ;
243
287
}
0 commit comments