MCPcopy Create free account
hub / github.com/ElementsProject/lightning / decompress

Function decompress

devtools/onion.c:275–314  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

273}
274
275static void decompress(char *hexprivkey, char *hexonion)
276{
277 struct privkey rendezvous_key;
278 size_t onionlen = hex_data_size(strlen(hexonion));
279 u8 *compressed;
280 struct pubkey ephkey;
281 struct secret shared_secret;
282 struct onionpacket *onion;
283 struct sphinx_compressed_onion *tinyonion;
284
285 if (!hex_decode(hexprivkey, strlen(hexprivkey), &rendezvous_key, sizeof(rendezvous_key)))
286 errx(1, "Invalid private key hex '%s'", hexprivkey);
287
288 compressed = tal_arr(NULL, u8, onionlen);
289 if (!hex_decode(hexonion, strlen(hexonion), compressed, onionlen))
290 errx(1, "Invalid onion hex '%s'", hexonion);
291
292 if (onionlen < HMAC_SIZE + 1 + PUBKEY_SIZE)
293 errx(1, "Onion is too short to contain the version, ephemeral key and HMAC");
294
295 pubkey_from_der(compressed + 1, PUBKEY_SIZE, &ephkey);
296
297 tinyonion = sphinx_compressed_onion_deserialize(NULL, compressed);
298 if (tinyonion == NULL)
299 errx(1, "Could not deserialize compressed onion");
300
301 if (!sphinx_create_shared_secret(&shared_secret,
302 &tinyonion->ephemeralkey,
303 &rendezvous_key.secret))
304 errx(1,
305 "Could not generate shared secret from ephemeral key %s "
306 "and private key %s",
307 pubkey_to_hexstr(NULL, &ephkey), hexprivkey);
308
309 onion = sphinx_decompress(NULL, tinyonion, &shared_secret);
310 if (onion == NULL)
311 errx(1, "Could not decompress compressed onion");
312
313 printf("Decompressed Onion: %s\n", tal_hex(NULL, serialize_onionpacket(NULL, onion)));
314}
315
316/* Tal wrappers for opt. */
317static void *opt_allocfn(size_t size)

Callers 1

mainFunction · 0.85

Calls 10

hex_data_sizeFunction · 0.85
hex_decodeFunction · 0.85
errxFunction · 0.85
pubkey_from_derFunction · 0.85
pubkey_to_hexstrFunction · 0.85
sphinx_decompressFunction · 0.85
tal_hexFunction · 0.85
serialize_onionpacketFunction · 0.50

Tested by

no test coverage detected