| 273 | } |
| 274 | |
| 275 | static 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. */ |
| 317 | static void *opt_allocfn(size_t size) |
no test coverage detected