summaryrefslogtreecommitdiff
path: root/toxcore/net_crypto.c
diff options
context:
space:
mode:
authorTyler Bunnell <tylerbunnell@gmail.com>2013-09-01 20:42:59 -0600
committerTyler Bunnell <tylerbunnell@gmail.com>2013-09-01 20:42:59 -0600
commitd1c52788c5d4ec5f782df02f6851a74f5dff7da2 (patch)
tree1454c1de8d9c1ae7d3a9b515076437decab5c4dc /toxcore/net_crypto.c
parent86c748e75552bfc5d57d7ae07d45b440000090d2 (diff)
Fix signed/unsigned comparison warnings
Diffstat (limited to 'toxcore/net_crypto.c')
-rw-r--r--toxcore/net_crypto.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c
index 87c98089..f55f40a1 100644
--- a/toxcore/net_crypto.c
+++ b/toxcore/net_crypto.c
@@ -32,6 +32,8 @@
32#define CONN_ESTABLISHED 3 32#define CONN_ESTABLISHED 3
33#define CONN_TIMED_OUT 4 33#define CONN_TIMED_OUT 4
34 34
35static uint8_t crypt_id_valid(int crypt_connection_id, Net_Crypto *c) { return crypt_connection_id < 0 || (uint32_t)crypt_connection_id >= c->crypto_connections_length; }
36
35/* Use this instead of memcmp; not vulnerable to timing attacks. */ 37/* Use this instead of memcmp; not vulnerable to timing attacks. */
36uint8_t crypto_iszero(uint8_t *mem, uint32_t length) 38uint8_t crypto_iszero(uint8_t *mem, uint32_t length)
37{ 39{
@@ -150,7 +152,7 @@ void random_nonce(uint8_t *nonce)
150 */ 152 */
151int read_cryptpacket(Net_Crypto *c, int crypt_connection_id, uint8_t *data) 153int read_cryptpacket(Net_Crypto *c, int crypt_connection_id, uint8_t *data)
152{ 154{
153 if (crypt_connection_id < 0 || crypt_connection_id >= c->crypto_connections_length) 155 if (crypt_id_valid(crypt_connection_id,c))
154 return 0; 156 return 0;
155 157
156 if (c->crypto_connections[crypt_connection_id].status != CONN_ESTABLISHED) 158 if (c->crypto_connections[crypt_connection_id].status != CONN_ESTABLISHED)
@@ -182,7 +184,7 @@ int read_cryptpacket(Net_Crypto *c, int crypt_connection_id, uint8_t *data)
182 */ 184 */
183int write_cryptpacket(Net_Crypto *c, int crypt_connection_id, uint8_t *data, uint32_t length) 185int write_cryptpacket(Net_Crypto *c, int crypt_connection_id, uint8_t *data, uint32_t length)
184{ 186{
185 if (crypt_connection_id < 0 || crypt_connection_id >= c->crypto_connections_length) 187 if (crypt_id_valid(crypt_connection_id,c))
186 return 0; 188 return 0;
187 189
188 if (length - crypto_box_BOXZEROBYTES + crypto_box_ZEROBYTES > MAX_DATA_SIZE - 1) 190 if (length - crypto_box_BOXZEROBYTES + crypto_box_ZEROBYTES > MAX_DATA_SIZE - 1)
@@ -304,7 +306,8 @@ static int cryptopacket_handle(void *object, IP_Port source, uint8_t *packet, ui
304 len); 306 len);
305 307
306 } else { /* If request is not for us, try routing it. */ 308 } else { /* If request is not for us, try routing it. */
307 if (route_packet(dht, packet + 1, packet, length) == length) 309 int retval = route_packet(dht, packet + 1, packet, length);
310 if (retval < 0 || (uint32_t)retval == length)
308 return 0; 311 return 0;
309 } 312 }
310 } 313 }
@@ -505,7 +508,7 @@ int crypto_inbound(Net_Crypto *c, uint8_t *public_key, uint8_t *secret_nonce, ui
505 */ 508 */
506int crypto_kill(Net_Crypto *c, int crypt_connection_id) 509int crypto_kill(Net_Crypto *c, int crypt_connection_id)
507{ 510{
508 if (crypt_connection_id < 0 || crypt_connection_id >= c->crypto_connections_length) 511 if (crypt_id_valid(crypt_connection_id,c))
509 return 1; 512 return 1;
510 513
511 if (c->crypto_connections[crypt_connection_id].status != CONN_NO_CONNECTION) { 514 if (c->crypto_connections[crypt_connection_id].status != CONN_NO_CONNECTION) {
@@ -596,7 +599,7 @@ int accept_crypto_inbound(Net_Crypto *c, int connection_id, uint8_t *public_key,
596 */ 599 */
597int is_cryptoconnected(Net_Crypto *c, int crypt_connection_id) 600int is_cryptoconnected(Net_Crypto *c, int crypt_connection_id)
598{ 601{
599 if (crypt_connection_id >= 0 && crypt_connection_id < c->crypto_connections_length) 602 if (crypt_connection_id >= 0 && (uint32_t)crypt_connection_id < c->crypto_connections_length)
600 return c->crypto_connections[crypt_connection_id].status; 603 return c->crypto_connections[crypt_connection_id].status;
601 604
602 return CONN_NO_CONNECTION; 605 return CONN_NO_CONNECTION;