Browse Source

Merge pull request #55 from wipedlife/master

regex getopt
darwin_fixes
orignal 7 years ago committed by GitHub
parent
commit
96ac5d0d60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      vanity.hpp
  2. 172
      vanitygen.cpp

2
vanity.hpp

@ -39,7 +39,7 @@
W[i] + k) W[i] + k)
static i2p::data::SigningKeyType type; //static i2p::data::SigningKeyType type;
//static i2p::data::PrivateKeys keys; //static i2p::data::PrivateKeys keys;
static bool found=false; static bool found=false;

172
vanitygen.cpp

@ -1,4 +1,17 @@
#include "vanity.hpp" #include "vanity.hpp"
#include<regex.h>
#include<getopt.h>
static struct{
bool reg=false;
int threads=-1;
i2p::data::SigningKeyType signature;
std::string outputpath="";
regex_t regex;
}options;
static void inline CalculateW (const uint8_t block[64], uint32_t W[64]) static void inline CalculateW (const uint8_t block[64], uint32_t W[64])
{ {
@ -8,7 +21,7 @@ implementation of orignal
for (int i = 0; i < 16; i++) for (int i = 0; i < 16; i++)
#ifdef _WIN32 #ifdef _WIN32
W[i] = htobe32(((uint32_t *)(block))[i]); W[i] = htobe32(((uint32_t *)(block))[i]);
#else #else // from big endian to little endian ( swap )
W[i] = be32toh(((uint32_t *)(block))[i]); W[i] = be32toh(((uint32_t *)(block))[i]);
#endif #endif
@ -99,8 +112,17 @@ static inline size_t ByteStreamToBase32 (const uint8_t * inBuf, size_t len, char
return ret; return ret;
} }
static inline bool NotThat(const char * what, const regex_t * reg){
int ret = regexec(reg, what, 0, 0, 0);
if( ret == REG_NOMATCH ) return true;
else if(ret == 0) return false;
std::cerr << "Some error in regexping" << std::endl;
exit(2);
}
static inline bool NotThat(const char * a, const char *b) static inline bool NotThat(const char * a, const char *b)
{ {
while(*b) while(*b)
if(*a++!=*b++) if(*a++!=*b++)
return true; return true;
@ -163,7 +185,11 @@ Orignal is sensei of crypto ;)
hash[j] = htobe32(state1[j]); hash[j] = htobe32(state1[j]);
ByteStreamToBase32 ((uint8_t*)hash, 32, addr, len); ByteStreamToBase32 ((uint8_t*)hash, 32, addr, len);
// std::cout << addr << std::endl; // std::cout << addr << std::endl;
if(!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(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;
@ -174,6 +200,7 @@ Orignal is sensei of crypto ;)
return true; return true;
} }
(*nonce)++; (*nonce)++;
hashescounter++; hashescounter++;
if (found) if (found)
@ -186,38 +213,100 @@ Orignal is sensei of crypto ;)
return true; return true;
} }
int main (int argc, char * argv[])
{
if ( argc < 3 )
{
std::cout << "Usage: " << argv[0] << " filename generatestring <threads(default of system)> <signature type>" << std::endl; void usaging(void){
return 0; const constexpr char * help="vain pattern [options]\n"
"-h --help help menu\n"
"-r --reg regexp instead just text pattern\n"
"--threads -t (default count of system)\n"
"--signature -s (signature type)\n"
"-o --output output file(default private.dat)\n"
"--usage usaging\n"
"--prefix -p\n"
"";
puts(help);
} }
if(!check_prefix(argv[2]))
{
std::cout << "Not correct prefix" << std::endl; void parsing(int argc, char ** args){
return 0; int option_index;
static struct option long_options[]={
{"help",no_argument,0,'h'},
{"reg", no_argument,0,'r'},
{"threads", required_argument, 0, 't'},
{"signature", required_argument,0,'s'},
{"output", required_argument,0,'o'},
{"usage", no_argument,0,0},
{0,0,0,0}
};
int c;
while( (c=getopt_long(argc,args, "hrt:s:o:", long_options, &option_index))!=-1){
switch(c){
case 0:
if ( std::string(long_options[option_index].name) == std::string("usage") ){
usaging();
exit(1);
} }
i2p::crypto::InitCrypto (false); case 'h':
type = i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519; usaging();
if ( argc > 3 ) exit(0);
break;
case 'r':
options.reg=true;
break;
case 't':
options.threads=atoi(optarg);
break;
case 's':
options.signature = NameToSigType(std::string(optarg));
break;
case 'o':
options.outputpath=optarg;
break;
case '?':
std::cerr << "Undefined argument" << std::endl;
default:
std::cerr << args[0] << " --usage / --help" << std::endl;
exit(1);
break;
}
}
}
int main (int argc, char * argv[])
{ {
unsigned int tmp = atoi(argv[3]);
if(tmp > 255)
if ( argc < 2 )
{ {
std::cout << "Really more than 255 threads?:D Nope, sorry" << std::endl; usaging();
return 0; return 0;
} }
count_cpu=atoi(argv[3]); parsing( argc > 2 ? argc-1 : argc, argc > 2 ? argv+1 : argv);
} //
if ( argc > 4 ) if(!options.reg && !check_prefix( argv[1] ))
{ {
type = NameToSigType(std::string(argv[4])); std::cout << "Not correct prefix(just string)" << std::endl;
return 1;
}else{
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;
}
} }
i2p::crypto::InitCrypto (false);
options.signature = i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519;
/////////////// ///////////////
//For while //For while
if(type != i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519) if(options.signature != i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519)
{ {
std::cout << "For a while only ED25519-SHA512" << std::endl; std::cout << "For a while only ED25519-SHA512" << std::endl;
return 0; return 0;
@ -225,8 +314,8 @@ int main (int argc, char * argv[])
/////////////// ///////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
auto keys = i2p::data::PrivateKeys::CreateRandomKeys (type); auto keys = i2p::data::PrivateKeys::CreateRandomKeys (options.signature);
switch(type) switch(options.signature)
{ {
case i2p::data::SIGNING_KEY_TYPE_DSA_SHA1: case i2p::data::SIGNING_KEY_TYPE_DSA_SHA1:
case i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA512_P521: case i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA512_P521:
@ -240,7 +329,7 @@ int main (int argc, char * argv[])
} }
//TODO: for other types. //TODO: for other types.
switch(type) switch(options.signature)
{ {
case i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA256_P256: case i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA256_P256:
break; break;
@ -264,40 +353,40 @@ int main (int argc, char * argv[])
KeyBuf = new uint8_t[keys.GetFullLen()]; KeyBuf = new uint8_t[keys.GetFullLen()];
keys.ToBuffer (KeyBuf, keys.GetFullLen ()); keys.ToBuffer (KeyBuf, keys.GetFullLen ());
if(!count_cpu) if(options.threads <= 0)
{ {
#if defined(WIN32) #if defined(WIN32)
SYSTEM_INFO siSysInfo; SYSTEM_INFO siSysInfo;
GetSystemInfo(&siSysInfo); GetSystemInfo(&siSysInfo);
count_cpu = siSysInfo.dwNumberOfProcessors; options.threads = siSysInfo.dwNumberOfProcessors;
#elif defined(_SC_NPROCESSORS_CONF) #elif defined(_SC_NPROCESSORS_CONF)
count_cpu = sysconf(_SC_NPROCESSORS_CONF); options.threads = sysconf(_SC_NPROCESSORS_CONF);
#elif defined(HW_NCPU) #elif defined(HW_NCPU)
int req[] = { CTL_HW, HW_NCPU }; int req[] = { CTL_HW, HW_NCPU };
size_t len = sizeof(count_cpu); size_t len = sizeof(options.threads);
v = sysctl(req, 2, &count_cpu, &len, NULL, 0); v = sysctl(req, 2, &options.threads, &len, NULL, 0);
#else #else
count_cpu = 4; options.threads = 1;
#endif #endif
} }
std::cout << "Start vanity generator in " << count_cpu << " threads" << std::endl; std::cout << "Start vanity generator in " << options.threads << " threads" << std::endl;
unsigned short attempts = 0; unsigned short attempts = 0;
while(!found) while(!found)
{//while {//while
{//stack(for destructors(vector/thread)) {//stack(for destructors(vector/thread))
std::vector<std::thread> threads(count_cpu); std::vector<std::thread> threads(options.threads);
unsigned long long thoughtput = 0x4F4B5A37; unsigned long long thoughtput = 0x4F4B5A37;
for ( unsigned int j = count_cpu;j--;) for ( unsigned int j = options.threads;j--;)
{ {
threads[j] = std::thread(thread_find,KeyBuf,argv[2],j,thoughtput); threads[j] = std::thread(thread_find,KeyBuf,argv[1],j,thoughtput);
thoughtput+=1000; thoughtput+=1000;
}//for }//for
for(unsigned int j = 0; j < count_cpu;j++) for(unsigned int j = 0; j < (unsigned int)options.threads;j++)
threads[j].join(); threads[j].join();
if(FoundNonce == 0) if(FoundNonce == 0)
@ -312,16 +401,21 @@ int main (int argc, char * argv[])
memcpy (KeyBuf + MutateByte, &FoundNonce, 4); memcpy (KeyBuf + MutateByte, &FoundNonce, 4);
std::cout << "Hashes: " << hashescounter << std::endl; std::cout << "Hashes: " << hashescounter << std::endl;
std::ofstream f (argv[1], std::ofstream::binary | std::ofstream::out); if(options.outputpath.size() == 0) options.outputpath="private.dat";
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.GetFullLen ());
delete [] KeyBuf; delete [] KeyBuf;
} }
else else
std::cout << "Can't create file " << argv[1] << std::endl; std::cout << "Can't create file " << options.outputpath << std::endl;
i2p::crypto::TerminateCrypto (); i2p::crypto::TerminateCrypto ();
return 0; return 0;
} }
//

Loading…
Cancel
Save