-
Notifications
You must be signed in to change notification settings - Fork 472
/
keyhunt.cpp
6689 lines (5917 loc) · 208 KB
/
keyhunt.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Develop by Alberto
email: albertobsd@gmail.com
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <vector>
#include <inttypes.h>
#include "base58/libbase58.h"
#include "rmd160/rmd160.h"
#include "oldbloom/oldbloom.h"
#include "bloom/bloom.h"
#include "sha3/sha3.h"
#include "util.h"
#include "secp256k1/SECP256k1.h"
#include "secp256k1/Point.h"
#include "secp256k1/Int.h"
#include "secp256k1/IntGroup.h"
#include "secp256k1/Random.h"
#include "hash/sha256.h"
#include "hash/ripemd160.h"
#if defined(_WIN64) && !defined(__CYGWIN__)
#include "getopt.h"
#include <windows.h>
#else
#include <unistd.h>
#include <pthread.h>
#include <sys/random.h>
#endif
#ifdef __unix__
#ifdef __CYGWIN__
#else
#include <linux/random.h>
#endif
#endif
#define CRYPTO_NONE 0
#define CRYPTO_BTC 1
#define CRYPTO_ETH 2
#define CRYPTO_ALL 3
#define MODE_XPOINT 0
#define MODE_ADDRESS 1
#define MODE_BSGS 2
#define MODE_RMD160 3
#define MODE_PUB2RMD 4
#define MODE_MINIKEYS 5
#define MODE_VANITY 6
#define SEARCH_UNCOMPRESS 0
#define SEARCH_COMPRESS 1
#define SEARCH_BOTH 2
uint32_t THREADBPWORKLOAD = 1048576;
struct checksumsha256 {
char data[32];
char backup[32];
};
struct bsgs_xvalue {
uint8_t value[6];
uint64_t index;
};
struct address_value {
uint8_t value[20];
};
struct tothread {
int nt; //Number thread
char *rs; //range start
char *rpt; //rng per thread
};
struct bPload {
uint32_t threadid;
uint64_t from;
uint64_t to;
uint64_t counter;
uint64_t workload;
uint32_t aux;
uint32_t finished;
};
#if defined(_WIN64) && !defined(__CYGWIN__)
#define PACK( __Declaration__ ) __pragma( pack(push, 1) ) __Declaration__ __pragma( pack(pop))
PACK(struct publickey
{
uint8_t parity;
union {
uint8_t data8[32];
uint32_t data32[8];
uint64_t data64[4];
} X;
});
#else
struct __attribute__((__packed__)) publickey {
uint8_t parity;
union {
uint8_t data8[32];
uint32_t data32[8];
uint64_t data64[4];
} X;
};
#endif
const char *Ccoinbuffer_default = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
char *Ccoinbuffer = (char*) Ccoinbuffer_default;
char *str_baseminikey = NULL;
char *raw_baseminikey = NULL;
char *minikeyN = NULL;
int minikey_n_limit;
const char *version = "0.2.230519 Satoshi Quest";
#define CPU_GRP_SIZE 1024
std::vector<Point> Gn;
Point _2Gn;
std::vector<Point> GSn;
Point _2GSn;
void menu();
void init_generator();
int searchbinary(struct address_value *buffer,char *data,int64_t array_length);
void sleep_ms(int milliseconds);
void _sort(struct address_value *arr,int64_t N);
void _insertionsort(struct address_value *arr, int64_t n);
void _introsort(struct address_value *arr,uint32_t depthLimit, int64_t n);
void _swap(struct address_value *a,struct address_value *b);
int64_t _partition(struct address_value *arr, int64_t n);
void _myheapsort(struct address_value *arr, int64_t n);
void _heapify(struct address_value *arr, int64_t n, int64_t i);
void bsgs_sort(struct bsgs_xvalue *arr,int64_t n);
void bsgs_myheapsort(struct bsgs_xvalue *arr, int64_t n);
void bsgs_insertionsort(struct bsgs_xvalue *arr, int64_t n);
void bsgs_introsort(struct bsgs_xvalue *arr,uint32_t depthLimit, int64_t n);
void bsgs_swap(struct bsgs_xvalue *a,struct bsgs_xvalue *b);
void bsgs_heapify(struct bsgs_xvalue *arr, int64_t n, int64_t i);
int64_t bsgs_partition(struct bsgs_xvalue *arr, int64_t n);
int bsgs_searchbinary(struct bsgs_xvalue *arr,char *data,int64_t array_length,uint64_t *r_value);
int bsgs_secondcheck(Int *start_range,uint32_t a,uint32_t k_index,Int *privatekey);
int bsgs_thirdcheck(Int *start_range,uint32_t a,uint32_t k_index,Int *privatekey);
void sha256sse_22(uint8_t *src0, uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *dst0, uint8_t *dst1, uint8_t *dst2, uint8_t *dst3);
void sha256sse_23(uint8_t *src0, uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *dst0, uint8_t *dst1, uint8_t *dst2, uint8_t *dst3);
bool vanityrmdmatch(unsigned char *rmdhash);
void writevanitykey(bool compress,Int *key);
int addvanity(char *target);
int minimum_same_bytes(unsigned char* A,unsigned char* B, int length);
void writekey(bool compressed,Int *key);
void writekeyeth(Int *key);
void checkpointer(void *ptr,const char *file,const char *function,const char *name,int line);
bool isBase58(char c);
bool isValidBase58String(char *str);
bool readFileAddress(char *fileName);
bool readFileVanity(char *fileName);
bool forceReadFileAddress(char *fileName);
bool forceReadFileAddressEth(char *fileName);
bool forceReadFileXPoint(char *fileName);
bool processOneVanity();
bool initBloomFilter(struct bloom *bloom_arg,uint64_t items_bloom);
void writeFileIfNeeded(const char *fileName);
void calcualteindex(int i,Int *key);
#if defined(_WIN64) && !defined(__CYGWIN__)
DWORD WINAPI thread_process_vanity(LPVOID vargp);
DWORD WINAPI thread_process_minikeys(LPVOID vargp);
DWORD WINAPI thread_process(LPVOID vargp);
DWORD WINAPI thread_process_bsgs(LPVOID vargp);
DWORD WINAPI thread_process_bsgs_backward(LPVOID vargp);
DWORD WINAPI thread_process_bsgs_both(LPVOID vargp);
DWORD WINAPI thread_process_bsgs_random(LPVOID vargp);
DWORD WINAPI thread_process_bsgs_dance(LPVOID vargp);
DWORD WINAPI thread_bPload(LPVOID vargp);
DWORD WINAPI thread_bPload_2blooms(LPVOID vargp);
#else
void *thread_process_vanity(void *vargp);
void *thread_process_minikeys(void *vargp);
void *thread_process(void *vargp);
void *thread_process_bsgs(void *vargp);
void *thread_process_bsgs_backward(void *vargp);
void *thread_process_bsgs_both(void *vargp);
void *thread_process_bsgs_random(void *vargp);
void *thread_process_bsgs_dance(void *vargp);
void *thread_bPload(void *vargp);
void *thread_bPload_2blooms(void *vargp);
#endif
char *pubkeytopubaddress(char *pkey,int length);
void pubkeytopubaddress_dst(char *pkey,int length,char *dst);
void rmd160toaddress_dst(char *rmd,char *dst);
void set_minikey(char *buffer,char *rawbuffer,int length);
bool increment_minikey_index(char *buffer,char *rawbuffer,int index);
void increment_minikey_N(char *rawbuffer);
void KECCAK_256(uint8_t *source, size_t size,uint8_t *dst);
void generate_binaddress_eth(Point &publickey,unsigned char *dst_address);
int THREADOUTPUT = 0;
char *bit_range_str_min;
char *bit_range_str_max;
const char *bsgs_modes[5] = {"sequential","backward","both","random","dance"};
const char *modes[7] = {"xpoint","address","bsgs","rmd160","pub2rmd","minikeys","vanity"};
const char *cryptos[3] = {"btc","eth","all"};
const char *publicsearch[3] = {"uncompress","compress","both"};
const char *default_fileName = "addresses.txt";
#if defined(_WIN64) && !defined(__CYGWIN__)
HANDLE* tid = NULL;
HANDLE write_keys;
HANDLE write_random;
HANDLE bsgs_thread;
HANDLE *bPload_mutex = NULL;
#else
pthread_t *tid = NULL;
pthread_mutex_t write_keys;
pthread_mutex_t write_random;
pthread_mutex_t bsgs_thread;
pthread_mutex_t *bPload_mutex = NULL;
#endif
uint64_t FINISHED_THREADS_COUNTER = 0;
uint64_t FINISHED_THREADS_BP = 0;
uint64_t THREADCYCLES = 0;
uint64_t THREADCOUNTER = 0;
uint64_t FINISHED_ITEMS = 0;
uint64_t OLDFINISHED_ITEMS = -1;
uint8_t byte_encode_crypto = 0x00; /* Bitcoin */
int vanity_rmd_targets = 0;
int vanity_rmd_total = 0;
int *vanity_rmd_limits = NULL;
uint8_t ***vanity_rmd_limit_values_A = NULL,***vanity_rmd_limit_values_B = NULL;
int vanity_rmd_minimun_bytes_check_length = 999999;
char **vanity_address_targets = NULL;
struct bloom *vanity_bloom = NULL;
struct bloom bloom;
uint64_t *steps = NULL;
unsigned int *ends = NULL;
uint64_t N = 0;
uint64_t N_SEQUENTIAL_MAX = 0x100000000;
uint64_t DEBUGCOUNT = 0x400;
uint64_t u64range;
Int OUTPUTSECONDS;
int FLAGSKIPCHECKSUM = 0;
int FLAGENDOMORPHISM = 0;
int FLAGBLOOMMULTIPLIER = 1;
int FLAGVANITY = 0;
int FLAGBASEMINIKEY = 0;
int FLAGBSGSMODE = 0;
int FLAGDEBUG = 0;
int FLAGQUIET = 0;
int FLAGMATRIX = 0;
int KFACTOR = 1;
int MAXLENGTHADDRESS = -1;
int NTHREADS = 1;
int FLAGSAVEREADFILE = 0;
int FLAGREADEDFILE1 = 0;
int FLAGREADEDFILE2 = 0;
int FLAGREADEDFILE3 = 0;
int FLAGREADEDFILE4 = 0;
int FLAGUPDATEFILE1 = 0;
int FLAGSTRIDE = 0;
int FLAGSEARCH = 2;
int FLAGBITRANGE = 0;
int FLAGRANGE = 0;
int FLAGFILE = 0;
int FLAGMODE = MODE_ADDRESS;
int FLAGCRYPTO = 0;
int FLAGRAWDATA = 0;
int FLAGRANDOM = 0;
int FLAG_N = 0;
int FLAGPRECALCUTED_P_FILE = 0;
int bitrange;
char *str_N;
char *range_start;
char *range_end;
char *str_stride;
Int stride;
uint64_t BSGS_XVALUE_RAM = 6;
uint64_t BSGS_BUFFERXPOINTLENGTH = 32;
uint64_t BSGS_BUFFERREGISTERLENGTH = 36;
/*
BSGS Variables
*/
int *bsgs_found;
std::vector<Point> OriginalPointsBSGS;
bool *OriginalPointsBSGScompressed;
uint64_t bytes;
char checksum[32],checksum_backup[32];
char buffer_bloom_file[1024];
struct bsgs_xvalue *bPtable;
struct address_value *addressTable;
struct oldbloom oldbloom_bP;
struct bloom *bloom_bP;
struct bloom *bloom_bPx2nd; //2nd Bloom filter check
struct bloom *bloom_bPx3rd; //3rd Bloom filter check
struct checksumsha256 *bloom_bP_checksums;
struct checksumsha256 *bloom_bPx2nd_checksums;
struct checksumsha256 *bloom_bPx3rd_checksums;
#if defined(_WIN64) && !defined(__CYGWIN__)
std::vector<HANDLE> bloom_bP_mutex;
std::vector<HANDLE> bloom_bPx2nd_mutex;
std::vector<HANDLE> bloom_bPx3rd_mutex;
#else
pthread_mutex_t *bloom_bP_mutex;
pthread_mutex_t *bloom_bPx2nd_mutex;
pthread_mutex_t *bloom_bPx3rd_mutex;
#endif
uint64_t bloom_bP_totalbytes = 0;
uint64_t bloom_bP2_totalbytes = 0;
uint64_t bloom_bP3_totalbytes = 0;
uint64_t bsgs_m = 4194304;
uint64_t bsgs_m2;
uint64_t bsgs_m3;
uint64_t bsgs_aux;
uint32_t bsgs_point_number;
const char *str_limits_prefixs[7] = {"Mkeys/s","Gkeys/s","Tkeys/s","Pkeys/s","Ekeys/s","Zkeys/s","Ykeys/s"};
const char *str_limits[7] = {"1000000","1000000000","1000000000000","1000000000000000","1000000000000000000","1000000000000000000000","1000000000000000000000000"};
Int int_limits[7];
Int BSGS_GROUP_SIZE;
Int BSGS_CURRENT;
Int BSGS_R;
Int BSGS_AUX;
Int BSGS_N;
Int BSGS_N_double;
Int BSGS_M; //M is squareroot(N)
Int BSGS_M_double;
Int BSGS_M2; //M2 is M/32
Int BSGS_M2_double; //M2_double is M2 * 2
Int BSGS_M3; //M3 is M2/32
Int BSGS_M3_double; //M3_double is M3 * 2
Int ONE;
Int ZERO;
Int MPZAUX;
Point BSGS_P; //Original P is actually G, but this P value change over time for calculations
Point BSGS_MP; //MP values this is m * P
Point BSGS_MP2; //MP2 values this is m2 * P
Point BSGS_MP3; //MP3 values this is m3 * P
Point BSGS_MP_double; //MP2 values this is m2 * P * 2
Point BSGS_MP2_double; //MP2 values this is m2 * P * 2
Point BSGS_MP3_double; //MP3 values this is m3 * P * 2
std::vector<Point> BSGS_AMP2;
std::vector<Point> BSGS_AMP3;
Point point_temp,point_temp2; //Temp value for some process
Int n_range_start;
Int n_range_end;
Int n_range_diff;
Int n_range_aux;
Int lambda,lambda2,beta,beta2;
Secp256K1 *secp;
int main(int argc, char **argv) {
char buffer[2048];
char rawvalue[32];
struct tothread *tt; //tothread
Tokenizer t,tokenizerbsgs; //tokenizer
char *fileName = NULL;
char *hextemp = NULL;
char *aux = NULL;
char *aux2 = NULL;
char *pointx_str = NULL;
char *pointy_str = NULL;
char *str_seconds = NULL;
char *str_total = NULL;
char *str_pretotal = NULL;
char *str_divpretotal = NULL;
char *bf_ptr = NULL;
char *bPload_threads_available;
FILE *fd,*fd_aux1,*fd_aux2,*fd_aux3;
uint64_t i,BASE,PERTHREAD_R,itemsbloom,itemsbloom2,itemsbloom3;
uint32_t finished;
int readed,continue_flag,check_flag,c,salir,index_value,j;
Int total,pretotal,debugcount_mpz,seconds,div_pretotal,int_aux,int_r,int_q,int58;
struct bPload *bPload_temp_ptr;
size_t rsize;
#if defined(_WIN64) && !defined(__CYGWIN__)
DWORD s;
write_keys = CreateMutex(NULL, FALSE, NULL);
write_random = CreateMutex(NULL, FALSE, NULL);
bsgs_thread = CreateMutex(NULL, FALSE, NULL);
#else
pthread_mutex_init(&write_keys,NULL);
pthread_mutex_init(&write_random,NULL);
pthread_mutex_init(&bsgs_thread,NULL);
int s;
#endif
srand(time(NULL));
secp = new Secp256K1();
secp->Init();
OUTPUTSECONDS.SetInt32(30);
ZERO.SetInt32(0);
ONE.SetInt32(1);
BSGS_GROUP_SIZE.SetInt32(CPU_GRP_SIZE);
#if defined(_WIN64) && !defined(__CYGWIN__)
//Any windows secure random source goes here
rseed(clock() + time(NULL) + rand());
#else
unsigned long rseedvalue;
int bytes_read = getrandom(&rseedvalue, sizeof(unsigned long), GRND_NONBLOCK);
if(bytes_read > 0) {
rseed(rseedvalue);
/*
In any case that seed is for a failsafe RNG, the default source on linux is getrandom function
See https://www.2uo.de/myths-about-urandom/
*/
}
else {
/*
what year is??
WTF linux without RNG ?
*/
fprintf(stderr,"[E] Error getrandom() ?\n");
exit(EXIT_FAILURE);
rseed(clock() + time(NULL) + rand()*rand());
}
#endif
printf("[+] Version %s, developed by AlbertoBSD\n",version);
while ((c = getopt(argc, argv, "deh6MqRSB:b:c:C:E:f:I:k:l:m:N:n:p:r:s:t:v:G:8:z:")) != -1) {
switch(c) {
case 'h':
menu();
break;
case '6':
FLAGSKIPCHECKSUM = 1;
fprintf(stderr,"[W] Skipping checksums on files\n");
break;
case 'B':
index_value = indexOf(optarg,bsgs_modes,5);
if(index_value >= 0 && index_value <= 4) {
FLAGBSGSMODE = index_value;
//printf("[+] BSGS mode %s\n",optarg);
}
else {
fprintf(stderr,"[W] Ignoring unknow bsgs mode %s\n",optarg);
}
break;
case 'b':
bitrange = strtol(optarg,NULL,10);
if(bitrange > 0 && bitrange <=256 ) {
MPZAUX.Set(&ONE);
MPZAUX.ShiftL(bitrange-1);
bit_range_str_min = MPZAUX.GetBase16();
checkpointer((void *)bit_range_str_min,__FILE__,"malloc","bit_range_str_min" ,__LINE__ -1);
MPZAUX.Set(&ONE);
MPZAUX.ShiftL(bitrange);
if(MPZAUX.IsGreater(&secp->order)) {
MPZAUX.Set(&secp->order);
}
bit_range_str_max = MPZAUX.GetBase16();
checkpointer((void *)bit_range_str_max,__FILE__,"malloc","bit_range_str_min" ,__LINE__ -1);
FLAGBITRANGE = 1;
}
else {
fprintf(stderr,"[E] invalid bits param: %s.\n",optarg);
}
break;
case 'c':
index_value = indexOf(optarg,cryptos,3);
switch(index_value) {
case 0: //btc
FLAGCRYPTO = CRYPTO_BTC;
break;
case 1: //eth
FLAGCRYPTO = CRYPTO_ETH;
printf("[+] Setting search for ETH adddress.\n");
break;
/*
case 2: //all
FLAGCRYPTO = CRYPTO_ALL;
break;
*/
default:
FLAGCRYPTO = CRYPTO_NONE;
fprintf(stderr,"[E] Unknow crypto value %s\n",optarg);
exit(EXIT_FAILURE);
break;
}
break;
case 'C':
if(strlen(optarg) == 22) {
FLAGBASEMINIKEY = 1;
str_baseminikey = (char*) malloc(23);
checkpointer((void *)str_baseminikey,__FILE__,"malloc","str_baseminikey" ,__LINE__ - 1);
raw_baseminikey = (char*) malloc(23);
checkpointer((void *)raw_baseminikey,__FILE__,"malloc","raw_baseminikey" ,__LINE__ - 1);
strncpy(str_baseminikey,optarg,22);
for(i = 0; i< 21; i++) {
if(strchr(Ccoinbuffer,str_baseminikey[i+1]) != NULL) {
raw_baseminikey[i] = (int)(strchr(Ccoinbuffer,str_baseminikey[i+1]) - Ccoinbuffer) % 58;
}
else {
fprintf(stderr,"[E] invalid character in minikey\n");
exit(EXIT_FAILURE);
}
}
}
else {
fprintf(stderr,"[E] Invalid Minikey length %li : %s\n",strlen(optarg),optarg);
exit(EXIT_FAILURE);
}
break;
case 'd':
FLAGDEBUG = 1;
printf("[+] Flag DEBUG enabled\n");
break;
case 'e':
FLAGENDOMORPHISM = 1;
printf("[+] Endomorphism enabled\n");
lambda.SetBase16("5363ad4cc05c30e0a5261c028812645a122e22ea20816678df02967c1b23bd72");
lambda2.SetBase16("ac9c52b33fa3cf1f5ad9e3fd77ed9ba4a880b9fc8ec739c2e0cfc810b51283ce");
beta.SetBase16("7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee");
beta2.SetBase16("851695d49a83f8ef919bb86153cbcb16630fb68aed0a766a3ec693d68e6afa40");
break;
case 'f':
FLAGFILE = 1;
fileName = optarg;
break;
case 'I':
FLAGSTRIDE = 1;
str_stride = optarg;
break;
case 'k':
KFACTOR = (int)strtol(optarg,NULL,10);
if(KFACTOR <= 0) {
KFACTOR = 1;
}
printf("[+] K factor %i\n",KFACTOR);
break;
case 'l':
switch(indexOf(optarg,publicsearch,3)) {
case SEARCH_UNCOMPRESS:
FLAGSEARCH = SEARCH_UNCOMPRESS;
printf("[+] Search uncompress only\n");
break;
case SEARCH_COMPRESS:
FLAGSEARCH = SEARCH_COMPRESS;
printf("[+] Search compress only\n");
break;
case SEARCH_BOTH:
FLAGSEARCH = SEARCH_BOTH;
printf("[+] Search both compress and uncompress\n");
break;
}
break;
case 'M':
FLAGMATRIX = 1;
printf("[+] Matrix screen\n");
break;
case 'm':
switch(indexOf(optarg,modes,7)) {
case MODE_XPOINT: //xpoint
FLAGMODE = MODE_XPOINT;
printf("[+] Mode xpoint\n");
break;
case MODE_ADDRESS: //address
FLAGMODE = MODE_ADDRESS;
printf("[+] Mode address\n");
break;
case MODE_BSGS:
FLAGMODE = MODE_BSGS;
//printf("[+] Mode BSGS\n");
break;
case MODE_RMD160:
FLAGMODE = MODE_RMD160;
FLAGCRYPTO = CRYPTO_BTC;
printf("[+] Mode rmd160\n");
break;
case MODE_PUB2RMD:
FLAGMODE = MODE_PUB2RMD;
printf("[+] Mode pub2rmd was removed\n");
exit(0);
break;
case MODE_MINIKEYS:
FLAGMODE = MODE_MINIKEYS;
printf("[+] Mode minikeys\n");
break;
case MODE_VANITY:
FLAGMODE = MODE_VANITY;
printf("[+] Mode vanity\n");
if(vanity_bloom == NULL){
vanity_bloom = (struct bloom*) calloc(1,sizeof(struct bloom));
checkpointer((void *)vanity_bloom,__FILE__,"calloc","vanity_bloom" ,__LINE__ -1);
}
break;
default:
fprintf(stderr,"[E] Unknow mode value %s\n",optarg);
exit(EXIT_FAILURE);
break;
}
break;
case 'n':
FLAG_N = 1;
str_N = optarg;
break;
case 'q':
FLAGQUIET = 1;
printf("[+] Quiet thread output\n");
break;
case 'R':
printf("[+] Random mode\n");
FLAGRANDOM = 1;
FLAGBSGSMODE = 3;
break;
case 'r':
if(optarg != NULL) {
stringtokenizer(optarg,&t);
switch(t.n) {
case 1:
range_start = nextToken(&t);
if(isValidHex(range_start)) {
FLAGRANGE = 1;
range_end = secp->order.GetBase16();
}
else {
fprintf(stderr,"[E] Invalid hexstring : %s.\n",range_start);
}
break;
case 2:
range_start = nextToken(&t);
range_end = nextToken(&t);
if(isValidHex(range_start) && isValidHex(range_end)) {
FLAGRANGE = 1;
}
else {
if(isValidHex(range_start)) {
fprintf(stderr,"[E] Invalid hexstring : %s\n",range_start);
}
else {
fprintf(stderr,"[E] Invalid hexstring : %s\n",range_end);
}
}
break;
default:
printf("[E] Unknow number of Range Params: %i\n",t.n);
break;
}
}
break;
case 's':
OUTPUTSECONDS.SetBase10(optarg);
if(OUTPUTSECONDS.IsLower(&ZERO)) {
OUTPUTSECONDS.SetInt32(30);
}
if(OUTPUTSECONDS.IsZero()) {
printf("[+] Turn off stats output\n");
}
else {
hextemp = OUTPUTSECONDS.GetBase10();
printf("[+] Stats output every %s seconds\n",hextemp);
free(hextemp);
}
break;
case 'S':
FLAGSAVEREADFILE = 1;
break;
case 't':
NTHREADS = strtol(optarg,NULL,10);
if(NTHREADS <= 0) {
NTHREADS = 1;
}
printf((NTHREADS > 1) ? "[+] Threads : %u\n": "[+] Thread : %u\n",NTHREADS);
break;
case 'v':
FLAGVANITY = 1;
if(vanity_bloom == NULL){
vanity_bloom = (struct bloom*) calloc(1,sizeof(struct bloom));
checkpointer((void *)vanity_bloom,__FILE__,"calloc","vanity_bloom" ,__LINE__ -1);
}
if(isValidBase58String(optarg)) {
if(addvanity(optarg) > 0) {
printf("[+] Added Vanity search : %s\n",optarg);
}
else {
printf("[+] Vanity search \"%s\" was NOT Added\n",optarg);
}
}
else {
fprintf(stderr,"[+] The string \"%s\" is not Valid Base58\n",optarg);
}
break;
case '8':
if(strlen(optarg) == 58) {
Ccoinbuffer = optarg;
printf("[+] Base58 for Minikeys %s\n",Ccoinbuffer);
}
else {
fprintf(stderr,"[E] The base58 alphabet must be 58 characters long.\n");
exit(EXIT_FAILURE);
}
break;
case 'z':
FLAGBLOOMMULTIPLIER= strtol(optarg,NULL,10);
if(FLAGBLOOMMULTIPLIER <= 0) {
FLAGBLOOMMULTIPLIER = 1;
}
printf("[+] Bloom Size Multiplier %i\n",FLAGBLOOMMULTIPLIER);
break;
default:
fprintf(stderr,"[E] Unknow opcion -%c\n",c);
exit(EXIT_FAILURE);
break;
}
}
if( FLAGBSGSMODE == MODE_BSGS && FLAGENDOMORPHISM) {
fprintf(stderr,"[E] Endomorphism doesn't work with BSGS\n");
exit(EXIT_FAILURE);
}
if( FLAGBSGSMODE == MODE_BSGS && FLAGSTRIDE) {
fprintf(stderr,"[E] Stride doesn't work with BSGS\n");
exit(EXIT_FAILURE);
}
if(FLAGSTRIDE) {
if(str_stride[0] == '0' && str_stride[1] == 'x') {
stride.SetBase16(str_stride+2);
}
else{
stride.SetBase10(str_stride);
}
printf("[+] Stride : %s\n",stride.GetBase10());
}
else {
FLAGSTRIDE = 1;
stride.Set(&ONE);
}
init_generator();
if(FLAGMODE == MODE_BSGS ) {
printf("[+] Mode BSGS %s\n",bsgs_modes[FLAGBSGSMODE]);
}
if(FLAGFILE == 0) {
fileName =(char*) default_fileName;
}
if(FLAGMODE == MODE_ADDRESS && FLAGCRYPTO == CRYPTO_NONE) { //When none crypto is defined the default search is for Bitcoin
FLAGCRYPTO = CRYPTO_BTC;
printf("[+] Setting search for btc adddress\n");
}
if(FLAGRANGE) {
n_range_start.SetBase16(range_start);
if(n_range_start.IsZero()) {
n_range_start.AddOne();
}
n_range_end.SetBase16(range_end);
if(n_range_start.IsEqual(&n_range_end) == false ) {
if( n_range_start.IsLower(&secp->order) && n_range_end.IsLowerOrEqual(&secp->order) ) {
if( n_range_start.IsGreater(&n_range_end)) {
fprintf(stderr,"[W] Opps, start range can't be great than end range. Swapping them\n");
n_range_aux.Set(&n_range_start);
n_range_start.Set(&n_range_end);
n_range_end.Set(&n_range_aux);
}
n_range_diff.Set(&n_range_end);
n_range_diff.Sub(&n_range_start);
}
else {
fprintf(stderr,"[E] Start and End range can't be great than N\nFallback to random mode!\n");
FLAGRANGE = 0;
}
}
else {
fprintf(stderr,"[E] Start and End range can't be the same\nFallback to random mode!\n");
FLAGRANGE = 0;
}
}
if(FLAGMODE != MODE_BSGS && FLAGMODE != MODE_MINIKEYS) {
BSGS_N.SetInt32(DEBUGCOUNT);
if(FLAGRANGE == 0 && FLAGBITRANGE == 0) {
n_range_start.SetInt32(1);
n_range_end.Set(&secp->order);
n_range_diff.Set(&n_range_end);
n_range_diff.Sub(&n_range_start);
}
else {
if(FLAGBITRANGE) {
n_range_start.SetBase16(bit_range_str_min);
n_range_end.SetBase16(bit_range_str_max);
n_range_diff.Set(&n_range_end);
n_range_diff.Sub(&n_range_start);
}
else {
if(FLAGRANGE == 0) {
fprintf(stderr,"[W] WTF!\n");
}
}
}
}
N = 0;
if(FLAGMODE != MODE_BSGS ) {
if(FLAG_N){
if(str_N[0] == '0' && str_N[1] == 'x') {
N_SEQUENTIAL_MAX =strtol(str_N,NULL,16);
}
else {
N_SEQUENTIAL_MAX =strtol(str_N,NULL,10);
}
if(N_SEQUENTIAL_MAX < 1024) {
fprintf(stderr,"[I] n value need to be equal or great than 1024, back to defaults\n");
FLAG_N = 0;
N_SEQUENTIAL_MAX = 0x100000000;
}
if(N_SEQUENTIAL_MAX % 1024 != 0) {
fprintf(stderr,"[I] n value need to be multiplier of 1024\n");
FLAG_N = 0;
N_SEQUENTIAL_MAX = 0x100000000;
}
}
printf("[+] N = %p\n",(void*)N_SEQUENTIAL_MAX);
if(FLAGMODE == MODE_MINIKEYS) {
BSGS_N.SetInt32(DEBUGCOUNT);
if(FLAGBASEMINIKEY) {
printf("[+] Base Minikey : %s\n",str_baseminikey);
}
minikeyN = (char*) malloc(22);
checkpointer((void *)minikeyN,__FILE__,"malloc","minikeyN" ,__LINE__ -1);
i =0;
int58.SetInt32(58);
int_aux.SetInt64(N_SEQUENTIAL_MAX);
int_aux.Mult(253);
/* We get approximately one valid mini key for each 256 candidates mini keys since this is only statistics we multiply N_SEQUENTIAL_MAX by 253 to ensure not missed one one candidate minikey between threads... in this approach we repeat from 1 to 3 candidates in each N_SEQUENTIAL_MAX cycle IF YOU FOUND some other workaround please let me know */
i = 20;
salir = 0;
do {
if(!int_aux.IsZero()) {
int_r.Set(&int_aux);
int_r.Mod(&int58);
int_q.Set(&int_aux);
minikeyN[i] = (uint8_t)int_r.GetInt64();
int_q.Sub(&int_r);
int_q.Div(&int58);
int_aux.Set(&int_q);
i--;
}
else {
salir =1;
}
}while(!salir && i > 0);
minikey_n_limit = 21 -i;
}
else {
if(FLAGBITRANGE) { // Bit Range
printf("[+] Bit Range %i\n",bitrange);
}
else {
printf("[+] Range \n");
}
}
if(FLAGMODE != MODE_MINIKEYS) {
hextemp = n_range_start.GetBase16();
printf("[+] -- from : 0x%s\n",hextemp);
free(hextemp);
hextemp = n_range_end.GetBase16();
printf("[+] -- to : 0x%s\n",hextemp);
free(hextemp);
}
switch(FLAGMODE) {
case MODE_MINIKEYS:
case MODE_RMD160:
case MODE_ADDRESS:
case MODE_XPOINT:
if(!readFileAddress(fileName)) {
fprintf(stderr,"[E] Unenexpected error\n");
exit(EXIT_FAILURE);
}
break;
case MODE_VANITY:
if(!readFileVanity(fileName)) {
fprintf(stderr,"[E] Unenexpected error\n");
exit(EXIT_FAILURE);
}
break;
}
if(FLAGMODE != MODE_VANITY && !FLAGREADEDFILE1) {
printf("[+] Sorting data ...");
_sort(addressTable,N);
printf(" done! %" PRIu64 " values were loaded and sorted\n",N);
writeFileIfNeeded(fileName);
}
}
if(FLAGMODE == MODE_BSGS ) {
printf("[+] Opening file %s\n",fileName);
fd = fopen(fileName,"rb");
if(fd == NULL) {
fprintf(stderr,"[E] Can't open file %s\n",fileName);
exit(EXIT_FAILURE);
}
aux = (char*) malloc(1024);
checkpointer((void *)aux,__FILE__,"malloc","aux" ,__LINE__ - 1);
while(!feof(fd)) {
if(fgets(aux,1022,fd) == aux) {
trim(aux," \t\n\r");
if(strlen(aux) >= 128) { //Length of a full address in hexadecimal without 04
N++;
}else {
if(strlen(aux) >= 66) {
N++;
}
}
}
}
if(N == 0) {
fprintf(stderr,"[E] There is no valid data in the file\n");
exit(EXIT_FAILURE);
}
bsgs_found = (int*) calloc(N,sizeof(int));
checkpointer((void *)bsgs_found,__FILE__,"calloc","bsgs_found" ,__LINE__ -1 );
OriginalPointsBSGS.reserve(N);
OriginalPointsBSGScompressed = (bool*) malloc(N*sizeof(bool));
checkpointer((void *)OriginalPointsBSGScompressed,__FILE__,"malloc","OriginalPointsBSGScompressed" ,__LINE__ -1 );
pointx_str = (char*) malloc(65);
checkpointer((void *)pointx_str,__FILE__,"malloc","pointx_str" ,__LINE__ -1 );
pointy_str = (char*) malloc(65);
checkpointer((void *)pointy_str,__FILE__,"malloc","pointy_str" ,__LINE__ -1 );
fseek(fd,0,SEEK_SET);
i = 0;
while(!feof(fd)) {
if(fgets(aux,1022,fd) == aux) {
trim(aux," \t\n\r");