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. 12
      b33address.cpp
  2. 702
      famtool.cpp
  3. 119
      i2pbase64.cpp
  4. 4
      keygen.cpp
  5. 140
      keyinfo.cpp
  6. 20
      offlinekeys.cpp
  7. 16
      regaddr.cpp
  8. 30
      regaddralias.cpp
  9. 12
      routerinfo.cpp
  10. 20
      vanity.hpp
  11. 94
      vanitygen.cpp

12
b33address.cpp

@ -6,8 +6,9 @@
#include "common/key.hpp" #include "common/key.hpp"
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>();
@ -17,14 +18,13 @@ int main(int argc, char * argv[])
{ {
i2p::data::BlindedPublicKey blindedKey (ident); i2p::data::BlindedPublicKey blindedKey (ident);
std::cout << "b33 address: " << blindedKey.ToB33 () << ".b32.i2p" << std::endl; std::cout << "b33 address: " << blindedKey.ToB33 () << ".b32.i2p" << std::endl;
std::cout << "Today's store hash: " << blindedKey.GetStoreHash ().ToBase64 () << std::endl; std::cout << "Today's store hash: " << blindedKey.GetStoreHash ().ToBase64 () << std::endl;
} }
else else
std::cout << "Invalid signature type " << SigTypeToName (ident->GetSigningKeyType ()) << std::endl; std::cout << "Invalid signature type " << SigTypeToName (ident->GetSigningKeyType ()) << std::endl;
} }
else else
std::cout << "Invalid base64 address" << std::endl; std::cout << "Invalid base64 address" << std::endl;
return 0; return 0;
} }

702
famtool.cpp

