Browse Source

sphinx: Migrate sphinx compression to new interface

It also removes the duplicate compression code and serialization code.
travis-debug
Christian Decker 5 years ago
committed by Rusty Russell
parent
commit
ef86ee0bae
  1. 26
      common/sphinx.c
  2. 9
      common/sphinx.h
  3. 18
      devtools/onion.c

26
common/sphinx.c

@ -149,30 +149,6 @@ u8 *serialize_onionpacket(
return dst; return dst;
} }
u8 *serialize_compressed_onion(const tal_t *ctx,
const struct sphinx_path *sp,
const struct onionpacket *packet)
{
u8 *dst;
u8 der[PUBKEY_CMPR_LEN];
size_t payloads_size = sphinx_path_payloads_size(sp);
size_t max_prefill = ROUTING_INFO_SIZE - payloads_size;
size_t rv_onion_size = TOTAL_PACKET_SIZE - max_prefill;
int p = 0;
assert(sp->rendezvous_id != NULL);
dst = tal_arr(ctx, u8, rv_onion_size);
pubkey_to_der(der, &packet->ephemeralkey);
write_buffer(dst, &packet->version, 1, &p);
write_buffer(dst, der, sizeof(der), &p);
write_buffer(dst, packet->routinginfo, ROUTING_INFO_SIZE - max_prefill, &p);
write_buffer(dst, packet->mac, sizeof(packet->mac), &p);
return dst;
}
enum onion_type parse_onionpacket(const u8 *src, enum onion_type parse_onionpacket(const u8 *src,
const size_t srclen, const size_t srclen,
struct onionpacket *dest) struct onionpacket *dest)
@ -810,7 +786,7 @@ sphinx_compress(const tal_t *ctx, const struct onionpacket *packet,
size_t payloads_size = sphinx_path_payloads_size(path); size_t payloads_size = sphinx_path_payloads_size(path);
/* We can't compress an onion that doesn't have a rendez-vous node. */ /* We can't compress an onion that doesn't have a rendez-vous node. */
if (path->rendezvous_id) if (path->rendezvous_id == NULL)
return NULL; return NULL;
res = tal(ctx, struct sphinx_compressed_onion); res = tal(ctx, struct sphinx_compressed_onion);

9
common/sphinx.h

@ -234,15 +234,6 @@ void sphinx_add_hop(struct sphinx_path *path, const struct pubkey *pubkey,
*/ */
size_t sphinx_path_payloads_size(const struct sphinx_path *path); size_t sphinx_path_payloads_size(const struct sphinx_path *path);
/**
* Compress a rendez-vous onion by removing the unused blinded middle
* part. This middle part can be regenerated by the node processing this
* onion.
*/
u8 *serialize_compressed_onion(const tal_t *ctx,
const struct sphinx_path *sp,
const struct onionpacket *packet);
/** /**
* Set the rendez-vous node_id and make the onion generated from the * Set the rendez-vous node_id and make the onion generated from the
* sphinx_path compressible. To unset pass in a NULL rendezvous_id. * sphinx_path compressible. To unset pass in a NULL rendezvous_id.

18
devtools/onion.c

@ -32,7 +32,9 @@ static void do_generate(int argc, char **argv,
struct secret session_key; struct secret session_key;
struct secret *shared_secrets; struct secret *shared_secrets;
struct sphinx_path *sp; struct sphinx_path *sp;
struct sphinx_compressed_onion *comp;
u8 *serialized;
struct onionpacket *packet;
const u8* tmp_assocdata =tal_dup_arr(ctx, u8, assocdata, const u8* tmp_assocdata =tal_dup_arr(ctx, u8, assocdata,
ASSOC_DATA_SIZE, 0); ASSOC_DATA_SIZE, 0);
memset(&session_key, 'A', sizeof(struct secret)); memset(&session_key, 'A', sizeof(struct secret));
@ -93,13 +95,17 @@ static void do_generate(int argc, char **argv,
} }
} }
struct onionpacket *res = create_onionpacket(ctx, sp, &shared_secrets); packet = create_onionpacket(ctx, sp, &shared_secrets);
if (rvnode_id != NULL) if (rvnode_id != NULL) {
printf("Rendezvous onion: %s\n", comp = sphinx_compress(ctx, packet, sp);
tal_hex(ctx, serialize_compressed_onion(ctx, sp, res))); serialized = sphinx_compressed_onion_serialize(ctx, comp);
printf("Rendezvous onion: %s\n", tal_hex(ctx, serialized));
} else {
assert(sphinx_compress(ctx, packet, sp) == NULL);
}
u8 *serialized = serialize_onionpacket(ctx, res); serialized = serialize_onionpacket(ctx, packet);
if (!serialized) if (!serialized)
errx(1, "Error serializing message."); errx(1, "Error serializing message.");
printf("%s\n", tal_hex(ctx, serialized)); printf("%s\n", tal_hex(ctx, serialized));

Loading…
Cancel
Save