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