-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathkeyhunt.cpp
6154 lines (5471 loc) · 174 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 Luis Alberto
email: alberto.bsd@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>
#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_CHECK 6
#define SEARCH_UNCOMPRESS 0
#define SEARCH_COMPRESS 1
#define SEARCH_BOTH 2
#define FLIPBITLIMIT 10000000
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.211117 SSE Trick or treat ¡Beta!";
#define CPU_GRP_SIZE 1024
std::vector<Point> Gn;
Point _2Gn;
std::vector<Point> GSn;
Point _2GSn;
std::vector<Point> GSn2;
Point _2GSn2;
std::vector<Point> GSn3;
Point _2GSn3;
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);
#if defined(_WIN64) && !defined(__CYGWIN__)
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);
DWORD WINAPI thread_pub2rmd(LPVOID vargp);
//DWORD WINAPI thread_process_check_file_btc(LPVOID vargp);
#else
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);
void *thread_pub2rmd(void *vargp);
//void *thread_process_check_file_btc(void *vargp);
#endif
char *publickeytohashrmd160(char *pkey,int length);
void publickeytohashrmd160_dst(char *pkey,int length,char *dst);
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);
void memorycheck_bsgs();
int THREADOUTPUT = 0;
char *bit_range_str_min;
char *bit_range_str_max;
const char *bsgs_modes[5] {"secuential","backward","both","random","dance"};
const char *modes[6] = {"xpoint","address","bsgs","rmd160","pub2rmd","minikeys"};
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;
#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;
#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 */
//uint8_t byte_encode_crypto = 0x1E; /* Dogecoin */
struct bloom bloom;
uint64_t *steps = NULL;
unsigned int *ends = NULL;
uint64_t N = 0;
uint64_t N_SECUENTIAL_MAX = 0x100000000;
uint64_t DEBUGCOUNT = 0x400;
uint64_t u64range;
Int OUTPUTSECONDS;
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 FLAGVANITY = 0;
int FLAGMODE = MODE_ADDRESS;
int FLAGCRYPTO = 0;
int FLAGALREADYSORTED = 0;
int FLAGRAWDATA = 0;
int FLAGRANDOM = 0;
int FLAG_N = 0;
int FLAGPRECALCUTED_P_FILE = 0;
int COUNT_VANITIES = 0;
int *len_vanities;
int bitrange;
char *str_N;
char **vanities;
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;
unsigned long int 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_M; //M is squareroot(N)
Int BSGS_M2;
Int BSGS_M3;
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
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;
Secp256K1 *secp;
int main(int argc, char **argv) {
char buffer[2048];
char temporal[65];
char rawvalue[32];
struct tothread *tt; //tothread
Tokenizer t,tokenizerbsgs,tokenizer_xpoint; //tokenizer
char *filename = NULL;
char *precalculated_mp_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 j,total_precalculated,i,PERTHREAD,BASE,PERTHREAD_R,itemsbloom,itemsbloom2,itemsbloom3;
uint32_t finished;
int readed,continue_flag,check_flag,r,lenaux,lendiff,c,salir,index_value;
Int total,pretotal,debugcount_mpz,seconds,div_pretotal,int_aux,int_r,int_q,int58;
struct bPload *bPload_temp_ptr;
#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);
rseed(clock() + time(NULL));
#if defined(_WIN64) && !defined(__CYGWIN__)
printf("[+] Version %s, developed by AlbertoBSD(Win64 build by KV)\n", version);
#else
printf("[+] Version %s, developed by AlbertoBSD\n",version);
#endif
while ((c = getopt(argc, argv, "dehMqRwzSB:b:c:C:E:f:I:k:l:m:N:n:p:r:s:t:v:V:G:8:")) != -1) {
switch(c) {
case 'h':
printf("\nUsage:\n-h\t\tshow this help\n");
printf("-B Mode\t\tBSGS now have some modes <secuential,backward,both,random,dance>\n");
printf("-b bits\t\tFor some puzzles you only need some numbers of bits in the test keys.\n");
printf("-c crypto\tSearch for specific crypo. < btc, eth, all > valid only w/ -m address \n");
printf("-C mini\t\tSet the minikey Base only 22 character minikeys, ex: SRPqx8QiwnW4WNWnTVa2W5\n");
printf("-8 alpha\t\tSet the bas58 alphabet for minikeys");
printf("-f file\t\tSpecify filename with addresses or xpoints or uncompressed public keys\n");
printf("-I stride\tStride for xpoint, rmd160 and address, this option don't work with bsgs \n");
printf("-k value\tUse this only with bsgs mode, k value is factor for M, more speed but more RAM use wisely\n");
printf("-l look\tWhat type of address/hash160 are you looking for < compress , uncompress , both> Only for rmd160 and address\n");
printf("-m mode\t\tmode of search for cryptos. ( bsgs , xpoint , rmd160 , address ) default: address (more slow)\n");
printf("-M\t\tMatrix screen, feel like a h4x0r, but performance will droped\n");
printf("-n uptoN\tCheck for N secuential numbers before the random chossen this only work with -R option\n");
printf("\t\tUse -n to set the N for the BSGS process. Bigger N more RAM needed\n");
printf("-q\t\tQuiet the thread output\n");
printf("-r SR:EN\tStarRange:EndRange, the end range can be omited for search from start range to N-1 ECC value\n");
printf("-R\t\tRandom this is the default behaivor\n");
printf("-s ns\t\tNumber of seconds for the stats output, 0 to omit output.\n");
printf("-S\t\tCapital S is for SAVING in files BSGS data (Bloom filters and bPtable)\n");
printf("-t tn\t\tThreads number, must be positive integer\n");
printf("-v va\t\tSearch for vanity Address, only with -m address\n");
printf("-V file\t\tFile with vanity Address to search, only with -m address");
printf("-w\t\tMark the input file as RAW data xpoint fixed 32 byte each point. Valid only with -m xpoint\n");
printf("\nExample\n\n");
printf("%s -t 16 -r 1:FFFFFFFF -s 0\n\n",argv[0]);
printf("This line run the program with 16 threads from the range 1 to FFFFFFFF without stats output\n\n");
printf("Developed by AlbertoBSD\tTips BTC: 1ABSD1rMTmNZHJrJP8AJhDNG1XbQjWcRz7\n");
printf("Thanks to Iceland always helping and sharing his ideas.\nTips to Iceland: bc1q39meky2mn5qjq704zz0nnkl0v7kj4uz6r529at\n\n");
exit(0);
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();
MPZAUX.Set(&ONE);
MPZAUX.ShiftL(bitrange);
if(MPZAUX.IsGreater(&secp->order)) {
MPZAUX.Set(&secp->order);
}
bit_range_str_max = MPZAUX.GetBase16();
if(bit_range_str_min == NULL||bit_range_str_max == NULL) {
fprintf(stderr,"[E] error malloc()\n");
exit(0);
}
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;
printf("[+] Setting search for BTC adddress.\n");
break;
case 1: //eth
FLAGCRYPTO = CRYPTO_ETH;
printf("[+] Setting search for ETH adddress.\n");
break;
case 2: //all
FLAGCRYPTO = CRYPTO_ALL;
printf("[+] Setting search for all cryptocurrencies avaible [btc].\n");
break;
default:
FLAGCRYPTO = CRYPTO_NONE;
fprintf(stderr,"[E] Unknow crypto value %s\n",optarg);
exit(0);
break;
}
break;
case 'C':
if(strlen(optarg) == 22) {
FLAGBASEMINIKEY = 1;
str_baseminikey = (char*) malloc(23);
raw_baseminikey = (char*) malloc(23);
if(str_baseminikey == NULL || raw_baseminikey == NULL) {
fprintf(stderr,"[E] malloc()\n");
}
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(0);
}
}
}
else {
fprintf(stderr,"[E] Invalid Minikey length %i : %s\n",strlen(optarg),optarg);
exit(0);
}
break;
case 'd':
FLAGDEBUG = 1;
printf("[+] Flag DEBUG enabled\n");
break;
case 'e':
FLAGALREADYSORTED = 1;
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,6)) {
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\n");
break;
case MODE_MINIKEYS:
FLAGMODE = MODE_MINIKEYS;
printf("[+] Mode minikeys\n");
break;
/*
case MODE_CHECK:
FLAGMODE = MODE_CHECK;
printf("[+] Mode CHECK\n");
break;
*/
default:
fprintf(stderr,"[E] Unknow mode value %s\n",optarg);
exit(0);
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)) {
printf("[E] Invalid hexstring : %s\n",range_start);
}
else {
printf("[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(COUNT_VANITIES > 0) {
vanities = (char**)realloc(vanities,(COUNT_VANITIES +1 ) * sizeof(char*));
len_vanities = (int*)realloc(len_vanities,(COUNT_VANITIES +1 ) * sizeof(int));
}
else {
vanities = (char**)malloc(sizeof(char*));
len_vanities = (int*)malloc(sizeof(int));
}
if(vanities == NULL || len_vanities == NULL) {
fprintf(stderr,"[E] malloc!\n");
exit(0);
}
len_vanities[COUNT_VANITIES] = strlen(optarg);
vanities[COUNT_VANITIES] = (char*)malloc(len_vanities[COUNT_VANITIES]+2);
if(vanities[COUNT_VANITIES] == NULL) {
fprintf(stderr,"[E] malloc!\n");
exit(0);
}
snprintf(vanities[COUNT_VANITIES],len_vanities[COUNT_VANITIES]+1 ,"%s",optarg);
printf("[+] Added Vanity search : %s\n",vanities[COUNT_VANITIES]);
COUNT_VANITIES++;
break;
case 'V':
FLAGVANITY = 1;
printf("[+] Added Vanity file : %s\n",optarg);
fd = fopen(optarg,"r");
if(fd == NULL) {
fprintf(stderr,"[E] Can't open the file : %s\n",optarg);
exit(0);
}
r = 0;
do {
fgets(buffer,1024,fd);
trim(buffer,"\n\t\r ");
if(strlen(buffer) > 0) {
r++;
}
memset(buffer,0,1024);
}while(!feof(fd));
if(r > 0) {
if(COUNT_VANITIES > 0) {
vanities = (char**)realloc(vanities,(COUNT_VANITIES + r ) * sizeof(char*));
len_vanities = (int*)realloc(len_vanities,(COUNT_VANITIES + r )* sizeof(int));
}
else {
vanities = (char**)malloc( r * sizeof(char*));
len_vanities = (int*)malloc(r * sizeof(int));
}
if(vanities == NULL || len_vanities == NULL) {
fprintf(stderr,"[E] malloc!\n");
exit(0);
}
fseek(fd,0,SEEK_SET);
index_value = 0;
while(index_value < r){
fgets(buffer,1024,fd);
trim(buffer,"\n\t\r ");
if(strlen(buffer) > 0) {
len_vanities[COUNT_VANITIES+index_value] = strlen(buffer);
vanities[COUNT_VANITIES+index_value] = (char*) malloc(len_vanities[COUNT_VANITIES+index_value]+2);
if(vanities[COUNT_VANITIES+index_value] == NULL) {
fprintf(stderr,"[E] malloc!\n");
exit(0);
}
snprintf(vanities[COUNT_VANITIES+index_value],len_vanities[COUNT_VANITIES+index_value]+1 ,"%s",buffer);
printf("[D] Added Vanity search : %s\n",vanities[COUNT_VANITIES+index_value]);
}
memset(buffer,0,1024);
index_value++;
}
COUNT_VANITIES+= r;
}
else {
fprintf(stderr,"[W] file %s is emptied\n",optarg);
if(COUNT_VANITIES == 0) {
FLAGVANITY = 0;
}
}
fclose(fd);
fd = NULL;
break;
case 'w':
printf("[+] Data marked as RAW\n");
FLAGRAWDATA = 1;
break;
case '8':
if(strlen(optarg) != 58) {
fprintf(stderr,"[W] The base58 alphabet must be 58 characters long.\n");
}
else {
Ccoinbuffer = optarg;
printf("[+] Base58 for Minikeys %s\n",Ccoinbuffer);
}
break;
default:
fprintf(stderr,"[E] Unknow opcion -%c\n",c);
break;
}
}
if( ( FLAGBSGSMODE == MODE_BSGS || FLAGBSGSMODE == MODE_PUB2RMD ) && FLAGSTRIDE == 1) {
fprintf(stderr,"[E] Stride doesn't work with BSGS, pub2rmd\n");
exit(0);
}
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;
}
printf("[+] Opening file %s\n",filename);
fd = fopen(filename,"rb");
if(fd == NULL) {
fprintf(stderr,"[E] Can't open file %s\n",filename);
exit(0);
}
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(FLAGCRYPTO == CRYPTO_ETH) {
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_SECUENTIAL_MAX =strtol(str_N,NULL,16);
}
else {
N_SECUENTIAL_MAX =strtol(str_N,NULL,10);
}
if(N_SECUENTIAL_MAX < 1024) {
fprintf(stderr,"[I] n value need to be equal or great than 1024, back to defaults\n");
FLAG_N = 0;
N_SECUENTIAL_MAX = 0x100000000;
}
if(N_SECUENTIAL_MAX % 1024 != 0) {
fprintf(stderr,"[I] n value need to be multiplier of 1024\n");
FLAG_N = 0;
N_SECUENTIAL_MAX = 0x100000000;
}
}
printf("[+] N = %p\n",(void*)N_SECUENTIAL_MAX);
if(FLAGMODE == MODE_MINIKEYS) {
BSGS_N.SetInt32(DEBUGCOUNT);
if(FLAGBASEMINIKEY) {
printf("[+] Base Minikey : %s\n",str_baseminikey);
/*
for(i = 0; i < 21;i ++) {
printf("%i ",(uint8_t) raw_baseminikey[i]);
}
printf("\n");
*/
}
minikeyN = (char*) malloc(22);
if(minikeyN == NULL) {
fprintf(stderr,"[E] malloc()\n");
exit(0);
}
i =0;
int58.SetInt32(58);
int_aux.SetInt64(N_SECUENTIAL_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_SECUENTIAL_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_SECUENTIAL_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;
/*
for(i = 0; i < 21;i ++) {
printf("%i ",(uint8_t) minikeyN[i]);
}
printf(": minikey_n_limit %i\n",minikey_n_limit);
*/
}
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);
}
aux =(char*) malloc(1000);
if(aux == NULL) {
fprintf(stderr,"[E] error malloc()\n");
}
switch(FLAGMODE) {
case MODE_ADDRESS:
/* We need to count how many lines are in the file */
while(!feof(fd)) {
hextemp = fgets(aux,998,fd);
if(hextemp == aux) {
trim(aux," \t\n\r");
r = strlen(aux);