summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-05-01 19:42:44 -0400
committerirungentoo <irungentoo@gmail.com>2014-05-01 19:42:44 -0400
commitdeb8bfc350748555b7de5d0f4911c382b3f2d65e (patch)
tree7f026e9fb740cb7c6c6eee5397a1365e5a034ef5
parent47aa53a3840f81b42e0f78dea03a57ebd7c3ebb5 (diff)
Random number functions belong in crypto_core.
-rw-r--r--toxcore/DHT.h1
-rw-r--r--toxcore/Lossless_UDP.h1
-rw-r--r--toxcore/crypto_core.c16
-rw-r--r--toxcore/crypto_core.h9
-rw-r--r--toxcore/network.c15
-rw-r--r--toxcore/network.h5
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 */
55uint32_t random_int(void)
56{
57 uint32_t randnum;
58 randombytes((uint8_t *)&randnum , sizeof(randnum));
59 return randnum;
60}
61
62uint64_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. */
46int crypto_cmp(uint8_t *mem1, uint8_t *mem2, uint32_t length); 46int 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 */
53uint32_t random_int(void);
54uint64_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 */
209uint32_t random_int(void)
210{
211 uint32_t randnum;
212 randombytes((uint8_t *)&randnum , sizeof(randnum));
213 return randnum;
214}
215
216uint64_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
224static void loglogdata(char *message, uint8_t *buffer, size_t buflen, IP_Port *ip_port, ssize_t res); 209static 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). */
326uint64_t current_time(void); 326uint64_t current_time(void);
327 327
328/* return a random number.
329 */
330uint32_t random_int(void);
331uint64_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. */