diff options
-rw-r--r-- | toxcore/DHT.c | 21 |
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 | ||
1338 | static void divide_by_2(uint8_t *public_key) | 1338 | static 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]; |