Browse Source

clean code

Signed-off-by: R4SAS <r4sas@i2pmail.org>
pull/65/head
R4SAS 4 years ago
parent
commit
5f45990dff
Signed by: r4sas
GPG Key ID: 66F6C87B98EBCFE2
  1. 2
      b33address.cpp
  2. 6
      famtool.cpp
  3. 3
      i2pbase64.cpp
  4. 18
      keyinfo.cpp
  5. 4
      regaddralias.cpp
  6. 4
      vanity.hpp
  7. 66
      vanitygen.cpp

2
b33address.cpp

@ -8,6 +8,7 @@
int main(int argc, char * argv[]) int main(int argc, char * argv[])
{ {
// base64 input, b33 and store key output, 11->11 only // base64 input, b33 and store key output, 11->11 only
std::cout << "Waiting for base64 from stdin..." << std::endl;
std::string base64; std::string base64;
std::getline (std::cin, base64); std::getline (std::cin, base64);
auto ident = std::make_shared<i2p::data::IdentityEx>(); auto ident = std::make_shared<i2p::data::IdentityEx>();
@ -27,4 +28,3 @@ int main(int argc, char * argv[])
return 0; return 0;
} }

6
famtool.cpp

@ -277,13 +277,13 @@ int main(int argc, char * argv[])
if (sign) { if (sign) {
// sign // sign
if (!infile.size()) { if (!infile.size()) {
// no router info specififed // no router info specified
std::cerr << "no router keys file specified" << std::endl; std::cerr << "no router keys file specified" << std::endl;
return 1; return 1;
} }
if (!privkey.size()) { if (!privkey.size()) {
// no private key specified // no private key specified
std::cerr << "no private key specififed" << std::endl; std::cerr << "no private key specified" << std::endl;
return 1; return 1;
} }
@ -345,7 +345,7 @@ int main(int argc, char * argv[])
return 1; return 1;
} }
if(!certfile.size()) { if(!certfile.size()) {
std::cout << "no family cerifiticate specified" << std::endl; std::cout << "no family certificate specified" << std::endl;
return 1; return 1;
} }
auto v = LoadCertificate(certfile); auto v = LoadCertificate(certfile);

3
i2pbase64.cpp

@ -36,9 +36,6 @@ static int operate(std::function<std::size_t(const InCh *, size_t, OutCh *, size
return errno; return errno;
} }
int main(int argc, char * argv[]) int main(int argc, char * argv[])
{ {
int opt; int opt;

18
keyinfo.cpp

@ -9,6 +9,11 @@
#include <time.h> #include <time.h>
#include "common/key.hpp" #include "common/key.hpp"
static int printHelp(const char * exe, int exitcode)
{
std::cout << "usage: " << exe << " [-v] [-d] privatekey.dat" << std::endl;
return exitcode;
}
std::string ConvertTime (time_t t) std::string ConvertTime (time_t t)
{ {
@ -21,14 +26,16 @@ std::string ConvertTime (time_t t)
int main(int argc, char * argv[]) int main(int argc, char * argv[])
{ {
if(argc == 1) { if(argc == 1) {
std::cout << "usage: " << argv[0] << " [-v] [-d] privatekey.dat" << std::endl; return printHelp(argv[0], -1);
return -1;
} }
int opt; int opt;
bool print_full = false; bool print_full = false;
bool verbose = false; bool verbose = false;
while((opt = getopt(argc, argv, "vd"))!=-1) { while((opt = getopt(argc, argv, "hvd")) != -1) {
switch(opt){ switch(opt){
case 'h':
return printHelp(argv[0], 0);
case 'v': case 'v':
verbose = true; verbose = true;
break; break;
@ -36,10 +43,10 @@ int main(int argc, char * argv[])
print_full = true; print_full = true;
break; break;
default: default:
std::cout << "usage: " << argv[0] << " [-v] [-d] privatekey.dat" << std::endl; return printHelp(argv[0], -1);
return -1;
} }
} }
std::string fname(argv[optind]); std::string fname(argv[optind]);
i2p::data::PrivateKeys keys; i2p::data::PrivateKeys keys;
{ {
@ -60,6 +67,7 @@ int main(int argc, char * argv[])
return 3; return 3;
} }
} }
auto dest = keys.GetPublic(); auto dest = keys.GetPublic();
if(!dest) { if(!dest) {
std::cout << "failed to extract public key" << std::endl; std::cout << "failed to extract public key" << std::endl;

4
regaddralias.cpp

@ -33,7 +33,7 @@ int main (int argc, char * argv[])
} }
else else
{ {
std::cout << "Cab't open keyfile " << argv[1] << std::endl; std::cout << "Can't open keyfile " << argv[1] << std::endl;
return -1; return -1;
} }
} }
@ -56,7 +56,7 @@ int main (int argc, char * argv[])
} }
else else
{ {
std::cout << "Cab't open keyfile " << argv[2] << std::endl; std::cout << "Can't open keyfile " << argv[2] << std::endl;
return -1; return -1;
} }
} }

4
vanity.hpp

@ -54,7 +54,7 @@ static unsigned long long hashescounter;
unsigned int count_cpu; unsigned int count_cpu;
const uint8_t lastBlock[64] = const uint8_t lastBlock[64] =
{ {
0x05, 0x00, 0x04, 0x00, 0x07, 0x00, 0x00, 0x80, // 7 bytes EdDSA certificate 0x05, 0x00, 0x04, 0x00, 0x07, 0x00, 0x00, 0x80, // 7 bytes EdDSA certificate
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@ -63,5 +63,5 @@ const uint8_t lastBlock[64] =
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x38 // 3128 bits (391 bytes) 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x38 // 3128 bits (391 bytes)
}; };