@ -19,372 +19,372 @@ using namespace i2p::data;
static void usage(const std::string & name) static void usage(const std::string & name)
{ {
std::cout << "usage: " << name << " [-h] [-v] [-g -n family -c family.crt -k family.pem] [-s -n family -k family.pem -i router.keys -f router.info] [-V -c family.crt -f router.info]" << std::endl; std::cout << "usage: " << name << " [-h] [-v] [-g -n family -c family.crt -k family.pem] [-s -n family -k family.pem -i router.keys -f router.info] [-V -c family.crt -f router.info]" << std::endl;
} }
static void printhelp(const std::string & name) static void printhelp(const std::string & name)
{ {
usage(name); usage(name);
std::cout << std::endl; std::cout << std::endl;
std::cout << "generate a new family signing key for family called ``i2pfam''" << std::endl; std::cout << "generate a new family signing key for family called ``i2pfam''" << std::endl;
std::cout << name << " -g -n i2pfam -c myfam.crt -k myfam.pem" << std::endl << std::endl; std::cout << name << " -g -n i2pfam -c myfam.crt -k myfam.pem" << std::endl << std::endl;
std::cout << "sign a router info with family signing key" << std::endl; std::cout << "sign a router info with family signing key" << std::endl;
std::cout << name << " -s -n i2pfam -k myfam.pem -i router.keys -f router.info" << std::endl << std::endl; std::cout << name << " -s -n i2pfam -k myfam.pem -i router.keys -f router.info" << std::endl << std::endl;
std::cout << "verify signed router.info" << std::endl; std::cout << "verify signed router.info" << std::endl;
std::cout << name << " -V -n i2pfam -c myfam.pem -f router.info" << std::endl << std::endl; std::cout << name << " -V -n i2pfam -c myfam.pem -f router.info" << std::endl << std::endl;
} }
static std::shared_ptr<Verifier> LoadCertificate (const std::string& filename) static std::shared_ptr<Verifier> LoadCertificate (const std::string& filename)
{ {
std::shared_ptr<Verifier> verifier; std::shared_ptr<Verifier> verifier;
SSL_CTX * ctx = SSL_CTX_new (TLSv1_method ()); SSL_CTX * ctx = SSL_CTX_new (TLSv1_method ());
int ret = SSL_CTX_use_certificate_file (ctx, filename.c_str (), SSL_FILETYPE_PEM); int ret = SSL_CTX_use_certificate_file (ctx, filename.c_str (), SSL_FILETYPE_PEM);
if (ret) if (ret)
{ {
SSL * ssl = SSL_new (ctx); SSL * ssl = SSL_new (ctx);
X509 * cert = SSL_get_certificate (ssl); X509 * cert = SSL_get_certificate (ssl);
if (cert) if (cert)
{ {
// extract issuer name // extract issuer name
char name[100]; char name[100];
X509_NAME_oneline (X509_get_issuer_name(cert), name, 100); X509_NAME_oneline (X509_get_issuer_name(cert), name, 100);
char * cn = strstr (name, "CN="); char * cn = strstr (name, "CN=");
if (cn) if (cn)
{ {
cn += 3; cn += 3;
char * family = strstr (cn, ".family"); char * family = strstr (cn, ".family");
if (family) family[0] = 0; if (family) family[0] = 0;
} }
auto pkey = X509_get_pubkey (cert); auto pkey = X509_get_pubkey (cert);
EC_KEY * ecKey = EVP_PKEY_get1_EC_KEY (pkey); EC_KEY * ecKey = EVP_PKEY_get1_EC_KEY (pkey);
if (ecKey) if (ecKey)
{ {
auto group = EC_KEY_get0_group (ecKey); auto group = EC_KEY_get0_group (ecKey);
if (group) if (group)
{ {
int curve = EC_GROUP_get_curve_name (group); int curve = EC_GROUP_get_curve_name (group);
if (curve == NID_X9_62_prime256v1) if (curve == NID_X9_62_prime256v1)
{ {
uint8_t signingKey[64]; uint8_t signingKey[64];
BIGNUM * x = BN_new(), * y = BN_new(); BIGNUM * x = BN_new(), * y = BN_new();
EC_POINT_get_affine_coordinates_GFp (group, EC_POINT_get_affine_coordinates_GFp (group,
EC_KEY_get0_public_key (ecKey), x, y, NULL); EC_KEY_get0_public_key (ecKey), x, y, NULL);
bn2buf (x, signingKey, 32); bn2buf (x, signingKey, 32);
bn2buf (y, signingKey + 32, 32); bn2buf (y, signingKey + 32, 32);
BN_free (x); BN_free (y); BN_free (x); BN_free (y);
verifier = std::make_shared<i2p::crypto::ECDSAP256Verifier>(); verifier = std::make_shared<i2p::crypto::ECDSAP256Verifier>();
verifier->SetPublicKey (signingKey); verifier->SetPublicKey (signingKey);
} }
} }
EC_KEY_free (ecKey); EC_KEY_free (ecKey);
} }
EVP_PKEY_free (pkey); EVP_PKEY_free (pkey);
} }
SSL_free (ssl); SSL_free (ssl);
} }
SSL_CTX_free (ctx); SSL_CTX_free (ctx);
return verifier; return verifier;
} }
static bool CreateFamilySignature (const std::string& family, const IdentHash& ident, const std::string & filename, std::string & sig) static bool CreateFamilySignature (const std::string& family, const IdentHash& ident, const std::string & filename, std::string & sig)
{ {
SSL_CTX * ctx = SSL_CTX_new (TLSv1_method ()); SSL_CTX * ctx = SSL_CTX_new (TLSv1_method ());
int ret = SSL_CTX_use_PrivateKey_file (ctx, filename.c_str (), SSL_FILETYPE_PEM); int ret = SSL_CTX_use_PrivateKey_file (ctx, filename.c_str (), SSL_FILETYPE_PEM);
if (ret) if (ret)
{ {
SSL * ssl = SSL_new (ctx); SSL * ssl = SSL_new (ctx);
EVP_PKEY * pkey = SSL_get_privatekey (ssl); EVP_PKEY * pkey = SSL_get_privatekey (ssl);
EC_KEY * ecKey = EVP_PKEY_get1_EC_KEY (pkey); EC_KEY * ecKey = EVP_PKEY_get1_EC_KEY (pkey);
if (ecKey) if (ecKey)
{ {
auto group = EC_KEY_get0_group (ecKey); auto group = EC_KEY_get0_group (ecKey);
if (group) if (group)
{ {
int curve = EC_GROUP_get_curve_name (group); int curve = EC_GROUP_get_curve_name (group);
if (curve == NID_X9_62_prime256v1) if (curve == NID_X9_62_prime256v1)
{ {
uint8_t signingPrivateKey[32], buf[50], signature[64]; uint8_t signingPrivateKey[32], buf[50], signature[64];
bn2buf (EC_KEY_get0_private_key (ecKey), signingPrivateKey, 32); bn2buf (EC_KEY_get0_private_key (ecKey), signingPrivateKey, 32);
ECDSAP256Signer signer (signingPrivateKey); ECDSAP256Signer signer (signingPrivateKey);
size_t len = family.length (); size_t len = family.length ();
memcpy (buf, family.c_str (), len); memcpy (buf, family.c_str (), len);
memcpy (buf + len, (const uint8_t *)ident, 32); memcpy (buf + len, (const uint8_t *)ident, 32);
len += 32; len += 32;
signer.Sign (buf, len, signature); signer.Sign (buf, len, signature);
len = Base64EncodingBufferSize (64); len = Base64EncodingBufferSize (64);
char * b64 = new char[len+1]; char * b64 = new char[len+1];
len = ByteStreamToBase64 (signature, 64, b64, len); len = ByteStreamToBase64 (signature, 64, b64, len);
b64[len] = 0; b64[len] = 0;
sig = b64; sig = b64;
delete[] b64; delete[] b64;
} }
else else
return false; return false;
} }
} }
SSL_free (ssl); SSL_free (ssl);
} }
else else
return false; return false;
SSL_CTX_free (ctx); SSL_CTX_free (ctx);
return true; return true;
} }
int main(int argc, char * argv[]) int main(int argc, char * argv[])
{ {
if (argc == 1) { if (argc == 1) {
usage(argv[0]); usage(argv[0]);
return -1; return -1;
} }
int opt; int opt;
bool verbose = false; bool verbose = false;
bool help = false; bool help = false;
bool gen = false; bool gen = false;
bool sign = false; bool sign = false;
bool verify = false; bool verify = false;
std::string fam; std::string fam;
std::string privkey; std::string privkey;
std::string certfile; std::string certfile;
std::string infile; std::string infile;
std::string infofile; std::string infofile;
std::string outfile; std::string outfile;
while((opt = getopt(argc, argv, "vVhgsn:i:c:k:o:f:")) != -1) { while((opt = getopt(argc, argv, "vVhgsn:i:c:k:o:f:")) != -1) {
switch(opt) { switch(opt) {
case 'v': case 'v':
verbose = true; verbose = true;
break; break;
case 'h': case 'h':
help = true; help = true;
break; break;
case 'g': case 'g':
gen = true; gen = true;
break; break;
case 'n': case 'n':
fam = std::string(argv[optind-1]); fam = std::string(argv[optind-1]);
if (fam.size() + 32 > 50) { if (fam.size() + 32 > 50) {
std::cout << "family name too long" << std::endl; std::cout << "family name too long" << std::endl;
return 1; return 1;
} }
break; break;
case 'f': case 'f':
infofile = std::string(argv[optind-1]); infofile = std::string(argv[optind-1]);
break; break;
case 'i': case 'i':
infile = std::string(argv[optind-1]); infile = std::string(argv[optind-1]);
break; break;
case 'o': case 'o':
outfile = std::string(argv[optind-1]); outfile = std::string(argv[optind-1]);
case 'c': case 'c':
certfile = std::string(argv[optind-1]); certfile = std::string(argv[optind-1]);
break; break;
case 'k': case 'k':
privkey = std::string(argv[optind-1]); privkey = std::string(argv[optind-1]);
break; break;
case 'V': case 'V':
verify = true; verify = true;
break; break;
case 's': case 's':
sign = true; sign = true;
break; break;
default: default:
usage(argv[0]); usage(argv[0]);
return -1; return -1;
} }
} }
if(help) { if(help) {
printhelp(argv[0]); printhelp(argv[0]);
return 0; return 0;
} }
InitCrypto(false, true, true, false); InitCrypto(false, true, true, false);
if(!fam.size()) { if(!fam.size()) {
// no family name // no family name
std::cout << "no family name specified" << std::endl; std::cout << "no family name specified" << std::endl;
return 1; return 1;
} }
// generate family key code // generate family key code
if(gen) { if(gen) {
if(!privkey.size()) privkey = fam + ".key"; if(!privkey.size()) privkey = fam + ".key";
if(!certfile.size()) certfile = fam + ".crt"; if(!certfile.size()) certfile = fam + ".crt";
std::string cn = fam + ".family.i2p.net"; std::string cn = fam + ".family.i2p.net";
FILE * privf = fopen(privkey.c_str(), "w"); FILE * privf = fopen(privkey.c_str(), "w");
if(!privf) { if(!privf) {
fprintf(stderr, "cannot open %s: %s\n", privkey.c_str(), strerror(errno)); fprintf(stderr, "cannot open %s: %s\n", privkey.c_str(), strerror(errno));
return 1; return 1;
} }
FILE * certf = fopen(certfile.c_str(), "w"); FILE * certf = fopen(certfile.c_str(), "w");
if(!certf) { if(!certf) {
fprintf(stderr, "cannot open %s: %s\n", certfile.c_str(), strerror(errno)); fprintf(stderr, "cannot open %s: %s\n", certfile.c_str(), strerror(errno));
return 1; return 1;
} }
// openssl fagmastery starts here // openssl fagmastery starts here
EC_KEY * k_priv = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1); EC_KEY * k_priv = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
assert(k_priv); assert(k_priv);
EC_KEY_set_asn1_flag(k_priv, OPENSSL_EC_NAMED_CURVE); EC_KEY_set_asn1_flag(k_priv, OPENSSL_EC_NAMED_CURVE);
EC_KEY_generate_key(k_priv); EC_KEY_generate_key(k_priv);
if(verbose) std::cout << "generated key" << std::endl; if(verbose) std::cout << "generated key" << std::endl;
// TODO: password protection // TODO: password protection
PEM_write_ECPrivateKey(privf, k_priv, nullptr, nullptr, 0, nullptr, nullptr); PEM_write_ECPrivateKey(privf, k_priv, nullptr, nullptr, 0, nullptr, nullptr);
fclose(privf); fclose(privf);
if(verbose) std::cout << "wrote private key" << std::endl; if(verbose) std::cout << "wrote private key" << std::endl;
EVP_PKEY * ev_k = EVP_PKEY_new(); EVP_PKEY * ev_k = EVP_PKEY_new();
assert(ev_k); assert(ev_k);
assert(EVP_PKEY_assign_EC_KEY(ev_k, k_priv) == 1); assert(EVP_PKEY_assign_EC_KEY(ev_k, k_priv) == 1);
X509 * x = X509_new(); X509 * x = X509_new();
assert(x); assert(x);
X509_set_version(x, 2); X509_set_version(x, 2);
ASN1_INTEGER_set(X509_get_serialNumber(x), 0); ASN1_INTEGER_set(X509_get_serialNumber(x), 0);
X509_gmtime_adj(X509_get_notBefore(x),0); X509_gmtime_adj(X509_get_notBefore(x),0);
// TODO: make expiration date configurable // TODO: make expiration date configurable
X509_gmtime_adj(X509_get_notAfter(x),(long)60*60*24*365*10); X509_gmtime_adj(X509_get_notAfter(x),(long)60*60*24*365*10);
X509_set_pubkey(x, ev_k); X509_set_pubkey(x, ev_k);
X509_NAME * name = X509_get_subject_name(x); X509_NAME * name = X509_get_subject_name(x);
X509_NAME_add_entry_by_txt(name,"C", MBSTRING_ASC, (unsigned char *) "XX", -1, -1, 0); X509_NAME_add_entry_by_txt(name,"C", MBSTRING_ASC, (unsigned char *) "XX", -1, -1, 0);
X509_NAME_add_entry_by_txt(name,"ST", MBSTRING_ASC, (unsigned char *) "XX", -1, -1, 0); X509_NAME_add_entry_by_txt(name,"ST", MBSTRING_ASC, (unsigned char *) "XX", -1, -1, 0);
X509_NAME_add_entry_by_txt(name,"L", MBSTRING_ASC, (unsigned char *) "XX", -1, -1, 0); X509_NAME_add_entry_by_txt(name,"L", MBSTRING_ASC, (unsigned char *) "XX", -1, -1, 0);
X509_NAME_add_entry_by_txt(name,"O", MBSTRING_ASC, (unsigned char *) "I2P Anonymous Network", -1, -1, 0); X509_NAME_add_entry_by_txt(name,"O", MBSTRING_ASC, (unsigned char *) "I2P Anonymous Network", -1, -1, 0);
X509_NAME_add_entry_by_txt(name,"OU", MBSTRING_ASC, (unsigned char *) "family", -1, -1, 0); X509_NAME_add_entry_by_txt(name,"OU", MBSTRING_ASC, (unsigned char *) "family", -1, -1, 0);
X509_NAME_add_entry_by_txt(name,"CN", MBSTRING_ASC, (unsigned char *) cn.c_str(), -1, -1, 0); X509_NAME_add_entry_by_txt(name,"CN", MBSTRING_ASC, (unsigned char *) cn.c_str(), -1, -1, 0);
X509_set_issuer_name(x,name); X509_set_issuer_name(x,name);
if(verbose) std::cout << "signing cert" << std::endl; if(verbose) std::cout << "signing cert" << std::endl;
assert(X509_sign(x, ev_k, EVP_sha256())); assert(X509_sign(x, ev_k, EVP_sha256()));
if(verbose) std::cout << "writing private key" << std::endl; if(verbose) std::cout << "writing private key" << std::endl;
PEM_write_X509(certf, x); PEM_write_X509(certf, x);
fclose(certf); fclose(certf);
EVP_PKEY_free(ev_k); EVP_PKEY_free(ev_k);
X509_free(x); X509_free(x);
std::cout << "family " << fam << " made" << std::endl; std::cout << "family " << fam << " made" << std::endl;
} }
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;
} }
{ {
std::ifstream i; std::ifstream i;
i.open(infofile); i.open(infofile);
if(!i.is_open()) { if(!i.is_open()) {
std::cout << "cannot open " << infofile << std::endl; std::cout << "cannot open " << infofile << std::endl;
return 1; return 1;
} }
} }
if (verbose) std::cout << "load " << infofile << std::endl; if (verbose) std::cout << "load " << infofile << std::endl;
PrivateKeys keys; PrivateKeys keys;
{ {
std::ifstream fi(infile, std::ifstream::in | std::ifstream::binary); std::ifstream fi(infile, std::ifstream::in | std::ifstream::binary);
if(!fi.is_open()) { if(!fi.is_open()) {
std::cout << "cannot open " << infile << std::endl; std::cout << "cannot open " << infile << std::endl;
return 1; return 1;
} }
fi.seekg (0, std::ios::end); fi.seekg (0, std::ios::end);
size_t len = fi.tellg(); size_t len = fi.tellg();
fi.seekg (0, std::ios::beg); fi.seekg (0, std::ios::beg);
uint8_t * k = new uint8_t[len]; uint8_t * k = new uint8_t[len];
fi.read((char*)k, len); fi.read((char*)k, len);
if(!keys.FromBuffer(k, len)) { if(!keys.FromBuffer(k, len)) {
std::cout << "invalid key file " << infile << std::endl; std::cout << "invalid key file " << infile << std::endl;
return 1; return 1;
} }
delete [] k; delete [] k;
} }
RouterInfo ri(infofile); RouterInfo ri(infofile);
auto ident = ri.GetIdentHash(); auto ident = ri.GetIdentHash();
if (verbose) std::cout << "add " << ident.ToBase64() << " to " << fam << std::endl; if (verbose) std::cout << "add " << ident.ToBase64() << " to " << fam << std::endl;
std::string sig; std::string sig;
if(CreateFamilySignature(fam, ident, privkey, sig)) { if(CreateFamilySignature(fam, ident, privkey, sig)) {
ri.SetProperty(ROUTER_INFO_PROPERTY_FAMILY, fam); ri.SetProperty(ROUTER_INFO_PROPERTY_FAMILY, fam);
ri.SetProperty(ROUTER_INFO_PROPERTY_FAMILY_SIG, sig); ri.SetProperty(ROUTER_INFO_PROPERTY_FAMILY_SIG, sig);
if (verbose) std::cout << "signed " << sig << std::endl; if (verbose) std::cout << "signed " << sig << std::endl;
ri.CreateBuffer(keys); ri.CreateBuffer(keys);
if(!ri.SaveToFile(infofile)) { if(!ri.SaveToFile(infofile)) {
std::cout << "failed to save to " << infofile << std::endl; std::cout << "failed to save to " << infofile << std::endl;
} }
} else { } else {
std::cout << "failed to sign router info" << std::endl; std::cout << "failed to sign router info" << std::endl;
} }
std::cout << "signed" << std::endl; std::cout << "signed" << std::endl;
} }
if(verify) { if(verify) {
if(!infofile.size()) { if(!infofile.size()) {
std::cout << "no router info file specified" << std::endl; std::cout << "no router info file specified" << std::endl;
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);
if(!v) { if(!v) {
std::cout << "invalid certificate" << std::endl; std::cout << "invalid certificate" << std::endl;
return 1; return 1;
} }
{ {
std::ifstream i; std::ifstream i;
i.open(infofile); i.open(infofile);
if(!i.is_open()) { if(!i.is_open()) {
std::cout << "cannot open " << infofile << std::endl; std::cout << "cannot open " << infofile << std::endl;
return 1; return 1;
} }
} }
if (verbose) std::cout << "load " << infofile << std::endl; if (verbose) std::cout << "load " << infofile << std::endl;
RouterInfo ri(infofile); RouterInfo ri(infofile);
auto sig = ri.GetProperty(ROUTER_INFO_PROPERTY_FAMILY_SIG); auto sig = ri.GetProperty(ROUTER_INFO_PROPERTY_FAMILY_SIG);
if (ri.GetProperty(ROUTER_INFO_PROPERTY_FAMILY) != fam) { if (ri.GetProperty(ROUTER_INFO_PROPERTY_FAMILY) != fam) {
std::cout << infofile << " does not belong to " << fam << std::endl; std::cout << infofile << " does not belong to " << fam << std::endl;
return 1; return 1;
} }
auto ident = ri.GetIdentHash(); auto ident = ri.GetIdentHash();
uint8_t buf[50]; uint8_t buf[50];
size_t len = fam.length(); size_t len = fam.length();
memcpy(buf, fam.c_str(), len); memcpy(buf, fam.c_str(), len);
memcpy(buf + len, (const uint8_t *) ident, 32); memcpy(buf + len, (const uint8_t *) ident, 32);
len += 32; len += 32;
uint8_t sigbuf[64]; uint8_t sigbuf[64];
Base64ToByteStream(sig.c_str(), sig.length(), sigbuf, 64); Base64ToByteStream(sig.c_str(), sig.length(), sigbuf, 64);
if(!v->Verify(buf, len, sigbuf)) { if(!v->Verify(buf, len, sigbuf)) {
std::cout << "invalid signature" << std::endl; std::cout << "invalid signature" << std::endl;
return 1; return 1;
} }
std::cout << "verified" << std::endl; std::cout << "verified" << std::endl;
} }
return 0; return 0;
} }

