Browse Source

(vain) calculate a key for a thread instead one a key for all threads https://github.com/PurpleI2P/i2pd-tools/issues/92

pull/93/head
startyourday60 9 months ago
parent
commit
2d06872f52
  1. 26
      vain.cpp
  2. 2
      vanity.hpp

26
vain.cpp

@ -7,6 +7,7 @@
//#include<format> // is not supports for me //#include<format> // is not supports for me
// some global vars in vanitygen.hpp // some global vars in vanitygen.hpp
static unsigned short fKeyId = 0;
static struct{ static struct{
bool reg=false; bool reg=false;
int threads=-1; int threads=-1;
@ -194,6 +195,7 @@ Orignal is sensei of crypto ;)
found=true; found=true;
FoundNonce=*nonce; FoundNonce=*nonce;
// From there place we get a nonce, for some one a byte. // From there place we get a nonce, for some one a byte.
fKeyId = id_thread;
return true; return true;
} }
@ -320,7 +322,6 @@ int main (int argc, char * argv[])
static std::string outPutFileName = options.outputpath; static std::string outPutFileName = options.outputpath;
auto doSearch = [argc,argv] () { auto doSearch = [argc,argv] () {
found = false; found = false;
auto keys = i2p::data::PrivateKeys::CreateRandomKeys (options.signature);
// TODO: create libi2pd_tools // TODO: create libi2pd_tools
// If file not exists we create a dump file. (a bug was found in issues) // If file not exists we create a dump file. (a bug was found in issues)
switch(options.signature) switch(options.signature)
@ -358,8 +359,14 @@ int main (int argc, char * argv[])
break; break;
} }
// there we gen key to buffer. That we mem allocate... // there we gen key to buffer. That we mem allocate...
KeyBuf = new uint8_t[keys.GetFullLen()]; const auto keys_len = i2p::data::PrivateKeys::CreateRandomKeys (options.signature).GetFullLen(); // is will be constant. so calculate every time is a bad way
keys.ToBuffer (KeyBuf, keys.GetFullLen ()); auto KeyBufs = new uint8_t*[options.threads];//[keys_len];
for(auto i = options.threads-1; i--;) {
KeyBufs[i] = new uint8_t[keys_len];
auto keys = i2p::data::PrivateKeys::CreateRandomKeys (options.signature);
keys.ToBuffer (KeyBufs[i], keys_len);
}
/// there was some things for cpu 665% usage, but is not helpful even /// there was some things for cpu 665% usage, but is not helpful even
std::cout << "Start vanity generator in " << options.threads << " threads" << std::endl; std::cout << "Start vanity generator in " << options.threads << " threads" << std::endl;
// there we start to change byte in our private key. we can change another bytes too // there we start to change byte in our private key. we can change another bytes too
@ -380,7 +387,10 @@ int main (int argc, char * argv[])
// thoughtput is our magic number that we increment on 1000 everytime // thoughtput is our magic number that we increment on 1000 everytime
// so we just change a one a byte in key and convert private key to address // so we just change a one a byte in key and convert private key to address
// after we check it. // after we check it.
threads[j] = std::thread(thread_find,KeyBuf,argv[1],j,thoughtput); auto n = j != 0 ? j-1 : 0 ;
std::cout << "Use " << n << " key" << std::endl;
threads[j] = std::thread(thread_find,KeyBufs[ n ],argv[1],j,thoughtput);
thoughtput+=1000; thoughtput+=1000;
}//for }//for
@ -403,6 +413,8 @@ int main (int argc, char * argv[])
}//while }//while
// before we write result we would to create private.dat a file. dump file. we can use for it keygen // before we write result we would to create private.dat a file. dump file. we can use for it keygen
// so. // so.
// std::cout << fKeyId << std::endl;
auto KeyBuf = KeyBufs[fKeyId - 1 < 0 ? 0 : fKeyId - 1];
memcpy (KeyBuf + MutateByte, &FoundNonce, 4); memcpy (KeyBuf + MutateByte, &FoundNonce, 4);
std::cout << "Hashes: " << hashescounter << std::endl; std::cout << "Hashes: " << hashescounter << std::endl;
@ -429,8 +441,10 @@ int main (int argc, char * argv[])
std::ofstream f (options.outputpath, std::ofstream::binary | std::ofstream::out); std::ofstream f (options.outputpath, std::ofstream::binary | std::ofstream::out);
if (f) if (f)
{ {
f.write ((char *)KeyBuf, keys.GetFullLen ()); f.write ((char *)KeyBuf, keys_len);
delete [] KeyBuf; for (unsigned i = options.threads-1;i--;)
delete [] KeyBufs[i];
delete [] KeyBufs;
} }
else else
std::cout << "Can't create file " << options.outputpath << std::endl; std::cout << "Can't create file " << options.outputpath << std::endl;

2
vanity.hpp

@ -67,7 +67,7 @@ static size_t MutateByte;
static uint32_t FoundNonce=0; static uint32_t FoundNonce=0;
static uint8_t * KeyBuf; //static uint8_t ** KeyBufs;
//static uint8_t * PaddingBuf; //static uint8_t * PaddingBuf;
static unsigned long long hashescounter; static unsigned long long hashescounter;

Loading…
Cancel
Save