My changes:
In Constans.h:
#define CLIENT_TIMEOUT 36000.0
In Kangaroo.cpp:
...added
bool Kangaroo::output(string msg) {
FILE *f = stdout;
f = fopen("Result.txt", "a");
if (f == NULL) {
printf("[error] Cannot open file Result.txt\n");
f = stdout;
return false;
}
else {
fprintf(f, "%s\n", msg.c_str());
fclose(f);
printf("[i] Success saved to file Result.txt\n");
return true;
}
}
// ----------------------------------------------------------------------------
bool Kangaroo::CheckKey(Int d1,Int d2,uint8_t type) {
// Resolve equivalence collision
if(type & 0x1)
d1.ModNegK1order();
if(type & 0x2)
d2.ModNegK1order();
Int pk(&d1);
pk.ModAddK1order(&d2);
Point P = secp->ComputePublicKey(&pk);
if(P.equals(keyToSearch)) {
// Key solved
#ifdef USE_SYMMETRY
pk.ModAddK1order(&rangeWidthDiv2);
#endif
pk.ModAddK1order(&rangeStart);
Point PR = secp->ComputePublicKey(&pk);
::printf("\nKey#%2d [%dN]Pub: 0x%s \n",keyIdx,type,secp->GetPublicKeyHex(true,keysToSearch[keyIdx]).c_str());
// Save Priv
std::string prvkey = pk.GetBase16().c_str();
bool save_pk = output(prvkey + string(":") + string("04") + PR.x.GetBase16().c_str() + PR.y.GetBase16().c_str() );
if( PR.equals(keysToSearch[keyIdx]) ) {
::printf(" Priv: 0x%s \n",pk.GetBase16().c_str());
} else {
::printf(" Failed !\n");
::printf(" Priv: 0x%s \n",pk.GetBase16().c_str());
return false;
}
return true;
}
if(P.equals(keyToSearchNeg)) {
// Key solved
pk.ModNegK1order();
#ifdef USE_SYMMETRY
pk.ModAddK1order(&rangeWidthDiv2);
#endif
pk.ModAddK1order(&rangeStart);
Point PR = secp->ComputePublicKey(&pk);
::printf("\nKey#%2d [%dS]Pub: 0x%s \n",keyIdx,type,secp->GetPublicKeyHex(true,keysToSearch[keyIdx]).c_str());
// Save Priv
std::string prvkeyNeg = pk.GetBase16().c_str();
bool save_pk = output(prvkeyNeg + string(":") + string("04") + PR.x.GetBase16().c_str() + PR.y.GetBase16().c_str() );
if(PR.equals(keysToSearch[keyIdx]) ) {
::printf(" Priv: 0x%s \n",pk.GetBase16().c_str());
} else {
::printf(" Failed !\n");
::printf(" Priv: 0x%s \n",pk.GetBase16().c_str());
return false;
}
return true;
}
return false;
}
afer
bool Kangaroo::ParseConfigFile(std::string &fileName) {
// In client mode, config come from the server
if(clientMode)
return true;
// Check file
FILE *fp = fopen(fileName.c_str(),"rb");
if(fp == NULL) {
::printf("Error: Cannot open %s %s\n",fileName.c_str(),strerror(errno));
return false;
}
fclose(fp);
// Get lines
vector lines;
int nbLine = 0;
string line;
ifstream inFile(fileName);
while(getline(inFile,line)) {
// Remove ending \r\n
int l = (int)line.length() - 1;
while(l >= 0 && isspace(line.at(l))) {
line.pop_back();
l--;
}
if(line.length() > 0) {
lines.push_back(line);
nbLine++;
}
}
if(lines.size()<3) {
::printf("Error: %s not enough arguments\n",fileName.c_str());
return false;
}
rangeStart.SetBase16((char *)lines[0].c_str());
rangeEnd.SetBase16((char *)lines[1].c_str());
for(int i=2;i<(int)lines.size();i++) {
Point p;
bool isCompressed;
if( !secp->ParsePublicKeyHex(lines[i],p,isCompressed) ) {
::printf("%s, error line %d: %s\n",fileName.c_str(),i,lines[i].c_str());
return false;
}
keysToSearch.push_back(p);
}
::printf("Start:%s\n",rangeStart.GetBase16().c_str());
::printf("Stop :%s\n",rangeEnd.GetBase16().c_str());
::printf("Keys :%d\n",(int)keysToSearch.size());
return true;
}
// ----------------------------------------------------------------------------
and in Kangaroo.h
added
bool output(std::string msg);
after
and before
int wtimeout;
int ntimeout;
(section //Backup stuff)