119
i2pbase64.cpp

@ -10,76 +10,73 @@ const size_t BUFFSZ = 1024;
static int printHelp(const char * exe, int exitcode) static int printHelp(const char * exe, int exitcode)
{ {
std::cout << "usage: " << exe << " [-d] [filename]" << std::endl; std::cout << "usage: " << exe << " [-d] [filename]" << std::endl;
return exitcode; return exitcode;
} }
template <typename InCh, typename OutCh, size_t isz, size_t osz> template <typename InCh, typename OutCh, size_t isz, size_t osz>
static int operate(std::function<std::size_t(const InCh *, size_t, OutCh *, size_t)> f, int infile, int outfile) static int operate(std::function<std::size_t(const InCh *, size_t, OutCh *, size_t)> f, int infile, int outfile)
{ {
InCh inbuf[isz]; InCh inbuf[isz];
OutCh outbuf[osz]; OutCh outbuf[osz];
ssize_t sz; ssize_t sz;
size_t outsz; size_t outsz;
while((sz = read(infile, inbuf, sizeof(inbuf))) > 0) while((sz = read(infile, inbuf, sizeof(inbuf))) > 0)
{ {
outsz = f(inbuf, sz, outbuf, sizeof(outbuf)); outsz = f(inbuf, sz, outbuf, sizeof(outbuf));
if(outsz && outsz <= sizeof(outbuf)) if(outsz && outsz <= sizeof(outbuf))
{ {
write(outfile, outbuf, outsz); write(outfile, outbuf, outsz);
} }
else else
{ {
return -1; return -1;
} }
} }
return errno; return errno;
} }
int main(int argc, char * argv[]) int main(int argc, char * argv[])
{ {
int opt; int opt;
bool decode = false; bool decode = false;
int infile = 0; int infile = 0;
while((opt = getopt(argc, argv, "dh")) != -1) while((opt = getopt(argc, argv, "dh")) != -1)
{ {
switch(opt) switch(opt)
{ {
case 'h': case 'h':
return printHelp(argv[0], 0); return printHelp(argv[0], 0);
case 'd': case 'd':
decode = true; decode = true;
break; break;
default: default:
continue; continue;
} }
} }
if (argc - optind > 1) if (argc - optind > 1)
{ {
return printHelp(argv[0], -1); return printHelp(argv[0], -1);
} }
if (optind < argc) if (optind < argc)
{ {
infile = open(argv[optind], O_RDONLY); infile = open(argv[optind], O_RDONLY);
if(infile == -1) { if(infile == -1) {
perror(argv[optind]); perror(argv[optind]);
return -1; return -1;
} }
} }
int retcode = 0; int retcode = 0;
if(decode) if(decode)
{ {
retcode = operate<char, uint8_t, BUFFSZ*4, BUFFSZ*3>(i2p::data::Base64ToByteStream, infile, 1); retcode = operate<char, uint8_t, BUFFSZ*4, BUFFSZ*3>(i2p::data::Base64ToByteStream, infile, 1);
} }
else else
{ {
retcode = operate<uint8_t, char, BUFFSZ*3, BUFFSZ*4>(&i2p::data::ByteStreamToBase64, infile, 1); retcode = operate<uint8_t, char, BUFFSZ*3, BUFFSZ*4>(&i2p::data::ByteStreamToBase64, infile, 1);
} }
close(infile); close(infile);
return retcode; return retcode;
} }

