common/sphinx: make onionpacket.routinginfo a dynamic member.

Still asserts that it's the standard size, but makes it a dynamic
member.  For simpliciy, changes the parse_onionpacket API (it must be
a tal object now, so we might as well allocate it here to catch all
the callers).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2020-12-08 21:05:32 +10:30
committed by Christian Decker
parent 3776af4a35
commit 32c7c133f4
13 changed files with 118 additions and 95 deletions

View File

@@ -206,7 +206,7 @@ int main(int argc, char **argv)
struct privkey privkey;
struct pubkey blinding;
u8 onion[TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE)], *dec;
struct onionpacket op;
struct onionpacket *op;
struct secret ss, onion_ss;
struct secret hmac, rho;
struct route_step *rs;
@@ -216,6 +216,7 @@ int main(int argc, char **argv)
struct pubkey res;
struct sha256 h;
int ret;
enum onion_wire failcode;
const unsigned char npub[crypto_aead_chacha20poly1305_ietf_NPUBBYTES] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
if (argc != 5)
@@ -232,7 +233,8 @@ int main(int argc, char **argv)
if (!pubkey_from_hexstr(argv[4], strlen(argv[4]), &blinding))
errx(1, "Invalid blinding %s", argv[4]);
if (parse_onionpacket(onion, sizeof(onion), &op) != 0)
op = parse_onionpacket(tmpctx, onion, sizeof(onion), &failcode);
if (!op)
errx(1, "Unparsable onion");
/* ss(r) = H(k(r) * E(r)) */
@@ -249,7 +251,7 @@ int main(int argc, char **argv)
* and use our raw privkey: this models how lightningd
* will do it, since hsmd knows only how to ECDH with
* our real key */
res = op.ephemeralkey;
res = op->ephemeralkey;
if (!first) {
if (secp256k1_ec_pubkey_tweak_mul(secp256k1_ctx,
&res.pubkey,
@@ -262,7 +264,7 @@ int main(int argc, char **argv)
privkey.secret.data, NULL, NULL) != 1)
abort();
rs = process_onionpacket(tmpctx, &op, &onion_ss, NULL, 0, false);
rs = process_onionpacket(tmpctx, op, &onion_ss, NULL, 0, false);
if (!rs)
errx(1, "Could not process onionpacket");

View File

@@ -102,7 +102,7 @@ static void do_generate(int argc, char **argv,
}
}
packet = create_onionpacket(ctx, sp, &shared_secrets);
packet = create_onionpacket(ctx, sp, ROUTING_INFO_SIZE, &shared_secrets);
if (rvnode_id != NULL) {
comp = sphinx_compress(ctx, packet, sp);
@@ -123,21 +123,21 @@ static struct route_step *decode_with_privkey(const tal_t *ctx, const u8 *onion,
{
struct privkey seckey;
struct route_step *step;
struct onionpacket packet;
struct onionpacket *packet;
enum onion_wire why_bad;
struct secret shared_secret;
if (!hex_decode(hexprivkey, strlen(hexprivkey), &seckey, sizeof(seckey)))
errx(1, "Invalid private key hex '%s'", hexprivkey);
why_bad = parse_onionpacket(onion, TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE), &packet);
packet = parse_onionpacket(tmpctx, onion, TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE), &why_bad);
if (why_bad != 0)
if (!packet)
errx(1, "Error parsing message: %s", onion_wire_name(why_bad));
if (!onion_shared_secret(&shared_secret, &packet, &seckey))
if (!onion_shared_secret(&shared_secret, packet, &seckey))
errx(1, "Error creating shared secret.");
step = process_onionpacket(ctx, &packet, &shared_secret, assocdata,
step = process_onionpacket(ctx, packet, &shared_secret, assocdata,
tal_bytelen(assocdata), true);
return step;
@@ -257,7 +257,7 @@ static void runtest(const char *filename)
}
sphinx_add_hop(path, &pubkey, full);
}
res = create_onionpacket(ctx, path, &shared_secrets);
res = create_onionpacket(ctx, path, ROUTING_INFO_SIZE, &shared_secrets);
serialized = serialize_onionpacket(ctx, res);
if (!serialized)