mirror of
https://github.com/PurpleI2P/i2pd-tools
synced 2025-01-15 17:20:08 +00:00
Merge pull request #91 from wipedlifepotato/master
Fix a bug with 'bad key format', also not rewrite exists .dat file
This commit is contained in:
commit
e60c0cd271
81
vain.cpp
81
vain.cpp
@ -188,14 +188,11 @@ Orignal is sensei of crypto ;)
|
|||||||
//bool result = options.reg ? !NotThat(addr, &options.regex) : !NotThat(addr,prefix);
|
//bool result = options.reg ? !NotThat(addr, &options.regex) : !NotThat(addr,prefix);
|
||||||
|
|
||||||
if( ( options.reg ? !NotThat(addr, options.regex) : !NotThat(addr,prefix) ) )
|
if( ( options.reg ? !NotThat(addr, options.regex) : !NotThat(addr,prefix) ) )
|
||||||
// if(result)
|
|
||||||
{
|
{
|
||||||
ByteStreamToBase32 ((uint8_t*)hash, 32, addr, 52);
|
ByteStreamToBase32 ((uint8_t*)hash, 32, addr, 52);
|
||||||
std::cout << "Address found " << addr << " in " << id_thread << std::endl;
|
std::cout << "Address found " << addr << " in " << id_thread << std::endl;
|
||||||
found=true;
|
found=true;
|
||||||
FoundNonce=*nonce;
|
FoundNonce=*nonce;
|
||||||
// free(hash);
|
|
||||||
// free(b);
|
|
||||||
// From there place we get a nonce, for some one a byte.
|
// From there place we get a nonce, for some one a byte.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -203,10 +200,8 @@ Orignal is sensei of crypto ;)
|
|||||||
|
|
||||||
(*nonce)++;
|
(*nonce)++;
|
||||||
hashescounter++;
|
hashescounter++;
|
||||||
if (found) // for another threads
|
if (found) // for another threads (?)
|
||||||
{
|
{
|
||||||
// free(hash);
|
|
||||||
// free(b);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}//while
|
}//while
|
||||||
@ -224,8 +219,6 @@ void usage(void){
|
|||||||
"--threads -t (default count of system)\n"
|
"--threads -t (default count of system)\n"
|
||||||
//"--signature -s (signature type)\n"
|
//"--signature -s (signature type)\n"
|
||||||
"-o --output output file(default " DEF_OUT_FILE ")\n"
|
"-o --output output file(default " DEF_OUT_FILE ")\n"
|
||||||
//"--usage usage\n"
|
|
||||||
//"--prefix -p\n"
|
|
||||||
"--multiplymode -m - multiple addresses search"
|
"--multiplymode -m - multiple addresses search"
|
||||||
"";
|
"";
|
||||||
puts(help);
|
puts(help);
|
||||||
@ -241,18 +234,12 @@ void parsing(int argc, char ** args){
|
|||||||
{"signature", required_argument,0,'s'},
|
{"signature", required_argument,0,'s'},
|
||||||
{"output", required_argument,0,'o'},
|
{"output", required_argument,0,'o'},
|
||||||
{"multiplymode", no_argument, 0, 'm'},
|
{"multiplymode", no_argument, 0, 'm'},
|
||||||
//{"usage", no_argument,0,0},
|
|
||||||
{0,0,0,0}
|
{0,0,0,0}
|
||||||
};
|
};
|
||||||
|
|
||||||
int c;
|
int c;
|
||||||
while( (c=getopt_long(argc,args, "hrt:s:o:m", long_options, &option_index))!=-1){
|
while( (c=getopt_long(argc,args, "hrt:s:o:m", long_options, &option_index))!=-1){
|
||||||
switch(c){
|
switch(c){
|
||||||
//case 0:
|
|
||||||
// if ( std::string(long_options[option_index].name) == std::string("usage") ){
|
|
||||||
// usage();
|
|
||||||
// exit(1);
|
|
||||||
// }
|
|
||||||
case 'm':
|
case 'm':
|
||||||
multipleSearchMode=true;
|
multipleSearchMode=true;
|
||||||
break;
|
break;
|
||||||
@ -296,23 +283,17 @@ int main (int argc, char * argv[])
|
|||||||
parsing( argc > 2 ? argc-1 : argc, argc > 2 ? argv+1 : argv); // parsing is was there.
|
parsing( argc > 2 ? argc-1 : argc, argc > 2 ? argv+1 : argv); // parsing is was there.
|
||||||
// if argc size more than 2. nameprogram is 1. and 2 is prefix. if not there is will be flags like regex
|
// if argc size more than 2. nameprogram is 1. and 2 is prefix. if not there is will be flags like regex
|
||||||
// TODO: ?
|
// TODO: ?
|
||||||
//
|
|
||||||
if(!options.reg && !check_prefix( argv[1] ))
|
if(!options.reg && !check_prefix( argv[1] ))
|
||||||
{
|
{
|
||||||
std::cout << "Not correct prefix(just string)" << std::endl;
|
std::cout << "Not correct prefix(just string)" << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}else{
|
}else{
|
||||||
options.regex=std::regex(argv[1]);
|
options.regex=std::regex(argv[1]);
|
||||||
// int ret = regcomp( &options.regex, argv[1], REG_EXTENDED );
|
|
||||||
// if( ret != 0 ){
|
|
||||||
// std::cerr << "Can't create regexp pattern from " << argv[1] << std::endl;
|
|
||||||
// return 1;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
// https://github.com/PurpleI2P/i2pd/blob/ae5239de435e1dcdff342961af9b506f60a494d4/libi2pd/Crypto.h#L310
|
// https://github.com/PurpleI2P/i2pd/blob/ae5239de435e1dcdff342961af9b506f60a494d4/libi2pd/Crypto.h#L310
|
||||||
//// init and terminate
|
//// init and terminate
|
||||||
// void InitCrypto (bool precomputation, bool aesni, bool avx, bool force);
|
// void InitCrypto (bool precomputation, bool aesni, bool avx, bool force);
|
||||||
// By default false to all.
|
// By default false to all. But on much proccessors some things will be enabled. SO, TODO
|
||||||
i2p::crypto::InitCrypto (PRECOMPUTATION_CRYPTO, AESNI_CRYPTO, AVX_CRYPTO, FORCE_CRYPTO);
|
i2p::crypto::InitCrypto (PRECOMPUTATION_CRYPTO, AESNI_CRYPTO, AVX_CRYPTO, FORCE_CRYPTO);
|
||||||
options.signature = i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519;
|
options.signature = i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519;
|
||||||
///////////////
|
///////////////
|
||||||
@ -327,20 +308,6 @@ int main (int argc, char * argv[])
|
|||||||
if(options.threads <= 0)
|
if(options.threads <= 0)
|
||||||
{
|
{
|
||||||
options.threads = std::thread::hardware_concurrency(); // thx for acetone. lol
|
options.threads = std::thread::hardware_concurrency(); // thx for acetone. lol
|
||||||
//
|
|
||||||
//#if defined(WIN32)
|
|
||||||
// SYSTEM_INFO siSysInfo;
|
|
||||||
// GetSystemInfo(&siSysInfo);
|
|
||||||
// options.threads = siSysInfo.dwNumberOfProcessors;
|
|
||||||
//#elif defined(_SC_NPROCESSORS_CONF)
|
|
||||||
// options.threads = sysconf(_SC_NPROCESSORS_CONF);
|
|
||||||
//#elif defined(HW_NCPU)
|
|
||||||
// int req[] = { CTL_HW, HW_NCPU };
|
|
||||||
// size_t len = sizeof(options.threads);
|
|
||||||
// v = sysctl(req, 2, &options.threads, &len, NULL, 0);
|
|
||||||
//#else
|
|
||||||
// options.threads = 1;
|
|
||||||
//#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -352,22 +319,8 @@ int main (int argc, char * argv[])
|
|||||||
if ( options . outputpath . empty () ) options . outputpath . assign ( DEF_OUT_FILE ) ;
|
if ( options . outputpath . empty () ) options . outputpath . assign ( DEF_OUT_FILE ) ;
|
||||||
static std::string outPutFileName = options.outputpath;
|
static std::string outPutFileName = options.outputpath;
|
||||||
auto doSearch = [argc,argv] () {
|
auto doSearch = [argc,argv] () {
|
||||||
|
found = false;
|
||||||
auto keys = i2p::data::PrivateKeys::CreateRandomKeys (options.signature);
|
auto keys = i2p::data::PrivateKeys::CreateRandomKeys (options.signature);
|
||||||
// IDK type, and don't want to check. so...
|
|
||||||
auto createDumpFile = [/*keys*/](std::string outFile, i2p::data::PrivateKeys keys){
|
|
||||||
std::cout <<" Create a outFile " << outFile << std::endl;
|
|
||||||
std::ofstream f(outFile, std::ofstream::binary | std::ofstream:: out);
|
|
||||||
if (!f) {
|
|
||||||
std::cerr << "Can't to create a dump file before search address" << std::endl;
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
size_t len = keys.GetFullLen ();
|
|
||||||
uint8_t * buf = new uint8_t[len];
|
|
||||||
len = keys.ToBuffer (buf, len);
|
|
||||||
f.write ((char *)buf, len);
|
|
||||||
delete[] buf;
|
|
||||||
}; // is double of code. we can found simillar in keygen.cpp. WE would to create a library like
|
|
||||||
// libi2pdtools
|
|
||||||
// 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)
|
||||||
@ -438,11 +391,12 @@ int main (int argc, char * argv[])
|
|||||||
// So I put it ^^^
|
// So I put it ^^^
|
||||||
for(unsigned int j = 0; j < (unsigned int)options.threads;j++)
|
for(unsigned int j = 0; j < (unsigned int)options.threads;j++)
|
||||||
threads[j].join();
|
threads[j].join();
|
||||||
|
|
||||||
if(FoundNonce == 0)
|
if(FoundNonce == 0)
|
||||||
{
|
{
|
||||||
RAND_bytes( KeyBuf+MutateByte , 90 ); // FoundNonce is
|
//keys = i2p::data::PrivateKeys::CreateRandomKeys (options.signature);
|
||||||
std::cout << "Attempts #" << ++attempts << std::endl;
|
//RAND_bytes( KeyBuf+MutateByte , 90 ); // FoundNonce is
|
||||||
|
std::cout << "(Generate a new keypair) Attempts #" << ++attempts << std::endl;
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}//stack
|
}//stack
|
||||||
@ -456,7 +410,14 @@ int main (int argc, char * argv[])
|
|||||||
// cplusplus.com/reference/string/string/assign yes we can. but I would don't change this
|
// cplusplus.com/reference/string/string/assign yes we can. but I would don't change this
|
||||||
//if(options.outputpath.size() == 0) options.outputpath = DEF_OUT_FILE;
|
//if(options.outputpath.size() == 0) options.outputpath = DEF_OUT_FILE;
|
||||||
options.outputpath = options.outputpath + std::to_string(foundKeys) + std::string(".dat");
|
options.outputpath = options.outputpath + std::to_string(foundKeys) + std::string(".dat");
|
||||||
|
do
|
||||||
|
{
|
||||||
|
options.outputpath.assign(outPutFileName);
|
||||||
|
options.outputpath = options.outputpath + std::to_string(foundKeys) + std::string(".dat");
|
||||||
|
foundKeys++;
|
||||||
|
//printf("foundKeys = %d\n", foundKeys);
|
||||||
|
}while( boost::filesystem::exists(options.outputpath) );
|
||||||
|
//puts("do while cycle break");
|
||||||
//if ( ! boost::algorithm::ends_with(options.outputpath, ".dat") )
|
//if ( ! boost::algorithm::ends_with(options.outputpath, ".dat") )
|
||||||
// options.outputpath = options.outputpath + ".dat";
|
// options.outputpath = options.outputpath + ".dat";
|
||||||
|
|
||||||
@ -464,7 +425,6 @@ int main (int argc, char * argv[])
|
|||||||
// before a mining we would to create a dump file
|
// before a mining we would to create a dump file
|
||||||
|
|
||||||
std::cout << "outpath for a now: " << options.outputpath << std::endl;
|
std::cout << "outpath for a now: " << options.outputpath << std::endl;
|
||||||
if( ! boost::filesystem::exists(options.outputpath) ) createDumpFile(options.outputpath, keys);
|
|
||||||
|
|
||||||
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)
|
||||||
@ -474,16 +434,19 @@ int main (int argc, char * argv[])
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
std::cout << "Can't create file " << options.outputpath << std::endl;
|
std::cout << "Can't create file " << options.outputpath << std::endl;
|
||||||
|
return 0;
|
||||||
}; // void doSearch lamda
|
}; // void doSearch lamda
|
||||||
|
|
||||||
do {
|
do {
|
||||||
doSearch();
|
doSearch();
|
||||||
foundKeys++;
|
if(found)
|
||||||
|
{
|
||||||
|
//TODO: an another variable for file count and found keys as found keys by one runs
|
||||||
|
//foundKeys++;
|
||||||
|
}
|
||||||
options.outputpath.assign(outPutFileName);
|
options.outputpath.assign(outPutFileName);
|
||||||
found = false;
|
|
||||||
FoundNonce = 0;
|
FoundNonce = 0;
|
||||||
} while(multipleSearchMode);
|
} while(multipleSearchMode || !found);
|
||||||
|
|
||||||
i2p::crypto::TerminateCrypto ();
|
i2p::crypto::TerminateCrypto ();
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -61,6 +61,7 @@
|
|||||||
// Global vars
|
// Global vars
|
||||||
static bool found=false;
|
static bool found=false;
|
||||||
static bool multipleSearchMode = false;
|
static bool multipleSearchMode = false;
|
||||||
|
//TODO: an another variable for file count and found keys as found keys by one runs
|
||||||
static unsigned int foundKeys = 0;
|
static unsigned int foundKeys = 0;
|
||||||
static size_t MutateByte;
|
static size_t MutateByte;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user