summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2018-03-28 13:36:14 +0000
committeriphydf <iphydf@users.noreply.github.com>2018-04-03 17:43:22 +0000
commit37d4a0b2ca1377268a82c085809edf63d19cc782 (patch)
tree9b0724cb55f479689cbc04c8b72f9bde99f775ab /toxcore
parent7fa0c89c96bdaf45bf202d770aa56dc7c68959b9 (diff)
Avoid the use of rand() in tests.
We control the random functions in crypto_core, so we can make them deterministic more easily. This will help test reproducibility in the future.
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/crypto_core.api.h5
-rw-r--r--toxcore/crypto_core.c7
-rw-r--r--toxcore/crypto_core.h5
3 files changed, 17 insertions, 0 deletions
diff --git a/toxcore/crypto_core.api.h b/toxcore/crypto_core.api.h
index bb2c0a13..e9e8aeb2 100644
--- a/toxcore/crypto_core.api.h
+++ b/toxcore/crypto_core.api.h
@@ -117,6 +117,11 @@ static int32_t public_key_cmp(
117namespace random { 117namespace random {
118 118
119/** 119/**
120 * Return a random 8 bit integer.
121 */
122static uint8_t u08();
123
124/**
120 * Return a random 16 bit integer. 125 * Return a random 16 bit integer.
121 */ 126 */
122static uint16_t u16(); 127static uint16_t u16();
diff --git a/toxcore/crypto_core.c b/toxcore/crypto_core.c
index 26589219..b2f0e5f0 100644
--- a/toxcore/crypto_core.c
+++ b/toxcore/crypto_core.c
@@ -86,6 +86,13 @@ int32_t public_key_cmp(const uint8_t *pk1, const uint8_t *pk2)
86 return crypto_verify_32(pk1, pk2); 86 return crypto_verify_32(pk1, pk2);
87} 87}
88 88
89uint8_t random_u08(void)
90{
91 uint8_t randnum;
92 randombytes(&randnum, 1);
93 return randnum;
94}
95
89uint16_t random_u16(void) 96uint16_t random_u16(void)
90{ 97{
91 uint16_t randnum; 98 uint16_t randnum;
diff --git a/toxcore/crypto_core.h b/toxcore/crypto_core.h
index 2c83fd25..e7e913b6 100644
--- a/toxcore/crypto_core.h
+++ b/toxcore/crypto_core.h
@@ -127,6 +127,11 @@ void crypto_sha512(uint8_t *hash, const uint8_t *data, size_t length);
127int32_t public_key_cmp(const uint8_t *pk1, const uint8_t *pk2); 127int32_t public_key_cmp(const uint8_t *pk1, const uint8_t *pk2);
128 128
129/** 129/**
130 * Return a random 8 bit integer.
131 */
132uint8_t random_u08(void);
133
134/**
130 * Return a random 16 bit integer. 135 * Return a random 16 bit integer.
131 */ 136 */
132uint16_t random_u16(void); 137uint16_t random_u16(void);