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 *);