2014-02-11 08:53:44 +08:00
|
|
|
/* Public key cracker.
|
|
|
|
*
|
|
|
|
* Can be used to find public keys starting with specific hex (ABCD) for example.
|
|
|
|
*
|
|
|
|
* NOTE: There's probably a way to make this faster.
|
|
|
|
*
|
|
|
|
* Usage: ./cracker ABCDEF
|
|
|
|
*
|
|
|
|
* Will try to find a public key starting with: ABCDEF
|
|
|
|
*/
|
|
|
|
|
2018-07-17 06:46:02 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2014-02-11 08:53:44 +08:00
|
|
|
|
2018-07-17 06:46:02 +08:00
|
|
|
/* Sodium includes*/
|
2016-09-09 22:02:45 +08:00
|
|
|
#include <sodium/crypto_scalarmult_curve25519.h>
|
|
|
|
#include <sodium/randombytes.h>
|
2014-02-11 08:53:44 +08:00
|
|
|
|
2018-07-17 06:46:02 +08:00
|
|
|
#include "../../testing/misc_tools.h"
|
|
|
|
#include "../../toxcore/ccompat.h"
|
2014-02-11 08:53:44 +08:00
|
|
|
|
2018-07-17 09:18:04 +08:00
|
|
|
static void print_key(uint8_t *client_id)
|
2014-02-11 08:53:44 +08:00
|
|
|
{
|
|
|
|
uint32_t j;
|
|
|
|
|
|
|
|
for (j = 0; j < 32; j++) {
|
2018-02-24 01:11:00 +08:00
|
|
|
printf("%02X", client_id[j]);
|
2014-02-11 08:53:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
if (argc < 2) {
|
2014-04-17 00:08:44 +08:00
|
|
|
printf("usage: ./cracker public_key(or beginning of one in hex format)\n");
|
2014-02-11 08:53:44 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
long long unsigned int num_tries = 0;
|
|
|
|
|
|
|
|
uint32_t len = strlen(argv[1]) / 2;
|
|
|
|
unsigned char *key = hex_string_to_bin(argv[1]);
|
|
|
|
uint8_t pub_key[32], priv_key[32], c_key[32];
|
|
|
|
|
2016-09-09 22:02:45 +08:00
|
|
|
if (len > 32) {
|
2014-02-11 08:53:44 +08:00
|
|
|
len = 32;
|
2016-09-09 22:02:45 +08:00
|
|
|
}
|
2014-02-11 08:53:44 +08:00
|
|
|
|
|
|
|
memcpy(c_key, key, len);
|
|
|
|
free(key);
|
|
|
|
randombytes(priv_key, 32);
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
crypto_scalarmult_curve25519_base(pub_key, priv_key);
|
|
|
|
uint32_t i;
|
|
|
|
|
2016-09-09 22:02:45 +08:00
|
|
|
if (memcmp(c_key, pub_key, len) == 0) {
|
2014-02-11 08:53:44 +08:00
|
|
|
break;
|
2016-09-09 22:02:45 +08:00
|
|
|
}
|
2014-02-11 08:53:44 +08:00
|
|
|
|
|
|
|
for (i = 32; i != 0; --i) {
|
|
|
|
priv_key[i - 1] += 1;
|
|
|
|
|
2016-09-09 22:02:45 +08:00
|
|
|
if (priv_key[i - 1] != 0) {
|
2014-02-11 08:53:44 +08:00
|
|
|
break;
|
2016-09-09 22:02:45 +08:00
|
|
|
}
|
2014-02-11 08:53:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
++num_tries;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Public key:\n");
|
|
|
|
print_key(pub_key);
|
|
|
|
printf("\nPrivate key:\n");
|
|
|
|
print_key(priv_key);
|
|
|
|
printf("\n %llu keys tried\n", num_tries);
|
|
|
|
return 0;
|
|
|
|
}
|