From 522ca2804d7087fa6d3fa1506db03afc465557c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Gallou=C3=ABt?= Date: Wed, 15 Nov 2017 22:04:44 +0000 Subject: [PATCH] Add mud_new_key() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Adrien Gallouët --- mud.c | 17 +++++++++-------- mud.h | 1 + 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/mud.c b/mud.c index 69a121f..88869e8 100644 --- a/mud.c +++ b/mud.c @@ -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; diff --git a/mud.h b/mud.h index b195030..eedbe9c 100644 --- a/mud.h +++ b/mud.h @@ -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 *);