4
keygen.cpp

@ -13,7 +13,7 @@ int main (int argc, char * argv[])
return -1; return -1;
} }
i2p::crypto::InitCrypto (false, true, true, false); i2p::crypto::InitCrypto (false, true, true, false);
i2p::data::SigningKeyType type = i2p::data::SIGNING_KEY_TYPE_DSA_SHA1; i2p::data::SigningKeyType type = i2p::data::SIGNING_KEY_TYPE_DSA_SHA1;
if (argc > 2) { if (argc > 2) {
std::string str(argv[2]); std::string str(argv[2]);
type = NameToSigType(str); type = NameToSigType(str);
@ -30,7 +30,7 @@ int main (int argc, char * argv[])
std::cout << "Destination " << keys.GetPublic ()->GetIdentHash ().ToBase32 () << " created" << std::endl; std::cout << "Destination " << keys.GetPublic ()->GetIdentHash ().ToBase32 () << " created" << std::endl;
} }
else else
std::cout << "Can't create file " << argv[1] << std::endl; std::cout << "Can't create file " << argv[1] << std::endl;
i2p::crypto::TerminateCrypto (); i2p::crypto::TerminateCrypto ();

140
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)
{ {
@ -20,71 +25,74 @@ 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 'v': case 'h':
verbose = true; return printHelp(argv[0], 0);
break; case 'v':
case 'd': verbose = true;
print_full = true; break;
break; case 'd':
default: print_full = true;
std::cout << "usage: " << argv[0] << " [-v] [-d] privatekey.dat" << std::endl; break;
return -1; default:
} return printHelp(argv[0], -1);
} }
std::string fname(argv[optind]); }
i2p::data::PrivateKeys keys;
{ std::string fname(argv[optind]);
std::vector<uint8_t> buff; i2p::data::PrivateKeys keys;
std::ifstream inf; {
inf.open(fname); std::vector<uint8_t> buff;
if (!inf.is_open()) { std::ifstream inf;
std::cout << "cannot open private key file " << fname << std::endl; inf.open(fname);
return 2; if (!inf.is_open()) {
} std::cout << "cannot open private key file " << fname << std::endl;
inf.seekg(0, std::ios::end); return 2;
const std::size_t len = inf.tellg(); }
inf.seekg(0, std::ios::beg); inf.seekg(0, std::ios::end);
buff.resize(len); const std::size_t len = inf.tellg();
inf.read((char*)buff.data(), buff.size()); inf.seekg(0, std::ios::beg);
if (!keys.FromBuffer(buff.data(), buff.size())) { buff.resize(len);
std::cout << "bad key file format" << std::endl; inf.read((char*)buff.data(), buff.size());
return 3; if (!keys.FromBuffer(buff.data(), buff.size())) {
} std::cout << "bad key file format" << std::endl;
} return 3;
auto dest = keys.GetPublic(); }
if(!dest) { }
std::cout << "failed to extract public key" << std::endl;
return 3; auto dest = keys.GetPublic();
} if(!dest) {
std::cout << "failed to extract public key" << std::endl;
const auto & ident = dest->GetIdentHash(); return 3;
if (verbose) { }
std::cout << "Destination: " << dest->ToBase64() << std::endl;
std::cout << "Destination Hash: " << ident.ToBase64() << std::endl; const auto & ident = dest->GetIdentHash();
std::cout << "B32 Address: " << ident.ToBase32() << ".b32.i2p" << std::endl; if (verbose) {
std::cout << "Signature Type: " << SigTypeToName(dest->GetSigningKeyType()) << std::endl; std::cout << "Destination: " << dest->ToBase64() << std::endl;
std::cout << "Encryption Type: " << (int) dest->GetCryptoKeyType() << std::endl; std::cout << "Destination Hash: " << ident.ToBase64() << std::endl;
if (keys.IsOfflineSignature ()) std::cout << "B32 Address: " << ident.ToBase32() << ".b32.i2p" << std::endl;
{ std::cout << "Signature Type: " << SigTypeToName(dest->GetSigningKeyType()) << std::endl;
std::cout << "Offline signature" << std::endl; std::cout << "Encryption Type: " << (int) dest->GetCryptoKeyType() << std::endl;
const auto& offlineSignature = keys.GetOfflineSignature (); if (keys.IsOfflineSignature ())
std::cout << "Expires: " << ConvertTime (bufbe32toh(offlineSignature.data ())) << std::endl; {
std::cout << "Transient Signature Type: " << SigTypeToName(bufbe16toh(offlineSignature.data () + 4)) << std::endl; std::cout << "Offline signature" << std::endl;
const auto& offlineSignature = keys.GetOfflineSignature ();
std::cout << "Expires: " << ConvertTime (bufbe32toh(offlineSignature.data ())) << std::endl;
std::cout << "Transient Signature Type: " << SigTypeToName(bufbe16toh(offlineSignature.data () + 4)) << std::endl;
}
} else {
if(print_full) {
std::cout << dest->ToBase64() << std::endl;
} else {
std::cout << ident.ToBase32() << ".b32.i2p" << std::endl;
}
} }
} else {
if(print_full) {
std::cout << dest->ToBase64() << std::endl;
} else {
std::cout << ident.ToBase32() << ".b32.i2p" << std::endl;
}
}
} }

