summaryrefslogtreecommitdiff
path: root/other/fun
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-02-10 19:53:44 -0500
committerirungentoo <irungentoo@gmail.com>2014-02-10 19:53:44 -0500
commitd6e2f903a71981b26c86198fb20f8c00bb0452b1 (patch)
tree81046f75612e5ae216682980e88e841cff321bac /other/fun
parent80f001e03bed48c5ec0029255354fc00f2904222 (diff)
Added entry to TODO and a public key cracker (vanity key finder) to other/fun.
Diffstat (limited to 'other/fun')
-rw-r--r--other/fun/cracker.c75
1 files changed, 75 insertions, 0 deletions
diff --git a/other/fun/cracker.c b/other/fun/cracker.c
new file mode 100644
index 00000000..9921df31
--- /dev/null
+++ b/other/fun/cracker.c
@@ -0,0 +1,75 @@
1/* Public key cracker.
2 *
3 * Can be used to find public keys starting with specific hex (ABCD) for example.
4 *
5 * NOTE: There's probably a way to make this faster.
6 *
7 * Usage: ./cracker ABCDEF
8 *
9 * Will try to find a public key starting with: ABCDEF
10 */
11
12#include "../../testing/misc_tools.c"
13#include <time.h>
14
15/* NaCl includes*/
16#include <crypto_scalarmult_curve25519.h>
17#include <randombytes.h>
18
19/* Sodium include*/
20//#include <libsodium.h>
21
22void print_key(uint8_t *client_id)
23{
24 uint32_t j;
25
26 for (j = 0; j < 32; j++) {
27 printf("%02hhX", client_id[j]);
28 }
29}
30
31
32int main(int argc, char *argv[])
33{
34 if (argc < 2) {
35 printf("usage: ./cracker public_key(or beggining of one in hex format)\n");
36 return 0;
37 }
38
39 long long unsigned int num_tries = 0;
40
41 uint32_t len = strlen(argv[1]) / 2;
42 unsigned char *key = hex_string_to_bin(argv[1]);
43 uint8_t pub_key[32], priv_key[32], c_key[32];
44
45 if (len > 32)
46 len = 32;
47
48 memcpy(c_key, key, len);
49 free(key);
50 randombytes(priv_key, 32);
51
52 while (1) {
53 crypto_scalarmult_curve25519_base(pub_key, priv_key);
54 uint32_t i;
55
56 if (memcmp(c_key, pub_key, len) == 0)
57 break;
58
59 for (i = 32; i != 0; --i) {
60 priv_key[i - 1] += 1;
61
62 if (priv_key[i - 1] != 0)
63 break;
64 }
65
66 ++num_tries;
67 }
68
69 printf("Public key:\n");
70 print_key(pub_key);
71 printf("\nPrivate key:\n");
72 print_key(priv_key);
73 printf("\n %llu keys tried\n", num_tries);
74 return 0;
75}