bloom filter update to solve some limits, error percent update in keyhunt

This commit is contained in:
AlbertoBSD 2021-03-10 08:19:15 +01:00
parent f4e9d4e6df
commit 49836e059e
6 changed files with 72 additions and 160 deletions

View File

@ -2,6 +2,7 @@
- Added K factor for BSGS
- Added bPfile.c to generate a precalculated file
- Remove unused files about keccak and sha3
- Change Bloom filter limits and % of error from 0.001 to 0.00001 in bloomfilter.
#Version 0.1.20210112 BSGS
- Added mode BSGS this work with a file with uncompressed keys

View File

@ -14,11 +14,11 @@ and then execute:
``./keyhunt``
you need to have tome file called **adddress.txt** or specify other file with the **-f** opcion
you need to have some file called **adddress.txt** or specify other file with the **-f** option
``./keyhunt -f ~/some/path/to/other/file.txt``
if you want more thereads use the **-t** option
if you want more threads use the **-t** option
``./keyhunt -f ~/some/path/to/other/file.txt -t 8``
@ -32,7 +32,7 @@ The default behaivor ot keyhunt is to choose a random key and check secuentialy
# BSGS ( Baby step giant step)
The new version of keyhunt implement the bsgs algorithm to search privatekeys for a knowed publickey.
The new version of keyhunt implement the BSGS algorimth to search privatekeys for a knowed publickey.
The address.txt file need to have a 130 hexadecimal characters uncompress publickey per line any other word followed by an space is ignored example of the file:
@ -52,7 +52,7 @@ btw any word followed by and space after the publickey is ignored the file can b
To try to find those privatekey this is the line of execution:
`` ./keyhunt -m bsgs -f test_120.txt -r 800000000000000000000000000000:FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ``
`` ./keyhunt -m bsgs -f test_120.txt -b 800000000000000000000000000000:FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF``
Output:
@ -86,13 +86,13 @@ Test the puzzle 120 with the next publickey:
```
Line of execution in random mode **-R**
``./keyhunt -m bsgs -f 120.txt -r 800000000000000000000000000000:FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF -R``
``./keyhunt -m bsgs -f 120.txt -b 120 -R``
Example Output:
```
$ ./keyhunt -m bsgs -f 120.txt -r 800000000000000000000000000000:FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF -R
$ ./keyhunt -m bsgs -f 120.txt -b 120 -R
[+] Version 0.1.20210112 BSGS
[+] Setting mode BSGS
[+] Setting random mode.
@ -116,39 +116,66 @@ Good speed no? 1.1 Terakeys/s for one single thread
**Total 35184372088832 keys in 30 seconds: 1172812402961 keys/s**
We can speed up our process selecting a bigger n value **-n value** btw the n value is the total length of item tested in the radom range, and bigger n value means more ram to be use:
We can speed up our process selecting a bigger K value **-k value** btw the n value is the total length of item tested in the radom range, a bigger k value means more ram to be use:
Example:
``$ ./keyhunt -m bsgs -f 120.txt -r 800000000000000000000000000000:FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF -R -n 1000000000000000 -s 120``
``$ ./keyhunt -m bsgs -f 120.txt -b 120 -k 20``
Example output:
```
$ ./keyhunt -m bsgs -f 120.txt -r 800000000000000000000000000000:FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF -R -n 1000000000000000 -s 120
[+] Version 0.1.20210112 BSGS
$ ./keyhunt -m bsgs -f 120.txt -b 120 -k 20 -R -p ~/keyhunt/bPfile.bin
[+] Version 0.1.20210306 K*BSGS
[+] Setting mode BSGS
[+] Min range: 800000000000000000000000000000
[+] Max range: ffffffffffffffffffffffffffffff
[+] Setting k factor to 20
[+] Setting random mode.
[+] Stats output every 120 seconds
[+] Opening file 120.txt
[+] Added 1 points from file
[+] Setting N up to 1000000025191729.
[+] Init bloom filter for 31622777 elements : 54.00 MB
[+] Allocating 965.00 MB for aMP Points
[+] Precalculating 31622777 aMP points
[+] Allocating 1085.00 MB for bP Points
[+] precalculating 31622777 bP points
[+] Sorting 31622777 elements
[+] Thread 0: 0000000000000000000000000000000000f7e37bb1f8b39dc749ff0c6be2b918
[+] Thread 0: 0000000000000000000000000000000000fe37e21c957baf3823262cf7270d67
Total 1000000025191729 keys in 120 seconds: 8333333543264 keys/s
[+] Thread 0: 0000000000000000000000000000000000af1723ee0314a3381a58b5421bce63
Total 2000000050383458 keys in 240 seconds: 8333333543264 keys/s
[+] Bit Range 120
[+] Setting N up to 17592253153280.
[+] Init bloom filter for 83886080 elements : 239.00 MB
[+] Allocating 6.00 MB for aMP Points
[+] Precalculating 209716 aMP points
[+] Allocating 1280.00 MB for bP Points
[+] precalculating 83886080 bP points
[+] Sorting 83886080 elements
(Thread output omited....)
Total 562952100904960 keys in 30 seconds: 18765070030165 keys/s
(Thread output omited....)
Total 2445323188305920 keys in 120 seconds: 20377693235882 keys/s
```
**8.3 Terakeys/s for one single thread**
**20 Terakeys/s for one single thread**
Want to more Speed use a bigger -k value like 120, it will use some 9 GB of RAM
```
[+] Version 0.1.20210306 K*BSGS
[+] Setting mode BSGS
[+] Min range: 800000000000000000000000000000
[+] Max range: ffffffffffffffffffffffffffffff
[+] Setting k factor to 120
[+] Setting random mode.
[+] Opening file 120.txt
[+] Added 1 points from file
[+] Bit Range 120
[+] Setting N up to 17592420925440.
[+] Init bloom filter for 503316480 elements : 1437.00 MB
[+] Allocating 1.00 MB for aMP Points
[+] Precalculating 34953 aMP points
[+] Allocating 7680.00 MB for bP Points
[+] precalculating 503316480 bP points
[+] Sorting 503316480 elements
(Thread output omited....)
Total 3465706922311680 keys in 30 seconds: 115523564077056 keys/s
````
**~100 Terakeys/s for one single thread**
Please be careful with the n value and test it first by you own, againts a knowed publickey/privatekey, some values of n are bugging and I need to solve the errors, please report any extrage behaivor of the tool.
# Dependencies
- libgmp

View File

@ -84,7 +84,7 @@ int main(int argc, char **argv) {
mpz_init_set(P.x,G.x);
mpz_init_set(P.y,G.y);
p_file = fopen(argv[2],"w+b");
p_file = fopen(argv[2],"wb");
if(p_file == NULL) {
printf("Can't create file %s\n",argv[2]);

View File

@ -80,13 +80,13 @@ static int bloom_check_add(struct bloom * bloom,
// DEPRECATED - Please migrate to bloom_init2.
int bloom_init(struct bloom * bloom, int entries, double error)
int bloom_init(struct bloom * bloom, unsigned long long int entries, double error)
{
return bloom_init2(bloom, (unsigned int)entries, error);
return bloom_init2(bloom, entries, error);
}
int bloom_init2(struct bloom * bloom, unsigned int entries, double error)
int bloom_init2(struct bloom * bloom, unsigned long long int entries, double error)
{
memset(bloom, 0, sizeof(struct bloom));
@ -144,7 +144,7 @@ void bloom_print(struct bloom * bloom)
printf("bloom at %p\n", (void *)bloom);
if (!bloom->ready) { printf(" *** NOT READY ***\n"); }
printf(" ->version = %d.%d\n", bloom->major, bloom->minor);
printf(" ->entries = %u\n", bloom->entries);
printf(" ->entries = %lu\n", bloom->entries);
printf(" ->error = %f\n", bloom->error);
printf(" ->bits = %llu\n", bloom->bits);
printf(" ->bits per elem = %f\n", bloom->bpe);

View File

@ -24,7 +24,7 @@ struct bloom
// These fields are part of the public interface of this structure.
// Client code may read these values if desired. Client code MUST NOT
// modify any of these.
unsigned int entries;
unsigned long long int entries;
unsigned long long int bits;
unsigned long long int bytes;
unsigned char hashes;
@ -68,7 +68,7 @@ struct bloom
* 1 - on failure
*
*/
int bloom_init2(struct bloom * bloom, unsigned int entries, double error);
int bloom_init2(struct bloom * bloom, unsigned long long int entries, double error);
/**
@ -76,7 +76,7 @@ int bloom_init2(struct bloom * bloom, unsigned int entries, double error);
* Kept for compatibility with libbloom v.1. To be removed in v3.0.
*
*/
int bloom_init(struct bloom * bloom, int entries, double error);
int bloom_init(struct bloom * bloom, unsigned long long int entries, double error);
/** ***************************************************************************

136
keyhunt.c
View File

@ -1,4 +1,3 @@
/*
Develop by Luis Alberto
email: alberto.bsd@gmail.com
@ -101,7 +100,6 @@ const char *minus_params[2] = {"quiet","help"};
pthread_t *tid = NULL;
pthread_mutex_t write_keys;
pthread_mutex_t write_range;
pthread_mutex_t write_random;
pthread_mutex_t threads_end;
pthread_mutex_t bsgs_thread;
@ -427,16 +425,13 @@ int main(int argc, char **argv) {
break;
}
}
/*
gmp_printf("[+] %Zu\n",EC.p);
gmp_printf("[+] %Zu\n",EC.n);
*/
if(FLAGMODE != MODE_BSGS && FLAGRANDOM == 1) {
FLAGRANGE = 0;
}
if(DEBUGCOUNT > N_SECUENTIAL_MAX) {
DEBUGCOUNT = N_SECUENTIAL_MAX - 1;
//printf("Setting debug count to %u",N_SECUENTIAL_MAX);
}
if(FLAGFILE == 0) {
filename =(char*) default_filename;
@ -503,7 +498,6 @@ int main(int argc, char **argv) {
hextemp = fgets(aux,1000,fd);
if(hextemp == aux) {
trim(aux," \t\n\r");
//printf("reading %s\n",aux);
r = strlen(aux);
if(r > 10) { //Any length for invalid Address?
if(r > MAXLENGTHADDRESS) {
@ -532,13 +526,13 @@ int main(int argc, char **argv) {
}
printf("[+] Initializing bloom filter for %u elements.\n",N);
if(N <= 10000) {
if(bloom_init2(&bloom,10000,0.0001) == 1){
if(bloom_init2(&bloom,10000,0.00001) == 1){
fprintf(stderr,"[E] error bloom_init for 10000 elements.\n");
exit(0);
}
}
else {
if(bloom_init2(&bloom,N,0.0001) == 1){
if(bloom_init2(&bloom,N,0.00001) == 1){
fprintf(stderr,"[E] error bloom_init for %u elements.\n",N);
fprintf(stderr,"[+] man enough is enough stop it\n");
exit(0);
@ -796,13 +790,13 @@ int main(int argc, char **argv) {
printf("[+] Setting N up to %llu.\n",(long long unsigned int)DEBUGCOUNT);
if(bsgs_m > 1000) {
if(bloom_init2(&bloom_bPx,bsgs_m,0.001) == 1){
if(bloom_init2(&bloom_bPx,bsgs_m,0.00001) == 1){
fprintf(stderr,"[E] error bloom_init for %lu elements\n",bsgs_m);
exit(0);
}
}
else {
if(bloom_init2(&bloom_bPx,1000,0.001) == 1){
if(bloom_init2(&bloom_bPx,1000,0.00001) == 1){
fprintf(stderr,"[E] error bloom_init for 1000 elements\n");
exit(0);
}
@ -1040,9 +1034,11 @@ int main(int argc, char **argv) {
mpz_init(debugcount_mpz);
sprintf(temporal,"%llu",(long long unsigned int)DEBUGCOUNT);
mpz_set_str(debugcount_mpz,temporal,10);
/*
printf("DEBUGCOUNT: %llu\n",DEBUGCOUNT);
gmp_printf("debugcount_mpz: %Zu\n",debugcount_mpz);
printf("NTHREADS: %i\n",NTHREADS);
*/
do {
sleep(1);
seconds+=1;
@ -1064,7 +1060,6 @@ int main(int argc, char **argv) {
i = 0;
while(i < NTHREADS) {
mpz_mul_ui(pretotal,debugcount_mpz,steps[i]);
/*printf("steps: %i\n",steps[i]);*/
mpz_add(total,total,pretotal);
i++;
}
@ -1106,105 +1101,10 @@ void Point_Doubling(struct Point *P, struct Point *R) {
mpz_clear(slope);
}
/*
void Point_Doubling(struct Point *P, struct Point *R) {
mpz_t slope, temp;
mpz_init(temp);
mpz_init(slope);
if(mpz_cmp_ui(P->y, 0) != 0) {
mpz_mul_ui(temp, P->y, 2);
mpz_invert(temp, temp, EC.p);
mpz_mul(slope, P->x, P->x);
mpz_mul_ui(slope, slope, 3);
mpz_mul(slope, slope, temp);
mpz_mod(slope, slope, EC.p);
mpz_mul(R->x, slope, slope);
mpz_sub(R->x, R->x, P->x);
mpz_sub(R->x, R->x, P->x);
mpz_mod(R->x, R->x, EC.p);
mpz_sub(temp, P->x, R->x);
mpz_mul(R->y, slope, temp);
mpz_sub(R->y, R->y, P->y);
mpz_mod(R->y, R->y, EC.p);
} else {
mpz_set_ui(R->x, 0);
mpz_set_ui(R->y, 0);
}
mpz_clear(temp);
mpz_clear(slope);
}
*/
/*
void Point_Addition(struct Point *P, struct Point *Q, struct Point *R) {
mpz_t PA_temp,PA_slope;
mpz_init(PA_temp);
mpz_init(PA_slope);
mpz_mod(Q->x, Q->x, EC.p);
mpz_mod(Q->y, Q->y, EC.p);
mpz_mod(P->x, P->x, EC.p);
mpz_mod(P->y, P->y, EC.p);
if(mpz_cmp_ui(P->x, 0) == 0 && mpz_cmp_ui(P->y, 0) == 0) {
mpz_set(R->x, Q->x);
mpz_set(R->y, Q->y);
}
else {
if(mpz_cmp_ui(Q->x, 0) == 0 && mpz_cmp_ui(Q->y, 0) == 0) {
mpz_set(R->x, P->x);
mpz_set(R->y, P->y);
}
else {
if(mpz_cmp_ui(Q->y, 0) != 0) {
mpz_sub(PA_temp, EC.p, Q->y);
mpz_mod(PA_temp, PA_temp, EC.p);
}
else {
mpz_set_ui(PA_temp, 0);
}
if(mpz_cmp(P->y, PA_temp) == 0 && mpz_cmp(P->x, Q->x) == 0) {
mpz_set_ui(R->x, 0);
mpz_set_ui(R->y, 0);
}
else {
if(mpz_cmp(P->x, Q->x) == 0 && mpz_cmp(P->y, Q->y) == 0) {
Point_Doubling(P, R);
}
else {
mpz_set_ui(PA_slope, 0);
mpz_sub(PA_temp, P->x, Q->x);
mpz_mod(PA_temp, PA_temp, EC.p);
mpz_invert(PA_temp, PA_temp, EC.p);
mpz_sub(PA_slope, P->y, Q->y);
mpz_mul(PA_slope, PA_slope, PA_temp);
mpz_mod(PA_slope, PA_slope, EC.p);
mpz_mul(R->x, PA_slope, PA_slope);
mpz_sub(R->x, R->x, P->x);
mpz_sub(R->x, R->x, Q->x);
mpz_mod(R->x, R->x, EC.p);
mpz_sub(PA_temp, P->x, R->x);
mpz_mul(R->y, PA_slope, PA_temp);
mpz_sub(R->y, R->y, P->y);
mpz_mod(R->y, R->y, EC.p);
}
}
}
}
mpz_clear(PA_temp);
mpz_clear(PA_slope);
}
*/
void Point_Addition(struct Point *P, struct Point *Q, struct Point *R) {
mpz_t PA_temp,PA_slope;
mpz_init(PA_temp);
mpz_init(PA_slope);
/*
mpz_mod(Q->x, Q->x, EC.p);
mpz_mod(Q->y, Q->y, EC.p);
mpz_mod(P->x, P->x, EC.p);
mpz_mod(P->y, P->y, EC.p);
*/
if(mpz_cmp_ui(P->x, 0) == 0 && mpz_cmp_ui(P->y, 0) == 0) {
mpz_set(R->x, Q->x);
mpz_set(R->y, Q->y);
@ -1430,16 +1330,8 @@ void *thread_process(void *vargp) {
pthread_mutex_unlock(&write_random);
hextemp = malloc(65);
gmp_sprintf(hextemp,"%0.64Zx",random_key_mpz);
pthread_mutex_lock(&write_range);
printf("Thread %i : Setting up base key: %s\n",thread_number,hextemp);
/*
range_file = fopen("./ranges.txt","a+");
if(range_file != NULL) {
fprintf(range_file,"%s\n",hextemp);
fclose(range_file);
}
*/
pthread_mutex_unlock(&write_range);
free(hextemp);
Scalar_Multiplication(G, &R, random_key_mpz);
count = 0;
@ -1633,15 +1525,7 @@ void *thread_process_range(void *vargp) {
exit(0);
}
printf("Thread %i : Setting up base key: %s\n",thread_number,tt->rs);
pthread_mutex_lock(&write_range);
/*
range_file = fopen("./ranges.txt","a+");
if(range_file != NULL) {
fprintf(range_file,"%s\n",tt->rs);
fclose(range_file);
}
*/
pthread_mutex_unlock(&write_range);
free(tt->rs);
free(tt->rpt);
free(tt);