20
offlinekeys.cpp

@ -23,8 +23,8 @@ int main (int argc, char * argv[])
std::ifstream inf; std::ifstream inf;
inf.open(fname); inf.open(fname);
if (!inf.is_open()) { if (!inf.is_open()) {
std::cout << "cannot open keys file " << fname << std::endl; std::cout << "cannot open keys file " << fname << std::endl;
return 2; return 2;
} }
inf.seekg(0, std::ios::end); inf.seekg(0, std::ios::end);
const std::size_t len = inf.tellg(); const std::size_t len = inf.tellg();
@ -32,13 +32,13 @@ int main (int argc, char * argv[])
buff.resize(len); buff.resize(len);
inf.read((char*)buff.data(), buff.size()); inf.read((char*)buff.data(), buff.size());
if (!keys.FromBuffer(buff.data(), buff.size())) { if (!keys.FromBuffer(buff.data(), buff.size())) {
std::cout << "bad keys file format" << std::endl; std::cout << "bad keys file format" << std::endl;
return 3; return 3;
} }
} }
i2p::data::SigningKeyType type = i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519; // EdDSA by default i2p::data::SigningKeyType type = i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519; // EdDSA by default
if (argc > 3) if (argc > 3)
{ {
std::string str(argv[3]); std::string str(argv[3]);
type = NameToSigType(str); type = NameToSigType(str);
@ -46,10 +46,10 @@ int main (int argc, char * argv[])
int days = 365; // 1 year by default int days = 365; // 1 year by default
if (argc > 4) if (argc > 4)
days = std::stoi (argv[4]); days = std::stoi (argv[4]);
uint32_t expires = i2p::util::GetSecondsSinceEpoch () + days*24*60*60; uint32_t expires = i2p::util::GetSecondsSinceEpoch () + days*24*60*60;
auto offlineKeys = keys.CreateOfflineKeys (type, expires); auto offlineKeys = keys.CreateOfflineKeys (type, expires);
std::ofstream f (argv[1], std::ofstream::binary | std::ofstream::out); std::ofstream f (argv[1], std::ofstream::binary | std::ofstream::out);
if (f) if (f)
{ {
@ -61,7 +61,7 @@ int main (int argc, char * argv[])
std::cout << "Offline keys for destination " << offlineKeys.GetPublic ()->GetIdentHash ().ToBase32 () << " created" << std::endl; std::cout << "Offline keys for destination " << offlineKeys.GetPublic ()->GetIdentHash ().ToBase32 () << " created" << std::endl;
} }
else else
std::cout << "Can't create file " << argv[1] << std::endl; std::cout << "Can't create file " << argv[1] << std::endl;
i2p::crypto::TerminateCrypto (); i2p::crypto::TerminateCrypto ();

16
regaddr.cpp

@ -12,22 +12,22 @@ int main (int argc, char * argv[])
return -1; return -1;
} }
i2p::crypto::InitCrypto (false, true, true, false); i2p::crypto::InitCrypto (false, true, true, false);
i2p::data::PrivateKeys keys; i2p::data::PrivateKeys keys;
std::ifstream s(argv[1], std::ifstream::binary); std::ifstream s(argv[1], std::ifstream::binary);
if (s.is_open ()) if (s.is_open ())
{ {
s.seekg (0, std::ios::end); s.seekg (0, std::ios::end);
size_t len = s.tellg(); size_t len = s.tellg();
s.seekg (0, std::ios::beg); s.seekg (0, std::ios::beg);
uint8_t * buf = new uint8_t[len]; uint8_t * buf = new uint8_t[len];
s.read ((char *)buf, len); s.read ((char *)buf, len);
if(keys.FromBuffer (buf, len)) if(keys.FromBuffer (buf, len))
{ {
auto signatureLen = keys.GetPublic ()->GetSignatureLen (); auto signatureLen = keys.GetPublic ()->GetSignatureLen ();
uint8_t * signature = new uint8_t[signatureLen]; uint8_t * signature = new uint8_t[signatureLen];
char * sig = new char[signatureLen*2]; char * sig = new char[signatureLen*2];
std::stringstream out; std::stringstream out;
out << argv[2] << "="; // address out << argv[2] << "="; // address
out << keys.GetPublic ()->ToBase64 (); out << keys.GetPublic ()->ToBase64 ();
@ -37,12 +37,12 @@ int main (int argc, char * argv[])
out << "#!sig=" << sig; out << "#!sig=" << sig;
delete[] signature; delete[] signature;
delete[] sig; delete[] sig;
std::cout << out.str () << std::endl; std::cout << out.str () << std::endl;
} }
else else
std::cout << "Failed to load keyfile " << argv[1] << std::endl; std::cout << "Failed to load keyfile " << argv[1] << std::endl;
delete[] buf; delete[] buf;
} }
i2p::crypto::TerminateCrypto (); i2p::crypto::TerminateCrypto ();

