Browse Source

sphinx: Removing last vestiges of the end-to-end payload

So far this was simply set to a zero-length end-to-end payload. We
don't have any plans of re-adding it for the moment, so let's get rid
of the unused code.
ppa-0.6.1
Christian Decker 8 years ago
committed by Rusty Russell
parent
commit
91b17d45d8
  1. 4
      daemon/pay.c
  2. 5
      daemon/peer.c
  3. 43
      daemon/sphinx.c
  4. 11
      daemon/sphinx.h
  5. 4
      test/test_sphinx.c

4
daemon/pay.c

@ -442,9 +442,7 @@ static void json_sendpay(struct command *cmd,
randombytes_buf(&sessionkey, sizeof(sessionkey));
/* Onion will carry us from first peer onwards. */
packet = create_onionpacket(
cmd, ids, hoppayloads,
sessionkey, (u8*)"", 0);
packet = create_onionpacket(cmd, ids, hoppayloads, sessionkey);
onion = serialize_onionpacket(cmd, packet);
if (pc)

5
daemon/peer.c

@ -4730,10 +4730,7 @@ static void json_newhtlc(struct command *cmd,
hoppayloads = tal_arrz(cmd, struct hoppayload, 1);
memcpy(&path[0], peer->id, sizeof(struct pubkey));
randombytes_buf(&sessionkey, sizeof(sessionkey));
packet = create_onionpacket(
cmd,
path,
hoppayloads, sessionkey, (u8*)"", 0);
packet = create_onionpacket(cmd, path, hoppayloads, sessionkey);
onion = serialize_onionpacket(cmd, packet);
log_debug(peer->log, "JSON command to add new HTLC");

43
daemon/sphinx.c

@ -70,7 +70,6 @@ u8 *serialize_onionpacket(
write_buffer(dst, m->mac, sizeof(m->mac), &p);
write_buffer(dst, m->routinginfo, ROUTING_INFO_SIZE, &p);
write_buffer(dst, m->hoppayloads, TOTAL_HOP_PAYLOAD_SIZE, &p);
write_buffer(dst, m->payload, MESSAGE_SIZE, &p);
return dst;
}
@ -102,7 +101,6 @@ struct onionpacket *parse_onionpacket(
read_buffer(&m->mac, src, 20, &p);
read_buffer(&m->routinginfo, src, ROUTING_INFO_SIZE, &p);
read_buffer(&m->hoppayloads, src, TOTAL_HOP_PAYLOAD_SIZE, &p);
read_buffer(m->payload, src, MESSAGE_SIZE, &p);
return m;
}
@ -135,27 +133,6 @@ static void xorbytes(uint8_t *d, const uint8_t *a, const uint8_t *b, size_t len)
d[i] = a[i] ^ b[i];
}
/*
* Encrypt a message `m` of length `mlen` with key `key` and store the
* ciphertext in `c`. `c` must be pre-allocated to at least `mlen` bytes.
*/
static void stream_encrypt(void *c, const void *m, const size_t mlen, const u8 *key)
{
u8 nonce[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
memcheck(c, mlen);
crypto_stream_chacha20_xor(c, m, mlen, nonce, key);
}
/*
* Decrypt a ciphertext `c` of length `clen` with key `key` and store the
* cleartext in `m`. `m` must be pre-allocated to at least `clen` bytes.
*/
static void stream_decrypt(void *m, const void *c, const size_t clen, const u8 *key)
{
stream_encrypt(m, c, clen, key);
}
/*
* Generate a pseudo-random byte stream of length `dstlen` from key `k` and
* store it in `dst`. `dst must be at least `dstlen` bytes long.
@ -184,12 +161,11 @@ static bool compute_hmac(
static void compute_packet_hmac(const struct onionpacket *packet, u8 *mukey, u8 *hmac)
{
u8 mactemp[ROUTING_INFO_SIZE + TOTAL_HOP_PAYLOAD_SIZE + MESSAGE_SIZE];
u8 mactemp[ROUTING_INFO_SIZE + TOTAL_HOP_PAYLOAD_SIZE];
u8 mac[32];
memcpy(mactemp, packet->routinginfo, ROUTING_INFO_SIZE);
memcpy(mactemp + ROUTING_INFO_SIZE, packet->hoppayloads, TOTAL_HOP_PAYLOAD_SIZE);
memcpy(mactemp + ROUTING_INFO_SIZE + TOTAL_HOP_PAYLOAD_SIZE, packet->payload, sizeof(packet->payload));
compute_hmac(mac, mactemp, sizeof(mactemp), mukey, KEY_LEN);
memcpy(hmac, mac, 20);
}
@ -364,9 +340,7 @@ struct onionpacket *create_onionpacket(
const tal_t *ctx,
struct pubkey *path,
struct hoppayload hoppayloads[],
const u8 *sessionkey,
const u8 *message,
const size_t messagelen
const u8 *sessionkey
)
{
struct onionpacket *packet = talz(ctx, struct onionpacket);
@ -382,15 +356,6 @@ struct onionpacket *create_onionpacket(
for (i = 0; i < num_hops; i++)
serialize_hoppayload(binhoppayloads[i], &hoppayloads[i]);
if (MESSAGE_SIZE > messagelen) {
memset(&packet->hoppayloads, 0, TOTAL_HOP_PAYLOAD_SIZE);
#if MESSAGE_SIZE != 0 /* Suppress GCC warning about 0-length memset */
memset(&packet->payload, 0xFF, MESSAGE_SIZE);
#endif
memcpy(&packet->payload, message, messagelen);
packet->payload[messagelen] = 0x7f;
}
if (!params)
return NULL;
packet->version = 1;
@ -429,9 +394,6 @@ struct onionpacket *create_onionpacket(
memcpy(packet->hoppayloads + len, hopfiller, sizeof(hopfiller));
}
/* Obfuscate end-to-end payload */
stream_encrypt(packet->payload, packet->payload, sizeof(packet->payload), keys.pi);
compute_packet_hmac(packet, keys.mu, nexthmac);
pubkey_hash160(nextaddr, &path[i]);
}
@ -497,7 +459,6 @@ struct route_step *process_onionpacket(
paddedheader + SECURITY_PARAMETER,
SECURITY_PARAMETER);
stream_decrypt(step->next->payload, msg->payload, sizeof(msg->payload), keys.pi);
memcpy(&step->next->routinginfo, paddedheader + 2 * SECURITY_PARAMETER, ROUTING_INFO_SIZE);
if (memeqzero(step->next->mac, sizeof(step->next->mac))) {

11
daemon/sphinx.h

@ -14,10 +14,9 @@
#define NUM_MAX_HOPS 20
#define HOP_PAYLOAD_SIZE 20
#define TOTAL_HOP_PAYLOAD_SIZE (NUM_MAX_HOPS * HOP_PAYLOAD_SIZE)
#define MESSAGE_SIZE 0
#define ROUTING_INFO_SIZE (2 * NUM_MAX_HOPS * SECURITY_PARAMETER)
#define TOTAL_PACKET_SIZE (1 + 33 + SECURITY_PARAMETER + ROUTING_INFO_SIZE + \
TOTAL_HOP_PAYLOAD_SIZE + MESSAGE_SIZE)
TOTAL_HOP_PAYLOAD_SIZE)
struct onionpacket {
/* Cleartext information */
@ -29,7 +28,6 @@ struct onionpacket {
/* Encrypted information */
u8 routinginfo[ROUTING_INFO_SIZE];
u8 hoppayloads[TOTAL_HOP_PAYLOAD_SIZE];
u8 payload[MESSAGE_SIZE];
};
enum route_next_case {
@ -46,7 +44,6 @@ struct hoppayload {
struct route_step {
enum route_next_case nextcase;
struct onionpacket *next;
u8 *payload;
struct hoppayload *hoppayload;
};
@ -60,16 +57,12 @@ struct route_step {
* HOP_PAYLOAD_SIZE bytes)
* @num_hops: path length in nodes
* @sessionkey: 20 byte random session key to derive secrets from
* @message: end-to-end payload destined for the final recipient
* @messagelen: length of @message
*/
struct onionpacket *create_onionpacket(
const tal_t * ctx,
struct pubkey path[],
struct hoppayload hoppayloads[],
const u8 * sessionkey,
const u8 * message,
const size_t messagelen
const u8 * sessionkey
);
/**

4
test/test_sphinx.c

@ -56,9 +56,7 @@ int main(int argc, char **argv)
struct onionpacket *res = create_onionpacket(ctx,
path,
hoppayloads,
sessionkey,
(u8*)"testing",
7);
sessionkey);
u8 *serialized = serialize_onionpacket(ctx, res);
if (!serialized)

Loading…
Cancel
Save