sphinx: Parameterizing the HMAC size

Should have done this a long time ago...
This commit is contained in:
Christian Decker 2017-04-13 16:22:15 -07:00
parent 652d999dbd
commit 4a468af378
2 changed files with 10 additions and 9 deletions

View File

@ -1,4 +1,4 @@
#include "sphinx.h"
#include "lightningd/sphinx.h"
#include "utils.h"
#include <assert.h>
@ -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];

View File

@ -11,16 +11,17 @@
#include <sodium/randombytes.h>
#include <wire/wire.h>
#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
*/