From 07a6f482d9e799c3b0f04fc435cfad9a969028fb Mon Sep 17 00:00:00 2001 From: irungentoo Date: Sat, 12 Dec 2015 14:49:21 -0500 Subject: Update so this works with the new distance function. --- toxcore/DHT.c | 21 +++++++++++++++------ 1 file 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) return -1; } -static void divide_by_2(uint8_t *public_key) +static void abs_divide_by_2(uint8_t *public_key_dist) { unsigned int i; - _Bool one = 0; + _Bool one = 0, abs = 0; + + if (public_key_dist[0] & (1 << 7)) { + for (i = 0; i < crypto_box_PUBLICKEYBYTES; ++i) { + public_key_dist[i] = ~public_key_dist[i]; + } + + if (public_key_dist[crypto_box_PUBLICKEYBYTES - 1] != UINT8_MAX) + ++public_key_dist[crypto_box_PUBLICKEYBYTES - 1]; + } for (i = 0; i < crypto_box_PUBLICKEYBYTES; ++i) { _Bool temp = 0; - if (public_key[i] & (1)) { + if (public_key_dist[i] & (1)) { temp = 1; } - public_key[i] >>= 1; + public_key_dist[i] >>= 1; if (one) - public_key[i] += (1 << 7); + public_key_dist[i] += (1 << 7); one = temp; } @@ -1364,7 +1373,7 @@ static void find_midpoint(uint8_t *out, const uint8_t *top, const uint8_t *bot) out[i] = top[i] ^ bot[i]; } - divide_by_2(out); + abs_divide_by_2(out); for (i = 0; i < crypto_box_PUBLICKEYBYTES; ++i) { out[i] ^= bot[i]; -- cgit v1.2.3