66
vanitygen.cpp

@ -3,21 +3,21 @@
#include<getopt.h> #include<getopt.h>
static struct{ static struct
{
bool reg=false; bool reg=false;
int threads=-1; int threads=-1;
i2p::data::SigningKeyType signature; i2p::data::SigningKeyType signature;
std::string outputpath=""; std::string outputpath="";
std::regex regex; std::regex regex;
} options;
}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])
{ {
/* /**
implementation of orignal * 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]);
@ -31,9 +31,9 @@ implementation of orignal
static void inline TransformBlock (uint32_t state[8], const uint32_t W[64]) static void inline TransformBlock (uint32_t state[8], const uint32_t W[64])
{ {
/* /**
implementation of orignal * implementation of orignal
*/ */
uint32_t S[8]; uint32_t S[8];
memcpy(S, state, 32); memcpy(S, state, 32);
@ -60,9 +60,9 @@ implementation of orignal
void inline HashNextBlock (uint32_t state[8], const uint8_t * block) void inline HashNextBlock (uint32_t state[8], const uint8_t * block)
{ {
/* /**
implementation of orignal * implementation of orignal
*/ */
uint32_t W[64]; uint32_t W[64];
CalculateW (block, W); CalculateW (block, W);
TransformBlock (state, W); TransformBlock (state, W);
@ -126,11 +126,11 @@ static inline bool NotThat(const char * a, const char *b)
static inline bool thread_find(uint8_t * buf, const char * prefix, int id_thread, unsigned long long throughput) static inline bool thread_find(uint8_t * buf, const char * prefix, int id_thread, unsigned long long throughput)
{ {
/* /**
Thanks to orignal ^-^ * Thanks to orignal ^-^
For idea and example ^-^ * For idea and example ^-^
Orignal is sensei of crypto ;) * Orignal is sensei of crypto ;)
*/ */
std::cout << "Thread " << id_thread << " binded" << std::endl; std::cout << "Thread " << id_thread << " binded" << std::endl;
/* /*
union union
@ -181,10 +181,10 @@ Orignal is sensei of crypto ;)
ByteStreamToBase32 ((uint8_t*)hash, 32, addr, len); ByteStreamToBase32 ((uint8_t*)hash, 32, addr, len);
// std::cout << addr << std::endl; // std::cout << addr << std::endl;
//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) // 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;
@ -204,14 +204,10 @@ Orignal is sensei of crypto ;)
// free(b); // free(b);
break; break;
} }
}//while } // while
return true; return true;
} }
void usage(void){ void usage(void){
const constexpr char * help="vain [text-pattern|regex-pattern] [options]\n" const constexpr char * help="vain [text-pattern|regex-pattern] [options]\n"
"-h --help, help menu\n" "-h --help, help menu\n"
@ -220,12 +216,11 @@ void usage(void){
"--signature -s, (signature type)\n" "--signature -s, (signature type)\n"
"-o --output output file (default private.dat)\n" "-o --output output file (default private.dat)\n"
"--usage usage\n" "--usage usage\n"
//"--prefix -p\n" // "--prefix -p\n"
""; "";
puts(help); puts(help);
} }
void parsing(int argc, char ** args){ void parsing(int argc, char ** args){
int option_index; int option_index;
static struct option long_options[]={ static struct option long_options[]={
@ -274,10 +269,6 @@ void parsing(int argc, char ** args){
int main (int argc, char * argv[]) int main (int argc, char * argv[])
{ {
if ( argc < 2 ) if ( argc < 2 )
{ {
usage(); usage();
@ -320,7 +311,7 @@ int main (int argc, char * argv[])
case i2p::data::SIGNING_KEY_TYPE_RSA_SHA384_3072: case i2p::data::SIGNING_KEY_TYPE_RSA_SHA384_3072:
case i2p::data::SIGNING_KEY_TYPE_RSA_SHA512_4096: case i2p::data::SIGNING_KEY_TYPE_RSA_SHA512_4096:
case i2p::data::SIGNING_KEY_TYPE_GOSTR3410_TC26_A_512_GOSTR3411_512: case i2p::data::SIGNING_KEY_TYPE_GOSTR3410_TC26_A_512_GOSTR3411_512:
std::cout << "Sorry, i don't can generate adress for this signature type" << std::endl; std::cout << "Sorry, i don't can generate address for this signature type" << std::endl;
return 0; return 0;
break; break;
} }
@ -371,8 +362,8 @@ int main (int argc, char * argv[])
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(options.threads); std::vector<std::thread> threads(options.threads);
unsigned long long thoughtput = 0x4F4B5A37; unsigned long long thoughtput = 0x4F4B5A37;
@ -381,7 +372,7 @@ int main (int argc, char * argv[])
{ {
threads[j] = std::thread(thread_find,KeyBuf,argv[1],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 < (unsigned int)options.threads;j++) for(unsigned int j = 0; j < (unsigned int)options.threads;j++)
threads[j].join(); threads[j].join();
@ -392,8 +383,8 @@ int main (int argc, char * argv[])
std::cout << "Attempts #" << ++attempts << std::endl; std::cout << "Attempts #" << ++attempts << std::endl;
} }
}//stack } // stack
}//while } // while
memcpy (KeyBuf + MutateByte, &FoundNonce, 4); memcpy (KeyBuf + MutateByte, &FoundNonce, 4);
std::cout << "Hashes: " << hashescounter << std::endl; std::cout << "Hashes: " << hashescounter << std::endl;
@ -413,6 +404,3 @@ int main (int argc, char * argv[])
return 0; return 0;
} }
//

Loading…
Cancel
Save