diff options
-rw-r--r-- | toxcore/DHT.h | 1 | ||||
-rw-r--r-- | toxcore/Lossless_UDP.h | 1 | ||||
-rw-r--r-- | toxcore/crypto_core.c | 16 | ||||
-rw-r--r-- | toxcore/crypto_core.h | 9 | ||||
-rw-r--r-- | toxcore/network.c | 15 | ||||
-rw-r--r-- | toxcore/network.h | 5 |
6 files changed, 27 insertions, 20 deletions
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 @@ | |||
25 | #define DHT_H | 25 | #define DHT_H |
26 | 26 | ||
27 | #include "crypto_core.h" | 27 | #include "crypto_core.h" |
28 | #include "network.h" | ||
28 | 29 | ||
29 | /* Size of the client_id in bytes. */ | 30 | /* Size of the client_id in bytes. */ |
30 | #define CLIENT_ID_SIZE crypto_box_PUBLICKEYBYTES | 31 | #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 @@ | |||
25 | #define LOSSLESS_UDP_H | 25 | #define LOSSLESS_UDP_H |
26 | 26 | ||
27 | #include "network.h" | 27 | #include "network.h" |
28 | #include "crypto_core.h" | ||
28 | #include "misc_tools.h" | 29 | #include "misc_tools.h" |
29 | 30 | ||
30 | 31 | ||
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) | |||
50 | return (1 & ((check - 1) >> 8)) - 1; | 50 | return (1 & ((check - 1) >> 8)) - 1; |
51 | } | 51 | } |
52 | 52 | ||
53 | /* return a random number. | ||
54 | */ | ||
55 | uint32_t random_int(void) | ||
56 | { | ||
57 | uint32_t randnum; | ||
58 | randombytes((uint8_t *)&randnum , sizeof(randnum)); | ||
59 | return randnum; | ||
60 | } | ||
61 | |||
62 | uint64_t random_64b(void) | ||
63 | { | ||
64 | uint64_t randnum; | ||
65 | randombytes((uint8_t *)&randnum, sizeof(randnum)); | ||
66 | return randnum; | ||
67 | } | ||
68 | |||
53 | /* Precomputes the shared key from their public_key and our secret_key. | 69 | /* Precomputes the shared key from their public_key and our secret_key. |
54 | * This way we can avoid an expensive elliptic curve scalar multiply for each | 70 | * This way we can avoid an expensive elliptic curve scalar multiply for each |
55 | * encrypt/decrypt operation. | 71 | * 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 @@ | |||
45 | return -1 if they are not. */ | 45 | return -1 if they are not. */ |
46 | int crypto_cmp(uint8_t *mem1, uint8_t *mem2, uint32_t length); | 46 | int crypto_cmp(uint8_t *mem1, uint8_t *mem2, uint32_t length); |
47 | 47 | ||
48 | /* return a random number. | ||
49 | * | ||
50 | * random_int for a 32bin int. | ||
51 | * random_64b for a 64bit int. | ||
52 | */ | ||
53 | uint32_t random_int(void); | ||
54 | uint64_t random_64b(void); | ||
55 | |||
56 | |||
48 | /* Encrypts plain of length length to encrypted of length + 16 using the | 57 | /* Encrypts plain of length length to encrypted of length + 16 using the |
49 | * public key(32 bytes) of the receiver and the secret key of the sender and a 24 byte nonce. | 58 | * public key(32 bytes) of the receiver and the secret key of the sender and a 24 byte nonce. |
50 | * | 59 | * |
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) | |||
204 | #endif | 204 | #endif |
205 | } | 205 | } |
206 | 206 | ||
207 | /* return a random number. | ||
208 | */ | ||
209 | uint32_t random_int(void) | ||
210 | { | ||
211 | uint32_t randnum; | ||
212 | randombytes((uint8_t *)&randnum , sizeof(randnum)); | ||
213 | return randnum; | ||
214 | } | ||
215 | |||
216 | uint64_t random_64b(void) | ||
217 | { | ||
218 | uint64_t randnum; | ||
219 | randombytes((uint8_t *)&randnum, sizeof(randnum)); | ||
220 | return randnum; | ||
221 | } | ||
222 | 207 | ||
223 | #ifdef LOGGING | 208 | #ifdef LOGGING |
224 | static void loglogdata(char *message, uint8_t *buffer, size_t buflen, IP_Port *ip_port, ssize_t res); | 209 | 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); | |||
325 | /* return current UNIX time in microseconds (us). */ | 325 | /* return current UNIX time in microseconds (us). */ |
326 | uint64_t current_time(void); | 326 | uint64_t current_time(void); |
327 | 327 | ||
328 | /* return a random number. | ||
329 | */ | ||
330 | uint32_t random_int(void); | ||
331 | uint64_t random_64b(void); | ||
332 | |||
333 | /* Basic network functions: */ | 328 | /* Basic network functions: */ |
334 | 329 | ||
335 | /* Function to send packet(data) of length length to ip_port. */ | 330 | /* Function to send packet(data) of length length to ip_port. */ |