From 2d06872f528ce26f758223c3b871a2a464e222d8 Mon Sep 17 00:00:00 2001 From: startyourday60 Date: Sun, 27 Aug 2023 13:27:30 +0300 Subject: [PATCH 1/3] (vain) calculate a key for a thread instead one a key for all threads https://github.com/PurpleI2P/i2pd-tools/issues/92 --- vain.cpp | 26 ++++++++++++++++++++------ vanity.hpp | 2 +- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/vain.cpp b/vain.cpp index 104a36d..ed4779e 100755 --- a/vain.cpp +++ b/vain.cpp @@ -7,6 +7,7 @@ //#include // is not supports for me // some global vars in vanitygen.hpp +static unsigned short fKeyId = 0; static struct{ bool reg=false; int threads=-1; @@ -194,6 +195,7 @@ Orignal is sensei of crypto ;) found=true; FoundNonce=*nonce; // From there place we get a nonce, for some one a byte. + fKeyId = id_thread; return true; } @@ -320,7 +322,6 @@ int main (int argc, char * argv[]) static std::string outPutFileName = options.outputpath; auto doSearch = [argc,argv] () { found = false; - auto keys = i2p::data::PrivateKeys::CreateRandomKeys (options.signature); // TODO: create libi2pd_tools // If file not exists we create a dump file. (a bug was found in issues) switch(options.signature) @@ -358,8 +359,14 @@ int main (int argc, char * argv[]) break; } // there we gen key to buffer. That we mem allocate... - KeyBuf = new uint8_t[keys.GetFullLen()]; - keys.ToBuffer (KeyBuf, 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 + 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 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 @@ -380,7 +387,10 @@ int main (int argc, char * argv[]) // 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 // 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; }//for @@ -403,6 +413,8 @@ int main (int argc, char * argv[]) }//while // before we write result we would to create private.dat a file. dump file. we can use for it keygen // so. + // std::cout << fKeyId << std::endl; + auto KeyBuf = KeyBufs[fKeyId - 1 < 0 ? 0 : fKeyId - 1]; memcpy (KeyBuf + MutateByte, &FoundNonce, 4); 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); if (f) { - f.write ((char *)KeyBuf, keys.GetFullLen ()); - delete [] KeyBuf; + f.write ((char *)KeyBuf, keys_len); + for (unsigned i = options.threads-1;i--;) + delete [] KeyBufs[i]; + delete [] KeyBufs; } else std::cout << "Can't create file " << options.outputpath << std::endl; diff --git a/vanity.hpp b/vanity.hpp index e552f1c..bc9b8f9 100755 --- a/vanity.hpp +++ b/vanity.hpp @@ -67,7 +67,7 @@ static size_t MutateByte; static uint32_t FoundNonce=0; -static uint8_t * KeyBuf; +//static uint8_t ** KeyBufs; //static uint8_t * PaddingBuf; static unsigned long long hashescounter; From 57c0ca9d40f5cf5ec12c6f3176b97b9e25c867f0 Mon Sep 17 00:00:00 2001 From: startyourday60 Date: Sun, 27 Aug 2023 13:32:47 +0300 Subject: [PATCH 2/3] maybe a fix memory leak --- vain.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/vain.cpp b/vain.cpp index ed4779e..52c9e12 100755 --- a/vain.cpp +++ b/vain.cpp @@ -405,6 +405,10 @@ int main (int argc, char * argv[]) { //keys = i2p::data::PrivateKeys::CreateRandomKeys (options.signature); //RAND_bytes( KeyBuf+MutateByte , 90 ); // FoundNonce is + + for (unsigned i = options.threads-1;i--;) + delete [] KeyBufs[i]; + delete [] KeyBufs; std::cout << "(Generate a new keypair) Attempts #" << ++attempts << std::endl; return 1; } From 0f05ffd31fab8b64a91cbae2bc34923e84b438d4 Mon Sep 17 00:00:00 2001 From: startyourday60 Date: Sun, 27 Aug 2023 13:40:29 +0300 Subject: [PATCH 3/3] fix attemps variable --- vain.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/vain.cpp b/vain.cpp index 52c9e12..4d2993b 100755 --- a/vain.cpp +++ b/vain.cpp @@ -16,7 +16,7 @@ static struct{ std::regex regex; }options; - +static unsigned short attempts = 0;// it can be disabled, it's just for a statistic. For CPU this is a trash? static void inline CalculateW (const uint8_t block[64], uint32_t W[64]) { @@ -371,7 +371,6 @@ int main (int argc, char * argv[]) 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 // but we just change 1 byte in all key. So. TODO: change all bytes not one? - unsigned short attempts = 0;// it can be disabled, it's just for a statistic. For CPU this is a trash? while(!found) {//while {//stack(for destructors(vector/thread))