Remove a useless memcpy in mud_ctrl_path()
This commit is contained in:
43
mud.c
43
mud.c
@@ -697,6 +697,9 @@ int mud_encrypt (struct mud *mud, uint64_t nonce,
|
|||||||
const unsigned char *src, size_t src_size,
|
const unsigned char *src, size_t src_size,
|
||||||
size_t ad_size)
|
size_t ad_size)
|
||||||
{
|
{
|
||||||
|
if (!nonce)
|
||||||
|
return 0;
|
||||||
|
|
||||||
if (ad_size > src_size)
|
if (ad_size > src_size)
|
||||||
ad_size = src_size;
|
ad_size = src_size;
|
||||||
|
|
||||||
@@ -719,15 +722,11 @@ int mud_encrypt (struct mud *mud, uint64_t nonce,
|
|||||||
if (src)
|
if (src)
|
||||||
memcpy(dst+MUD_TIME_SIZE, src, ad_size);
|
memcpy(dst+MUD_TIME_SIZE, src, ad_size);
|
||||||
|
|
||||||
if (nonce) {
|
|
||||||
if (mud->crypto.use_next) {
|
if (mud->crypto.use_next) {
|
||||||
mud_encrypt_opt(&mud->crypto.next, &opt);
|
mud_encrypt_opt(&mud->crypto.next, &opt);
|
||||||
} else {
|
} else {
|
||||||
mud_encrypt_opt(&mud->crypto.current, &opt);
|
mud_encrypt_opt(&mud->crypto.current, &opt);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
mud_encrypt_opt(&mud->crypto.private, &opt);
|
|
||||||
}
|
|
||||||
|
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
@@ -836,30 +835,36 @@ static
|
|||||||
void mud_ctrl_path (struct mud *mud, enum mud_msg msg, struct path *path,
|
void mud_ctrl_path (struct mud *mud, enum mud_msg msg, struct path *path,
|
||||||
uint64_t now)
|
uint64_t now)
|
||||||
{
|
{
|
||||||
unsigned char data[256];
|
struct {
|
||||||
unsigned char ctrl[sizeof(data)+MUD_PACKET_MIN_SIZE];
|
unsigned char zero[MUD_TIME_SIZE];
|
||||||
size_t size = MUD_TIME_SIZE;
|
unsigned char time[MUD_TIME_SIZE];
|
||||||
|
unsigned char data[128+MUD_MAC_SIZE];
|
||||||
|
} ctrl;
|
||||||
|
|
||||||
mud_write48(data, now);
|
size_t size = 0;
|
||||||
|
|
||||||
|
memset(ctrl.zero, 0, MUD_TIME_SIZE);
|
||||||
|
mud_write48(ctrl.time, now);
|
||||||
|
|
||||||
if (msg == mud_pong) {
|
if (msg == mud_pong) {
|
||||||
mud_write48(&data[MUD_TIME_SIZE], path->recv_send_time);
|
mud_write48(&ctrl.data[0], path->recv_send_time);
|
||||||
mud_write48(&data[MUD_TIME_SIZE*2], path->rdt);
|
mud_write48(&ctrl.data[MUD_TIME_SIZE], path->rdt);
|
||||||
size += MUD_TIME_SIZE*2;
|
size = MUD_TIME_SIZE*2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg == mud_keyx) {
|
if (msg == mud_keyx) {
|
||||||
memcpy(&data[MUD_TIME_SIZE], &mud->crypto.public,
|
memcpy(ctrl.data, &mud->crypto.public, sizeof(mud->crypto.public));
|
||||||
sizeof(mud->crypto.public));
|
size = sizeof(mud->crypto.public);
|
||||||
size += sizeof(mud->crypto.public);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ret = mud_encrypt(mud, 0, ctrl, sizeof(ctrl), data, size, size);
|
struct crypto_opt opt = {
|
||||||
|
.dst = ctrl.data+size,
|
||||||
|
.ad = { .data = ctrl.zero,
|
||||||
|
.size = size+2*MUD_TIME_SIZE },
|
||||||
|
};
|
||||||
|
|
||||||
if (ret <= 0)
|
mud_encrypt_opt(&mud->crypto.private, &opt);
|
||||||
return;
|
mud_send_path(mud, path, now, &ctrl, size+2*MUD_TIME_SIZE+MUD_MAC_SIZE);
|
||||||
|
|
||||||
mud_send_path(mud, path, now, ctrl, ret);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
|
|||||||
Reference in New Issue
Block a user