30
regaddralias.cpp

@ -12,13 +12,13 @@ int main (int argc, char * argv[])
return -1; return -1;
} }
i2p::crypto::InitCrypto (false, true, true, false); i2p::crypto::InitCrypto (false, true, true, false);
i2p::data::PrivateKeys oldkeys, newkeys; i2p::data::PrivateKeys oldkeys, newkeys;
{ {
std::ifstream s(argv[1], std::ifstream::binary); std::ifstream s(argv[1], std::ifstream::binary);
if (s.is_open ()) if (s.is_open ())
{ {
s.seekg (0, std::ios::end); s.seekg (0, std::ios::end);
size_t len = s.tellg(); size_t len = s.tellg();
s.seekg (0, std::ios::beg); s.seekg (0, std::ios::beg);
@ -26,22 +26,22 @@ int main (int argc, char * argv[])
s.read ((char *)buf, len); s.read ((char *)buf, len);
if(!oldkeys.FromBuffer (buf, len)) if(!oldkeys.FromBuffer (buf, len))
{ {
std::cout << "Failed to load keyfile " << argv[1] << std::endl; std::cout << "Failed to load keyfile " << argv[1] << std::endl;
return -1; return -1;
} }
delete[] buf; delete[] buf;
} }
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;
} }
} }
{ {
std::ifstream s(argv[2], std::ifstream::binary); std::ifstream s(argv[2], std::ifstream::binary);
if (s.is_open ()) if (s.is_open ())
{ {
s.seekg (0, std::ios::end); s.seekg (0, std::ios::end);
size_t len = s.tellg(); size_t len = s.tellg();
s.seekg (0, std::ios::beg); s.seekg (0, std::ios::beg);
@ -49,14 +49,14 @@ int main (int argc, char * argv[])
s.read ((char *)buf, len); s.read ((char *)buf, len);
if(!newkeys.FromBuffer (buf, len)) if(!newkeys.FromBuffer (buf, len))
{ {
std::cout << "Failed to load keyfile " << argv[2] << std::endl; std::cout << "Failed to load keyfile " << argv[2] << std::endl;
return -1; return -1;
} }
delete[] buf; delete[] buf;
} }
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;
} }
} }
@ -69,7 +69,7 @@ int main (int argc, char * argv[])
auto oldSignatureLen = oldkeys.GetPublic ()->GetSignatureLen (); auto oldSignatureLen = oldkeys.GetPublic ()->GetSignatureLen ();
uint8_t * oldSignature = new uint8_t[oldSignatureLen]; uint8_t * oldSignature = new uint8_t[oldSignatureLen];
char * oldSig = new char[oldSignatureLen*2]; char * oldSig = new char[oldSignatureLen*2];
oldkeys.Sign ((uint8_t *)out.str ().c_str (), out.str ().length (), oldSignature); oldkeys.Sign ((uint8_t *)out.str ().c_str (), out.str ().length (), oldSignature);
auto len = i2p::data::ByteStreamToBase64 (oldSignature, oldSignatureLen, oldSig, oldSignatureLen*2); auto len = i2p::data::ByteStreamToBase64 (oldSignature, oldSignatureLen, oldSig, oldSignatureLen*2);
oldSig[len] = 0; oldSig[len] = 0;
@ -79,7 +79,7 @@ int main (int argc, char * argv[])
auto signatureLen = newkeys.GetPublic ()->GetSignatureLen (); auto signatureLen = newkeys.GetPublic ()->GetSignatureLen ();
uint8_t * signature = new uint8_t[signatureLen]; uint8_t * signature = new uint8_t[signatureLen];
char * sig = new char[signatureLen*2]; char * sig = new char[signatureLen*2];
newkeys.Sign ((uint8_t *)out.str ().c_str (), out.str ().length (), signature); newkeys.Sign ((uint8_t *)out.str ().c_str (), out.str ().length (), signature);
len = i2p::data::ByteStreamToBase64 (signature, signatureLen, sig, signatureLen*2); len = i2p::data::ByteStreamToBase64 (signature, signatureLen, sig, signatureLen*2);
sig[len] = 0; sig[len] = 0;
@ -87,7 +87,7 @@ int main (int argc, char * argv[])
delete[] signature; delete[] signature;
delete[] sig; delete[] sig;
std::cout << out.str () << std::endl; std::cout << out.str () << std::endl;
i2p::crypto::TerminateCrypto (); i2p::crypto::TerminateCrypto ();

