I try description algorim. But I do not understand a few moments.
int main(int argc, char **argv) {
secp256k1_context *ctx = secp256k1_context_create(SECP256K1_CONTEXT_NONE);
int next = 0;//Initial varibale next for cicl search in publick kes
//Convert publik keys from raw to eckey format. Nothing intresested.
for (int i = 0; i < NUMPUBKEYS; i++) {
if (!secp256k1_eckey_pubkey_parse(&pubkeys[i], rawpubkeys[i], 33)) {
printf("Unparsable pubkey %2d\n", i);
return -1;
}
}
printf("Build Hash\n");
secp256k1_gej pt;//Init variable pt
secp256k1_gej_set_ge(&pt, &secp256k1_ge_const_g);//??????
//Start cicle from 1 to GSTEP (1<<25 or other count bits). With step one.
for (size_t i = 1; i < GSTEP; i++) {
/*if(i%1000000==0){
printf("Generate %zu from %2d \n", i, GSTEP);
}*/
secp256k1_fe x,zinv;//Init variable z and zinv
secp256k1_fe_storage xst;//Init variable xst
secp256k1_fe_inv_var(&zinv, &pt.z);//????????? Maybe inverted variable. But zinv or pt.z?
secp256k1_fe_sqr(&zinv, &zinv);//Sqr from who? Sqr zinv from zinv?
secp256k1_fe_mul(&x, &pt.x, &zinv);//Multiple x pt.x and zinv. But who changes?
secp256k1_fe_to_storage(&xst, &x);//Return hash data to xst from x . xst this array from 8 part of hashes.
uint32_t entry = xst.n[0] & (HASH_SIZE-1);//In entry getted last (25-1 or other setted count bit) bit from xst.n[0] (first part from hash)
while (table[entry].exponent != 0) {//Cicle run if in table with key entry already setted data.
entry = (entry + (xst.n[1] | 1)) & (HASH_SIZE - 1);//Changed entry. In current xst.n[1] setted last bit to 1 plus add current entry. From this value get last 25-1 or other setted bits.
}//This is algortim searned free row in table with changed key by algoritm in up.
table[entry].exponent = i;//Set in table with key entry to subkey exponent varuibale i (currently pozition in main for)
table[entry].x = xst.n[2];//Set in table with key entry to subkey x, xst.n[2] (part of hash from storage)
//------------
//I try inserte here searched this hash in curently public keys. Algoritm founded, but maksimal found 25 or other setted bit, no more! Logical is true.
//------------
secp256k1_gej_add_ge_var(&pt, &pt, &secp256k1_ge_const_g, NULL);//????????????
}
//End generated main table
//But undestord. Variable i not used for generated hashes. Who is used aka privatkey?
printf("Search Keys\n");
secp256k1_ge ptgstep;//Init variable ptgstep
secp256k1_gej_neg(&pt, &pt);//Negativation pt ????? pt from previos step?
secp256k1_gej_double_var(&pt, &pt, NULL);//Double pt ???
secp256k1_ge_set_gej(&ptgstep, &pt);//????
secp256k1_gej_set_infinity(&pt);//????
//In up init variable from main cicl.
//Start cicl i from 0 (previos cilck start from 1). To 2*GSTEP (double gstep). With step 1.
for (size_t i = 0; i < 2*GSTEP; i++) {
//Start cicl j from next (dinamic variable for exclude founded keys on begin array). To NUMPUBKEYS (coun publick keys). With step 1.
for (int j = next; j < NUMPUBKEYS; j++) {
secp256k1_gej diff;//Init variable diff
secp256k1_fe x,zinv;//Init variable x and zinv
secp256k1_fe_storage xst;//Init variable xst
secp256k1_gej_add_ge_var(&diff, &pt, &pubkeys[j], NULL);//????? May be added variable diff, pt and pubkeys[j] (currently publick key)
secp256k1_fe_inv_var(&zinv, &diff.z);//??????Maybe inverted variable. But zinv or pt.z?
secp256k1_fe_sqr(&zinv, &zinv);//Sqr from who? Sqr zinv from zinv?
secp256k1_fe_mul(&x, &diff.x, &zinv);//Multiple x pt.x and zinv. But who changes?
secp256k1_fe_to_storage(&xst, &x);//Return hash data to xst from x . xst this array from 8 part of hashes.
uint32_t entry = xst.n[0] & (HASH_SIZE-1);//In entry getted last (25-1 or other setted count bit) bit from xst.n[0] (first part from hash)
//-----------------
//I try showed this entry for each publcik addr. And with each new cycle, this value was different for the same public key. Why?
//-----------------
while (table[entry].exponent != 0) {//Cicl run if in table with key entry present data.
if (table[entry].x == (uint32_t) xst.n[2]) {//If table[entry].x (hash part 2 generated in in prevos loop) equal xst.n[2] (hash part 2 from currently publik key) run block down
uint64_t key = (uint64_t) i * (uint64_t) (2 * GSTEP);//Generate varibale key. i * (2*GSTEP) . !!!!!!!!!!! Do not understand the logic. !!!!!!!!!!
//show founded key
printf("Found private key %2d: %16lx or %16lx\n", j + 1,
key - table[entry].exponent,
key + table[entry].exponent);
next++;//Add in variable next +1; Exclude this publick key from next searched.
if (next == NUMPUBKEYS)//if next equal NUMPUBKEYS, found ded last key, programm is stop
return 0;
}
entry = (entry + (xst.n[1] | 1)) & (HASH_SIZE - 1);//Changed entry. In current xst.n[1] setted last bit to 1 plus add current entry. From this value get last 25-1 or other setted bits.
}
if (j == next)///????????? In cycl each firt loop this is true, break? not searched other public keys.
break;
}
secp256k1_gej_add_ge_var(&pt, &pt, &ptgstep, NULL);//?????????? Choto gdeto kakto
}
return 0;
}