From deb8bfc350748555b7de5d0f4911c382b3f2d65e Mon Sep 17 00:00:00 2001 From: irungentoo Date: Thu, 1 May 2014 19:42:44 -0400 Subject: Random number functions belong in crypto_core. --- toxcore/DHT.h | 1 + toxcore/Lossless_UDP.h | 1 + toxcore/crypto_core.c | 16 ++++++++++++++++ toxcore/crypto_core.h | 9 +++++++++ toxcore/network.c | 15 --------------- toxcore/network.h | 5 ----- 6 files changed, 27 insertions(+), 20 deletions(-) (limited to 'toxcore') 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. */ -- cgit v1.2.3