1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-02-17 01:52:02 +00:00

update bip39bruteforce tool

This commit is contained in:
Pavol Rusnak 2016-08-15 15:05:32 +02:00
parent 4d6d9fe8ba
commit 245e2cc23d
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

View File

@ -6,30 +6,41 @@
#include "ecdsa.h" #include "ecdsa.h"
#include "curves.h" #include "curves.h"
char passphrase[256]; char iter[256];
uint8_t seed[512 / 8]; uint8_t seed[512 / 8];
uint8_t addr[21], pubkeyhash[20]; uint8_t addr[21], pubkeyhash[20];
int count = 0, found = 0; int count = 0, found = 0;
HDNode node; HDNode node;
clock_t start; clock_t start;
// around 120 tries per second // around 280 tries per second
// testing data: // testing data:
// //
// mnemonic: "all all all all all all all all all all all all" // mnemonic: "all all all all all all all all all all all all"
// address: "1JAd7XCBzGudGpJQSDSfpmJhiygtLQWaGL"
// passphrase: ""
//
// mnemonic: "all all all all all all all all all all all all"
// address: "1N3uJ5AU3FTYQ1ZQgTMtYmgSvMBmQiGVBS" // address: "1N3uJ5AU3FTYQ1ZQgTMtYmgSvMBmQiGVBS"
// passphrase: "testing" // passphrase: "testing"
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
if (argc != 3) { if (argc != 2 && argc != 3) {
fprintf(stderr, "Usage: bip39bruteforce mnemonic address\n"); fprintf(stderr, "Usage: bip39bruteforce address [mnemonic]\n");
return 1; return 1;
} }
const char *mnemonic = argv[1]; const char *address = argv[1];
const char *address = argv[2]; const char *mnemonic, *item;
if (!mnemonic_check(mnemonic)) { if (argc == 3) {
mnemonic = argv[2];
item = "passphrase";
} else {
mnemonic = NULL;
item = "mnemonic";
}
if (mnemonic && !mnemonic_check(mnemonic)) {
fprintf(stderr, "\"%s\" is not a valid mnemonic\n", mnemonic); fprintf(stderr, "\"%s\" is not a valid mnemonic\n", mnemonic);
return 2; return 2;
} }
@ -37,23 +48,28 @@ int main(int argc, char **argv)
fprintf(stderr, "\"%s\" is not a valid address\n", address); fprintf(stderr, "\"%s\" is not a valid address\n", address);
return 3; return 3;
} }
printf("Reading passphrases from stdin ...\n"); printf("Reading %ss from stdin ...\n", item);
start = clock(); start = clock();
for (;;) { for (;;) {
if (fgets(passphrase, 256, stdin) == NULL) break; if (fgets(iter, 256, stdin) == NULL) break;
int len = strlen(passphrase); int len = strlen(iter);
if (len <= 0) { if (len <= 0) {
continue; continue;
} }
count++; count++;
passphrase[len - 1] = 0; iter[len - 1] = 0;
mnemonic_to_seed(mnemonic, passphrase, seed, NULL); if (mnemonic) {
mnemonic_to_seed(mnemonic, iter, seed, NULL);
} else {
mnemonic_to_seed(iter, "", seed, NULL);
}
hdnode_from_seed(seed, 512 / 8, SECP256K1_NAME, &node); hdnode_from_seed(seed, 512 / 8, SECP256K1_NAME, &node);
hdnode_private_ckd_prime(&node, 44); hdnode_private_ckd_prime(&node, 44);
hdnode_private_ckd_prime(&node, 0); hdnode_private_ckd_prime(&node, 0);
hdnode_private_ckd_prime(&node, 0); hdnode_private_ckd_prime(&node, 0);
hdnode_private_ckd(&node, 0); hdnode_private_ckd(&node, 0);
hdnode_private_ckd(&node, 0); hdnode_private_ckd(&node, 0);
hdnode_fill_public_key(&node);
ecdsa_get_pubkeyhash(node.public_key, pubkeyhash); ecdsa_get_pubkeyhash(node.public_key, pubkeyhash);
if (memcmp(addr + 1, pubkeyhash, 20) == 0) { if (memcmp(addr + 1, pubkeyhash, 20) == 0) {
found = 1; found = 1;
@ -61,11 +77,11 @@ int main(int argc, char **argv)
} }
} }
float dur = (float)(clock() - start) / CLOCKS_PER_SEC; float dur = (float)(clock() - start) / CLOCKS_PER_SEC;
printf("Tried %d passphrases in %f seconds = %f tries/second\n", count, dur, (float)count/dur); printf("Tried %d %ss in %f seconds = %f tries/second\n", count, item, dur, (float)count/dur);
if (found) { if (found) {
printf("Correct passphrase found! :-)\n\"%s\"\n", passphrase); printf("Correct %s found! :-)\n\"%s\"\n", item, iter);
return 0; return 0;
} }
printf("Correct passphrase not found. :-(\n"); printf("Correct %s not found. :-(\n", item);
return 4; return 4;
} }