Add mud_new_key()

Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
This commit is contained in:
Adrien Gallouët
2017-11-15 22:04:44 +00:00
parent 78b76437e5
commit 522ca2804d
2 changed files with 10 additions and 8 deletions

17
mud.c
View File

@@ -577,6 +577,15 @@ mud_set_key(struct mud *mud, unsigned char *key, size_t size)
return 0;
}
int
mud_new_key(struct mud *mud)
{
unsigned char key[MUD_KEY_SIZE];
randombytes_buf(key, sizeof(key));
return mud_set_key(mud, key, sizeof(key));
}
int
mud_set_tc(struct mud *mud, int tc)
{
@@ -790,17 +799,9 @@ mud_create(int port, int v4, int v6, int aes, int mtu)
mud->send_timeout = MUD_SEND_TIMEOUT;
mud->time_tolerance = MUD_TIME_TOLERANCE;
mud->tc = MUD_PACKET_TC;
unsigned char key[MUD_KEY_SIZE];
randombytes_buf(key, sizeof(key));
mud_set_key(mud, key, sizeof(key));
mud->crypto.aes = aes && crypto_aead_aes256gcm_is_available();
mud_keyx_init(mud, now);
randombytes_buf(mud->kiss, sizeof(mud->kiss));
mud_set_mtu(mud, mtu);
return mud;

1
mud.h
View File

@@ -9,6 +9,7 @@ void mud_delete (struct mud *);
int mud_get_fd (struct mud *);
int mud_new_key (struct mud *);
int mud_set_key (struct mud *, unsigned char *, size_t);
int mud_get_key (struct mud *, unsigned char *, size_t *);