Created
February 25, 2015 19:04
-
-
Save landswellsong/395f2f98b83c91355a25 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sodium.h> | |
#include <stdio.h> | |
#define CLIENT_ID_SIZE crypto_box_PUBLICKEYBYTES | |
/* Copied over from DHT.c not to mess around with tox source deps */ | |
int id_closest(const uint8_t *id, const uint8_t *id1, const uint8_t *id2) | |
{ | |
size_t i; | |
uint8_t distance1, distance2; | |
for (i = 0; i < CLIENT_ID_SIZE; ++i) { | |
distance1 = abs(((int8_t *)id)[i] ^ ((int8_t *)id1)[i]); | |
distance2 = abs(((int8_t *)id)[i] ^ ((int8_t *)id2)[i]); | |
if (distance1 < distance2) | |
return 1; | |
if (distance1 > distance2) | |
return 2; | |
} | |
return 0; | |
} | |
int main() | |
{ | |
long tries=0; | |
uint8_t pA[crypto_box_PUBLICKEYBYTES], sA[crypto_box_SECRETKEYBYTES]; | |
uint8_t pB[crypto_box_PUBLICKEYBYTES], sB[crypto_box_SECRETKEYBYTES]; | |
uint8_t pC[crypto_box_PUBLICKEYBYTES], sC[crypto_box_SECRETKEYBYTES]; | |
/* Generating an initial pair */ | |
crypto_box_keypair(pA, sA); | |
crypto_box_keypair(pB, sB); | |
do | |
{ | |
crypto_box_keypair(pC, sC); | |
tries++; | |
} | |
while (id_closest(pA, pB, pC) != 2); | |
printf("Found a closer key after %ld tries\n", tries); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment