From 4a468af378a1e630da234f1855f27b6cb94b7545 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Thu, 13 Apr 2017 16:22:15 -0700 Subject: [PATCH] sphinx: Parameterizing the HMAC size Should have done this a long time ago... --- lightningd/sphinx.c | 10 +++++----- lightningd/sphinx.h | 9 +++++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lightningd/sphinx.c b/lightningd/sphinx.c index 7e8097001..85e022430 100644 --- a/lightningd/sphinx.c +++ b/lightningd/sphinx.c @@ -1,4 +1,4 @@ -#include "sphinx.h" +#include "lightningd/sphinx.h" #include "utils.h" #include @@ -101,7 +101,7 @@ struct onionpacket *parse_onionpacket( return tal_free(m); read_buffer(&m->routinginfo, src, ROUTING_INFO_SIZE, &p); - read_buffer(&m->mac, src, 20, &p); + read_buffer(&m->mac, src, SECURITY_PARAMETER, &p); return m; } @@ -151,7 +151,7 @@ static void compute_packet_hmac(const struct onionpacket *packet, write_buffer(mactemp, assocdata, assocdatalen, &pos); compute_hmac(mac, mactemp, sizeof(mactemp), mukey, KEY_LEN); - memcpy(hmac, mac, 20); + memcpy(hmac, mac, SECURITY_PARAMETER); } static bool generate_key(void *k, const char *t, u8 tlen, const u8 *s) @@ -375,7 +375,7 @@ struct onionpacket *create_onionpacket( if (!params) return NULL; packet->version = 1; - memset(nexthmac, 0, 20); + memset(nexthmac, 0, SECURITY_PARAMETER); memset(packet->routinginfo, 0, ROUTING_INFO_SIZE); generate_header_padding(filler, sizeof(filler), HOP_DATA_SIZE, @@ -418,7 +418,7 @@ struct route_step *process_onionpacket( ) { struct route_step *step = talz(ctx, struct route_step); - u8 hmac[20]; + u8 hmac[SECURITY_PARAMETER]; struct keyset keys; u8 blind[BLINDING_FACTOR_SIZE]; u8 stream[NUM_STREAM_BYTES]; diff --git a/lightningd/sphinx.h b/lightningd/sphinx.h index 08c4b5551..cd1da4c08 100644 --- a/lightningd/sphinx.h +++ b/lightningd/sphinx.h @@ -11,16 +11,17 @@ #include #include -#define SECURITY_PARAMETER 20 +#define SECURITY_PARAMETER 32 #define NUM_MAX_HOPS 20 -#define HOP_DATA_SIZE 53 +#define PAYLOAD_SIZE 32 +#define HOP_DATA_SIZE (1 + SECURITY_PARAMETER + PAYLOAD_SIZE) #define ROUTING_INFO_SIZE (HOP_DATA_SIZE * NUM_MAX_HOPS) #define TOTAL_PACKET_SIZE (1 + 33 + SECURITY_PARAMETER + ROUTING_INFO_SIZE) struct onionpacket { /* Cleartext information */ u8 version; - u8 mac[20]; + u8 mac[SECURITY_PARAMETER]; secp256k1_pubkey ephemeralkey; /* Encrypted information */ @@ -74,7 +75,7 @@ struct route_step { * @hoppayloads: payloads destined for individual hosts (limited to * HOP_PAYLOAD_SIZE bytes) * @num_hops: path length in nodes - * @sessionkey: 20 byte random session key to derive secrets from + * @sessionkey: 32 byte random session key to derive secrets from * @assocdata: associated data to commit to in HMACs * @assocdatalen: length of the assocdata */