diff --git a/toxcore/DHT.h b/toxcore/DHT.h index c37511a1..52aad266 100644 --- a/toxcore/DHT.h +++ b/toxcore/DHT.h @@ -25,6 +25,7 @@ #define DHT_H #include "crypto_core.h" +#include "network.h" /* Size of the client_id in bytes. */ #define CLIENT_ID_SIZE crypto_box_PUBLICKEYBYTES diff --git a/toxcore/Lossless_UDP.h b/toxcore/Lossless_UDP.h index b23d602a..587cd9ff 100644 --- a/toxcore/Lossless_UDP.h +++ b/toxcore/Lossless_UDP.h @@ -25,6 +25,7 @@ #define LOSSLESS_UDP_H #include "network.h" +#include "crypto_core.h" #include "misc_tools.h" diff --git a/toxcore/crypto_core.c b/toxcore/crypto_core.c index 0b1971e7..6e92f5b6 100644 --- a/toxcore/crypto_core.c +++ b/toxcore/crypto_core.c @@ -50,6 +50,22 @@ int crypto_cmp(uint8_t *mem1, uint8_t *mem2, uint32_t length) return (1 & ((check - 1) >> 8)) - 1; } +/* return a random number. + */ +uint32_t random_int(void) +{ + uint32_t randnum; + randombytes((uint8_t *)&randnum , sizeof(randnum)); + return randnum; +} + +uint64_t random_64b(void) +{ + uint64_t randnum; + randombytes((uint8_t *)&randnum, sizeof(randnum)); + return randnum; +} + /* Precomputes the shared key from their public_key and our secret_key. * This way we can avoid an expensive elliptic curve scalar multiply for each * encrypt/decrypt operation. diff --git a/toxcore/crypto_core.h b/toxcore/crypto_core.h index c5969453..6b69f917 100644 --- a/toxcore/crypto_core.h +++ b/toxcore/crypto_core.h @@ -45,6 +45,15 @@ return -1 if they are not. */ int crypto_cmp(uint8_t *mem1, uint8_t *mem2, uint32_t length); +/* return a random number. + * + * random_int for a 32bin int. + * random_64b for a 64bit int. + */ +uint32_t random_int(void); +uint64_t random_64b(void); + + /* Encrypts plain of length length to encrypted of length + 16 using the * public key(32 bytes) of the receiver and the secret key of the sender and a 24 byte nonce. * diff --git a/toxcore/network.c b/toxcore/network.c index 6a7661c4..28925180 100644 --- a/toxcore/network.c +++ b/toxcore/network.c @@ -204,21 +204,6 @@ uint64_t current_time(void) #endif } -/* return a random number. - */ -uint32_t random_int(void) -{ - uint32_t randnum; - randombytes((uint8_t *)&randnum , sizeof(randnum)); - return randnum; -} - -uint64_t random_64b(void) -{ - uint64_t randnum; - randombytes((uint8_t *)&randnum, sizeof(randnum)); - return randnum; -} #ifdef LOGGING static void loglogdata(char *message, uint8_t *buffer, size_t buflen, IP_Port *ip_port, ssize_t res); diff --git a/toxcore/network.h b/toxcore/network.h index d19f144c..4a893cff 100644 --- a/toxcore/network.h +++ b/toxcore/network.h @@ -325,11 +325,6 @@ int set_socket_dualstack(sock_t sock); /* return current UNIX time in microseconds (us). */ uint64_t current_time(void); -/* return a random number. - */ -uint32_t random_int(void); -uint64_t random_64b(void); - /* Basic network functions: */ /* Function to send packet(data) of length length to ip_port. */