12
routerinfo.cpp

@ -18,7 +18,7 @@ static std::string address_style_string(Addr addr)
return "SSU"; return "SSU";
} }
return "???"; return "???";
} }
template<typename Addr> template<typename Addr>
@ -73,7 +73,7 @@ int main(int argc, char * argv[])
optind ++; optind ++;
std::string fname(argv[idx]); std::string fname(argv[idx]);
i2p::data::RouterInfo ri(fname); i2p::data::RouterInfo ri(fname);
std::vector<std::shared_ptr<const i2p::data::RouterInfo::Address> > addrs; std::vector<std::shared_ptr<const i2p::data::RouterInfo::Address> > addrs;
auto a = ri.GetNTCP2Address(!ipv6); auto a = ri.GetNTCP2Address(!ipv6);
if(a) if(a)
@ -87,20 +87,20 @@ int main(int argc, char * argv[])
else else
std::cout << "Router Hash: "; std::cout << "Router Hash: ";
std::cout << ri.GetIdentHashBase64() << std::endl; std::cout << ri.GetIdentHashBase64() << std::endl;
for (const auto & a : addrs) { for (const auto & a : addrs) {
if(firewall) { if(firewall) {
write_firewall_entry(std::cout, a); write_firewall_entry(std::cout, a);
} else { } else {
std::cout << address_style_string(a) << ": " << a->host; std::cout << address_style_string(a) << ": " << a->host;
if (port) if (port)
std::cout << ":" << a->port; std::cout << ":" << a->port;
} }
std::cout << std::endl; std::cout << std::endl;
} }
} }
return 0; return 0;
} }

20
vanity.hpp

@ -54,14 +54,14 @@ 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,
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, 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)
}; };

94
vanitygen.cpp

@ -3,21 +3,21 @@
#include<getopt.h> #include<getopt.h>
static struct{ static struct
bool reg=false; {
int threads=-1; bool reg=false;
i2p::data::SigningKeyType signature; int threads=-1;
std::string outputpath=""; i2p::data::SigningKeyType signature;
std::regex regex; std::string outputpath="";
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
@ -179,39 +179,35 @@ Orignal is sensei of crypto ;)
for (int j = 8; j--;) for (int j = 8; j--;)
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;
//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;
found=true; found=true;
FoundNonce=*nonce; FoundNonce=*nonce;
// free(hash); // free(hash);
// free(b); // free(b);
return true; return true;
} }
(*nonce)++; (*nonce)++;
hashescounter++; hashescounter++;
if (found) if (found)
{ {
// free(hash); // free(hash);
// 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