summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2015-12-12 14:49:21 -0500
committerirungentoo <irungentoo@gmail.com>2015-12-12 14:49:21 -0500
commit07a6f482d9e799c3b0f04fc435cfad9a969028fb (patch)
tree05ab77237f6a52b75af7656dbcbe5d0b41988799
parent1c8109e524870bb51622c098ce08533535cb3eab (diff)
Update so this works with the new distance function.
-rw-r--r--toxcore/DHT.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c
index b4caa113..e748da7c 100644
--- a/toxcore/DHT.c
+++ b/toxcore/DHT.c
@@ -1335,22 +1335,31 @@ int DHT_getfriendip(const DHT *dht, const uint8_t *public_key, IP_Port *ip_port)
1335 return -1; 1335 return -1;
1336} 1336}
1337 1337
1338static void divide_by_2(uint8_t *public_key) 1338static void abs_divide_by_2(uint8_t *public_key_dist)
1339{ 1339{
1340 unsigned int i; 1340 unsigned int i;
1341 _Bool one = 0; 1341 _Bool one = 0, abs = 0;
1342
1343 if (public_key_dist[0] & (1 << 7)) {
1344 for (i = 0; i < crypto_box_PUBLICKEYBYTES; ++i) {
1345 public_key_dist[i] = ~public_key_dist[i];
1346 }
1347
1348 if (public_key_dist[crypto_box_PUBLICKEYBYTES - 1] != UINT8_MAX)
1349 ++public_key_dist[crypto_box_PUBLICKEYBYTES - 1];
1350 }
1342 1351
1343 for (i = 0; i < crypto_box_PUBLICKEYBYTES; ++i) { 1352 for (i = 0; i < crypto_box_PUBLICKEYBYTES; ++i) {
1344 _Bool temp = 0; 1353 _Bool temp = 0;
1345 1354
1346 if (public_key[i] & (1)) { 1355 if (public_key_dist[i] & (1)) {
1347 temp = 1; 1356 temp = 1;
1348 } 1357 }
1349 1358
1350 public_key[i] >>= 1; 1359 public_key_dist[i] >>= 1;
1351 1360
1352 if (one) 1361 if (one)
1353 public_key[i] += (1 << 7); 1362 public_key_dist[i] += (1 << 7);
1354 1363
1355 one = temp; 1364 one = temp;
1356 } 1365 }
@@ -1364,7 +1373,7 @@ static void find_midpoint(uint8_t *out, const uint8_t *top, const uint8_t *bot)
1364 out[i] = top[i] ^ bot[i]; 1373 out[i] = top[i] ^ bot[i];
1365 } 1374 }
1366 1375
1367 divide_by_2(out); 1376 abs_divide_by_2(out);
1368 1377
1369 for (i = 0; i < crypto_box_PUBLICKEYBYTES; ++i) { 1378 for (i = 0; i < crypto_box_PUBLICKEYBYTES; ++i) {
1370 out[i] ^= bot[i]; 1379 out[i] ^= bot[i];