From dfa5a30f9c2bd9a3034aa24df7d77cbf3fa54b01 Mon Sep 17 00:00:00 2001 From: acetoneRu Date: Wed, 2 Jun 2021 13:42:38 -0400 Subject: [PATCH 01/45] gitignore updated --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 94d6982..5754812 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,8 @@ vain b33address offlinekeys regaddr_3ld +verifyhost +x25519 *.exe # private key files From e9223dae8a646e949f38c21db9a6a2b4c6f151da Mon Sep 17 00:00:00 2001 From: acetoneRu Date: Wed, 2 Jun 2021 13:50:38 -0400 Subject: [PATCH 02/45] README updated: dependencies are deleted --- README.md | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) mode change 100644 => 100755 README.md diff --git a/README.md b/README.md old mode 100644 new mode 100755 index b434ce0..1f0c4b4 --- a/README.md +++ b/README.md @@ -11,36 +11,18 @@ Notice: git submodules are used so make sure to clone this repository recursivel ### Dependencies * boost chrono + * boost date-time + * boost filesystem + * boost program-options + * libssl + * zlib1g -```bash - -depend="libboost-chrono-dev \ - libboost-date-time-dev \ - libboost-filesystem-dev \ - libboost-program-options-dev \ - libboost-system-dev \ - libboost-thread-dev \ - libssl-dev \ - zlib1g-dev" -kernel=`uname -a` - -case "$kernel" in -*Ubuntu*) - sudo apt install $depend;; -*debian*) - sudo aptitude install $depend;; -*gentoo*) - sudo emerge --deep --newuse dev-libs/boost dev-libs/openssl;; - -*) - echo "Just install libboost and libopenssl dev packages on your pc";; -esac -``` + (run `dependencies.sh`) ### Building @@ -162,3 +144,7 @@ Generate authentication string to register an alias address for existing domain cat auth_string.txt Send output of auth_string to http://reg.i2p/add and http://stats.i2p/i2p/addkey.html + +### x25519 + +Generate key pair with output in base64 encoding. Now the x25519 keys are used for authentication with an encrypted LeaseSet. From e9622a37c148f6b6d1b72e2cd4100e386458f9bb Mon Sep 17 00:00:00 2001 From: acetoneRu Date: Wed, 2 Jun 2021 14:07:10 -0400 Subject: [PATCH 03/45] depend script (Debian fixed, MinGW added) --- dependencies.sh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 dependencies.sh diff --git a/dependencies.sh b/dependencies.sh new file mode 100755 index 0000000..2b2b7d6 --- /dev/null +++ b/dependencies.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +dependNix="libboost-chrono-dev \ + libboost-date-time-dev \ + libboost-filesystem-dev \ + libboost-program-options-dev \ + libboost-system-dev \ + libboost-thread-dev \ + libssl-dev \ + zlib1g-dev" + +dependWin="mingw-w64-x86_64-boost \ + mingw-w64-x86_64-openssl \ + mingw-w64-x86_64-zlib" + +kernel=`uname -a` + +case "$kernel" in +*Ubuntu*|*Debian*) + sudo apt install $dependNix;; +*gentoo*) + sudo emerge --deep --newuse dev-libs/boost dev-libs/openssl;; +*MINGW64*) + pacman -S $dependWin;; +*) + echo "Just install libboost and libopenssl dev packages on your pc";; +esac From 263809be18ceaa566e89c4c2c72913c8155c14e1 Mon Sep 17 00:00:00 2001 From: acetone <63557806+acetoneRu@users.noreply.github.com> Date: Thu, 3 Jun 2021 00:34:30 -0400 Subject: [PATCH 04/45] RED25519-SHA512 added to README also pasted link to docs --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 1f0c4b4..d3e8d05 100755 --- a/README.md +++ b/README.md @@ -76,6 +76,9 @@ or | EDDSA-SHA512-ED25519 | 7 | | GOSTR3410_CRYPTO_PRO_A-GOSTR3411-256 | 9 | | GOSTR3410_TC26_A_512-GOSTR3411-512 | 10 | +| RED25519-SHA512 | 11 | + +For more information on the types of signatures, see the [documentation](https://i2pd.readthedocs.io/en/latest/user-guide/tunnels/#signature-types). ### vain From 9618b2093903cd306943b6cc1113dda8a78037d1 Mon Sep 17 00:00:00 2001 From: acetoneRu Date: Thu, 3 Jun 2021 00:56:35 -0400 Subject: [PATCH 05/45] keygen in user friendly mode --- keygen.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/keygen.cpp b/keygen.cpp index 9105d92..81d184c 100644 --- a/keygen.cpp +++ b/keygen.cpp @@ -17,6 +17,7 @@ int main (int argc, char * argv[]) if (argc > 2) { std::string str(argv[2]); type = NameToSigType(str); + if (SigTypeToName(type).find("unknown") != std::string::npos) { std::cerr << "Incorrect signature type" << std::endl; return -2; } } auto keys = i2p::data::PrivateKeys::CreateRandomKeys (type); std::ofstream f (argv[1], std::ofstream::binary | std::ofstream::out); @@ -28,6 +29,7 @@ int main (int argc, char * argv[]) f.write ((char *)buf, len); delete[] buf; std::cout << "Destination " << keys.GetPublic ()->GetIdentHash ().ToBase32 () << " created" << std::endl; + std::cout << "Signature type: " << SigTypeToName(type) << " (" << type << ")" << std::endl; } else std::cout << "Can't create file " << argv[1] << std::endl; From 3f59de5e733220c06008e11982196d01202dee62 Mon Sep 17 00:00:00 2001 From: acetoneRu Date: Thu, 3 Jun 2021 01:33:13 -0400 Subject: [PATCH 06/45] vanitygen output formatted with mutex --- vanitygen.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/vanitygen.cpp b/vanitygen.cpp index 982d09d..883284e 100644 --- a/vanitygen.cpp +++ b/vanitygen.cpp @@ -1,6 +1,7 @@ #include "vanity.hpp" -#include -#include +#include +#include +#include static struct @@ -124,6 +125,7 @@ static inline bool NotThat(const char * a, const char *b) return false; } +std::mutex mtx; static inline bool thread_find(uint8_t * buf, const char * prefix, int id_thread, unsigned long long throughput) { /** @@ -131,7 +133,9 @@ static inline bool thread_find(uint8_t * buf, const char * prefix, int id_thread * For idea and example ^-^ * Orignal is sensei of crypto ;) */ + mtx.lock(); std::cout << "Thread " << id_thread << " binded" << std::endl; + mtx.unlock(); /* union { From 24e127f561d721964daadd172e995e5ba9f7ae2c Mon Sep 17 00:00:00 2001 From: acetoneRu Date: Thu, 3 Jun 2021 02:09:22 -0400 Subject: [PATCH 07/45] gen: signature choice deleted --- vanitygen.cpp | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/vanitygen.cpp b/vanitygen.cpp index 883284e..81ee356 100644 --- a/vanitygen.cpp +++ b/vanitygen.cpp @@ -11,8 +11,17 @@ static struct i2p::data::SigningKeyType signature; std::string outputpath=""; std::regex regex; + bool sig_type = true; } options; +void check_sig_type() +{ + if (SigTypeToName(options.signature).find("unknown") != std::string::npos) + { + std::cerr << "Incorrect signature type" << std::endl; + options.sig_type = false; + } +} static void inline CalculateW (const uint8_t block[64], uint32_t W[64]) { @@ -214,13 +223,12 @@ static inline bool thread_find(uint8_t * buf, const char * prefix, int id_thread void usage(void){ const constexpr char * help="vain [text-pattern|regex-pattern] [options]\n" - "-h --help, help menu\n" - "-r --reg, regexp instead just text pattern (e.g. '(one|two).*')\n" - "--threads -t, (default count of system)\n" - "--signature -s, (signature type)\n" - "-o --output output file (default private.dat)\n" - "--usage usage\n" - // "--prefix -p\n" + "-h --help help menu\n" + "-r --reg regexp instead just text pattern (e.g. '(one|two).*')\n" + "-t --threads (default count of system)\n" +// "--signature -s, (signature type)\n" NOT IMPLEMENTED FUCKING PLAZ! + "-o --output output file (default private.dat)\n" + "--usage usage\n" ""; puts(help); } @@ -257,6 +265,7 @@ void parsing(int argc, char ** args){ break; case 's': options.signature = NameToSigType(std::string(optarg)); + check_sig_type(); break; case 'o': options.outputpath=optarg; @@ -306,6 +315,7 @@ int main (int argc, char * argv[]) /////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + if (!options.sig_type) return -2; auto keys = i2p::data::PrivateKeys::CreateRandomKeys (options.signature); switch(options.signature) { @@ -315,7 +325,7 @@ int main (int argc, char * argv[]) case i2p::data::SIGNING_KEY_TYPE_RSA_SHA384_3072: case i2p::data::SIGNING_KEY_TYPE_RSA_SHA512_4096: case i2p::data::SIGNING_KEY_TYPE_GOSTR3410_TC26_A_512_GOSTR3411_512: - std::cout << "Sorry, i don't can generate address for this signature type" << std::endl; + std::cout << "Sorry, I don't can generate address for this signature type" << std::endl; return 0; break; } From 4d89abf0af7d4cffe82da61362d1d94c18de7816 Mon Sep 17 00:00:00 2001 From: acetoneRu Date: Thu, 3 Jun 2021 02:53:30 -0400 Subject: [PATCH 08/45] id_thread is not needed for user output --- vanitygen.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vanitygen.cpp b/vanitygen.cpp index 81ee356..1dbd240 100644 --- a/vanitygen.cpp +++ b/vanitygen.cpp @@ -200,7 +200,7 @@ static inline bool thread_find(uint8_t * buf, const char * prefix, int id_thread // if(result) { ByteStreamToBase32 ((uint8_t*)hash, 32, addr, 52); - std::cout << "Address found " << addr << " in " << id_thread << std::endl; + std::cout << "Address found " << addr << std::endl; found=true; FoundNonce=*nonce; // free(hash); From d888825470eba84640769a5c2b66dede99707247 Mon Sep 17 00:00:00 2001 From: acetoneRu Date: Thu, 3 Jun 2021 03:10:56 -0400 Subject: [PATCH 09/45] --usage deleted because --help and -h already exist --- vanitygen.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/vanitygen.cpp b/vanitygen.cpp index 1dbd240..5030ec1 100644 --- a/vanitygen.cpp +++ b/vanitygen.cpp @@ -228,7 +228,6 @@ void usage(void){ "-t --threads (default count of system)\n" // "--signature -s, (signature type)\n" NOT IMPLEMENTED FUCKING PLAZ! "-o --output output file (default private.dat)\n" - "--usage usage\n" ""; puts(help); } From 56b8d02a975464f915d25d80f7cde44626f28897 Mon Sep 17 00:00:00 2001 From: acetone <63557806+acetoneRu@users.noreply.github.com> Date: Thu, 3 Jun 2021 03:45:27 -0400 Subject: [PATCH 10/45] keyinfo tool description corrected --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index d3e8d05..e460faf 100755 --- a/README.md +++ b/README.md @@ -91,17 +91,17 @@ Vanity generation address. #### Time to Generate on a 2.70GHz Processor | characters| time to generate (approx.) | | -------------------- | --------------- | -| 1 | ~0.082s | -| 2 | ~0.075s | -| 3 | ~0.100s | -| 4 | ~0.394s | -| 5 | ~6.343s | -| 6 | ~1m-5m | -| 7 | ~30m | +| 1 | ~0.082s | +| 2 | ~0.075s | +| 3 | ~0.100s | +| 4 | ~0.394s | +| 5 | ~6.343s | +| 6 | ~1m-5m | +| 7 | ~30m | ### keyinfo -Prints information about an i2p private key +Prints information about an i2p keys #### Usage From 31452d924dbb73b64b2d9b294f125092edc294ed Mon Sep 17 00:00:00 2001 From: acetone <63557806+acetoneRu@users.noreply.github.com> Date: Thu, 3 Jun 2021 03:54:28 -0400 Subject: [PATCH 11/45] i2p -> I2P --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e460faf..3a55aa1 100755 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ print iptables firewall rules to allow 1 nodes in netdb through firewall includi ### keygen -Generate an i2p private key +Generate an I2P private key #### Usage @@ -101,7 +101,7 @@ Vanity generation address. ### keyinfo -Prints information about an i2p keys +Prints information about an I2P private key #### Usage From 86f1bf9fe74b0f9ede4b2355d6ef192d5651de08 Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 25 Jun 2021 12:11:33 -0400 Subject: [PATCH 12/45] fixed #74 --- i2pd | 2 +- x25519.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/i2pd b/i2pd index f22eaa6..3c07665 160000 --- a/i2pd +++ b/i2pd @@ -1 +1 @@ -Subproject commit f22eaa6db51e36d0a064c56907589164752035c5 +Subproject commit 3c076654794c619eed228adcac075e9c1dea732f diff --git a/x25519.cpp b/x25519.cpp index faf2ad3..4a93b1e 100644 --- a/x25519.cpp +++ b/x25519.cpp @@ -38,7 +38,7 @@ int main(int argc, char * argv[]) { if (argc > 1) { - std::string arg = static_cast(argv[1]); + std::string arg (argv[1]); if (arg == "--usage" || arg == "--help" || arg == "-h") { std::cout << "The x25519 keys are used for authentication with an encrypted LeaseSet.\n" @@ -57,7 +57,7 @@ int main(int argc, char * argv[]) BoxKeys newKeys = getKeyPair(); - size_t len_out = 50; + const size_t len_out = 50; char b64Public[len_out] = {0}; char b64Private[len_out] = {0}; From a5b0dd1a34b0fd4c4f0fece1462ce77a7dc0eb4e Mon Sep 17 00:00:00 2001 From: xanoni <77220130+xanoni@users.noreply.github.com> Date: Mon, 18 Oct 2021 03:14:27 -0400 Subject: [PATCH 13/45] Improve `vain` output format and instructions - Clarify usage and instructions, add better examples - Move hardcoded defaults to vanity.hpp definitions - Fix typos (e.g., binded => bound) and make output look nicer --- vanity.hpp | 2 ++ vanitygen.cpp | 38 ++++++++++++++++++++------------------ 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/vanity.hpp b/vanity.hpp index 84c8e0f..4c46d3a 100644 --- a/vanity.hpp +++ b/vanity.hpp @@ -38,6 +38,8 @@ S[(70 - i) % 8], S[(71 - i) % 8], \ W[i] + k) +#define DEF_OUTNAME "private.dat" + //static i2p::data::SigningKeyType type; //static i2p::data::PrivateKeys keys; diff --git a/vanitygen.cpp b/vanitygen.cpp index 5030ec1..595462b 100644 --- a/vanitygen.cpp +++ b/vanitygen.cpp @@ -143,7 +143,7 @@ static inline bool thread_find(uint8_t * buf, const char * prefix, int id_thread * Orignal is sensei of crypto ;) */ mtx.lock(); - std::cout << "Thread " << id_thread << " binded" << std::endl; + std::cout << "[+] thread " << id_thread << " bound" << std::endl; mtx.unlock(); /* union @@ -200,7 +200,7 @@ static inline bool thread_find(uint8_t * buf, const char * prefix, int id_thread // if(result) { ByteStreamToBase32 ((uint8_t*)hash, 32, addr, 52); - std::cout << "Address found " << addr << std::endl; + std::cout << "\nFound address: " << addr << std::endl; found=true; FoundNonce=*nonce; // free(hash); @@ -222,12 +222,14 @@ static inline bool thread_find(uint8_t * buf, const char * prefix, int id_thread } void usage(void){ - const constexpr char * help="vain [text-pattern|regex-pattern] [options]\n" - "-h --help help menu\n" - "-r --reg regexp instead just text pattern (e.g. '(one|two).*')\n" - "-t --threads (default count of system)\n" -// "--signature -s, (signature type)\n" NOT IMPLEMENTED FUCKING PLAZ! - "-o --output output file (default private.dat)\n" + const constexpr char * help="Usage:\n" + " vain [text-pattern|regex-pattern] [options]\n\n" + "OPTIONS:\n" + " -h --help show this help (same as --usage)\n" + " -r --reg use regexp instead of simple text pattern, ex.: vain '(one|two).*' -r\n" + " -t --threads number of threads to use (default: one per processor)\n" +// " -s --signature (signature type)\n" // NOT IMPLEMENTED FUCKING PLAZ! + " -o --output privkey output file name (default: ./" DEF_OUTNAME ")\n" ""; puts(help); } @@ -308,7 +310,7 @@ int main (int argc, char * argv[]) //For while if(options.signature != i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519) { - std::cout << "For a while only ED25519-SHA512" << std::endl; + std::cout << "ED25519-SHA512 are currently the only signing keys supported." << std::endl; return 0; } /////////////// @@ -324,7 +326,7 @@ int main (int argc, char * argv[]) case i2p::data::SIGNING_KEY_TYPE_RSA_SHA384_3072: case i2p::data::SIGNING_KEY_TYPE_RSA_SHA512_4096: case i2p::data::SIGNING_KEY_TYPE_GOSTR3410_TC26_A_512_GOSTR3411_512: - std::cout << "Sorry, I don't can generate address for this signature type" << std::endl; + std::cout << "Sorry, selected signature type is not supported for address generation." << std::endl; return 0; break; } @@ -371,7 +373,7 @@ int main (int argc, char * argv[]) #endif } - std::cout << "Start vanity generator in " << options.threads << " threads" << std::endl; + std::cout << "Initializing vanity generator (" << options.threads << " threads)\n" << std::endl; unsigned short attempts = 0; while(!found) @@ -381,28 +383,28 @@ int main (int argc, char * argv[]) std::vector threads(options.threads); unsigned long long thoughtput = 0x4F4B5A37; - for ( unsigned int j = options.threads;j--;) + std::cout << "Starting attempt #" << ++attempts << ":" << std::endl; + for (unsigned int j = options.threads;j--;) { threads[j] = std::thread(thread_find,KeyBuf,argv[1],j,thoughtput); thoughtput+=1000; } // 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(); - if(FoundNonce == 0) + if (FoundNonce == 0) { RAND_bytes( KeyBuf+MutateByte , 90 ); - std::cout << "Attempts #" << ++attempts << std::endl; } } // stack } // while memcpy (KeyBuf + MutateByte, &FoundNonce, 4); - std::cout << "Hashes: " << hashescounter << std::endl; + std::cout << "Hashes calculated: " << hashescounter << std::endl; - if(options.outputpath.size() == 0) options.outputpath="private.dat"; + if(options.outputpath.size() == 0) options.outputpath.assign(DEF_OUTNAME); std::ofstream f (options.outputpath, std::ofstream::binary | std::ofstream::out); if (f) @@ -411,7 +413,7 @@ int main (int argc, char * argv[]) delete [] KeyBuf; } else - std::cout << "Can't create file " << options.outputpath << std::endl; + std::cout << "Can't create output file: " << options.outputpath << std::endl; i2p::crypto::TerminateCrypto (); From 06eab112fc70a51ca1d5ff7bcc0921210bce84b3 Mon Sep 17 00:00:00 2001 From: "Ill5.com Softworks" <105583568+ill5-com@users.noreply.github.com> Date: Sat, 29 Oct 2022 15:29:33 -0700 Subject: [PATCH 14/45] scan entire string when using regex len variable would only scan the length of the regex string. this means if you were to use the regex expression .*i2p$ it would generate btbi2pxm5xi4zh32ye5emeq5koqbdd2gywxmpzjpaivpf744bcka instead of btbckaxm5xi4zh32ye5emeq5koqbdd2gywxmpzjpaivpf744bi2p --- vanitygen.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/vanitygen.cpp b/vanitygen.cpp index 595462b..1ea3f31 100644 --- a/vanitygen.cpp +++ b/vanitygen.cpp @@ -162,7 +162,11 @@ static inline bool thread_find(uint8_t * buf, const char * prefix, int id_thread memcpy (b, buf, 391); - auto len = strlen (prefix); + size_t len = 52; + + if (!options.reg) + len = strlen(prefix); + // precalculate first 5 blocks (320 bytes) uint32_t state[8] = { 0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19 }; HashNextBlock (state, b); From aadc780b44135d4b13f80b843d4c43810c2d7a7d Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 25 Nov 2022 15:02:22 -0500 Subject: [PATCH 15/45] fixed build error for LocalRouterInfo and SSU2 --- famtool.cpp | 4 ++-- i2pd | 2 +- routerinfo.cpp | 21 ++++++++++++--------- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/famtool.cpp b/famtool.cpp index cbd0bfb..b117842 100644 --- a/famtool.cpp +++ b/famtool.cpp @@ -319,7 +319,7 @@ int main(int argc, char * argv[]) delete [] k; } - RouterInfo ri(infofile); + LocalRouterInfo ri(infofile); auto ident = ri.GetIdentHash(); @@ -365,7 +365,7 @@ int main(int argc, char * argv[]) if (verbose) std::cout << "load " << infofile << std::endl; - RouterInfo ri(infofile); + LocalRouterInfo ri(infofile); auto sig = ri.GetProperty(ROUTER_INFO_PROPERTY_FAMILY_SIG); if (ri.GetProperty(ROUTER_INFO_PROPERTY_FAMILY) != fam) { std::cout << infofile << " does not belong to " << fam << std::endl; diff --git a/i2pd b/i2pd index 3c07665..aead9db 160000 --- a/i2pd +++ b/i2pd @@ -1 +1 @@ -Subproject commit 3c076654794c619eed228adcac075e9c1dea732f +Subproject commit aead9db9712f8b07828a264a40898643385d7553 diff --git a/routerinfo.cpp b/routerinfo.cpp index aeb51f6..a2b1713 100644 --- a/routerinfo.cpp +++ b/routerinfo.cpp @@ -12,10 +12,10 @@ static void usage(const char * argv) template static std::string address_style_string(Addr addr) { - if(addr->transportStyle == i2p::data::RouterInfo::eTransportNTCP) { - return "NTCP"; - } else if (addr->transportStyle == i2p::data::RouterInfo::eTransportSSU) { - return "SSU"; + if(addr->transportStyle == i2p::data::RouterInfo::eTransportNTCP2) { + return "NTCP2"; + } else if (addr->transportStyle == i2p::data::RouterInfo::eTransportSSU2) { + return "SSU2"; } return "???"; @@ -26,9 +26,9 @@ static void write_firewall_entry(std::ostream & o, Addr addr) { std::string proto; - if(addr->transportStyle == i2p::data::RouterInfo::eTransportNTCP) { + if(addr->transportStyle == i2p::data::RouterInfo::eTransportNTCP2) { proto = "tcp"; - } else if (addr->transportStyle == i2p::data::RouterInfo::eTransportSSU) { + } else if (addr->transportStyle == i2p::data::RouterInfo::eTransportSSU2) { proto = "udp"; } else { // bail @@ -76,6 +76,9 @@ int main(int argc, char * argv[]) std::vector > addrs; auto a = ri.GetPublishedNTCP2V4Address(); + if(a) + addrs.push_back(a); + a = ri.GetSSU2V4Address(); if(a) addrs.push_back(a); if (ipv6) @@ -83,10 +86,10 @@ int main(int argc, char * argv[]) a = ri.GetPublishedNTCP2V6Address(); if(a) addrs.push_back(a); + a = ri.GetSSU2V6Address(); + if(a) + addrs.push_back(a); } - a = ri.GetSSUAddress(!ipv6); - if(a) - addrs.push_back(a); if(firewall) std::cout << "# "; From f9348979a23dec01d1bb91519f6bc2525dc01958 Mon Sep 17 00:00:00 2001 From: R4SAS Date: Sat, 11 Mar 2023 21:32:14 +0000 Subject: [PATCH 16/45] fix keyinfo on latest gcc, update Makefile Signed-off-by: R4SAS --- Makefile | 64 +++++++++++++++++++++++++++-------------------------- i2pd | 2 +- keyinfo.cpp | 52 +++++++++++++++++++++++++------------------ regaddr.cpp | 4 +++- 4 files changed, 67 insertions(+), 55 deletions(-) diff --git a/Makefile b/Makefile index 2ec136b..f0a251c 100644 --- a/Makefile +++ b/Makefile @@ -5,82 +5,84 @@ I2PD_LIB = libi2pd.a LIBI2PD_PATH = $(I2PD_PATH)/libi2pd LIBI2PD_CLIENT_PATH = $(I2PD_PATH)/libi2pd_client + CXX ?= g++ -FLAGS = -Wall -std=c++11 -Wno-misleading-indentation +CXXFLAGS = -Wall -std=c++17 +INCFLAGS = -I$(LIBI2PD_PATH) -I$(LIBI2PD_CLIENT_PATH) +DEFINES = -DOPENSSL_SUPPRESS_DEPRECATED + +LDFLAGS = +LDLIBS = $(I2PD_PATH)/$(I2PD_LIB) -lboost_system$(BOOST_SUFFIX) -lboost_date_time$(BOOST_SUFFIX) -lboost_filesystem$(BOOST_SUFFIX) -lboost_program_options$(BOOST_SUFFIX) -lssl -lcrypto -lz ifeq ($(UNAME),Linux) - FLAGS += -g + CXXFLAGS += -g else ifeq ($(UNAME),Darwin) - FLAGS += -g + CXXFLAGS += -g else ifeq ($(UNAME),FreeBSD) - FLAGS += -g + CXXFLAGS += -g else # Win32 - FLAGS += -Os -D_MT -DWIN32 -D_WINDOWS -DWIN32_LEAN_AND_MEAN + CXXFLAGS += -Os -fPIC -msse + DEFINES += -DWIN32_LEAN_AND_MEAN BOOST_SUFFIX = -mt endif -INCFLAGS = -I$(LIBI2PD_PATH) -I$(LIBI2PD_CLIENT_PATH) -CXXFLAGS = $(FLAGS) -LDFLAGS = -LIBS = $(I2PD_PATH)/$(I2PD_LIB) -lboost_system$(BOOST_SUFFIX) -lboost_date_time$(BOOST_SUFFIX) -lboost_filesystem$(BOOST_SUFFIX) -lboost_program_options$(BOOST_SUFFIX) -lssl -lcrypto -lz - ifeq ($(UNAME),Linux) - LIBS += -lrt -lpthread + LDLIBS += -lrt -lpthread else ifeq ($(UNAME),Darwin) - LIBS += -lpthread + LDLIBS += -lpthread LDFLAGS += -L/usr/local/opt/openssl@1.1/lib -L/usr/local/lib INCFLAGS += -I/usr/local/opt/openssl@1.1/include -I/usr/local/include else ifeq ($(UNAME),FreeBSD) - LIBS += -lthr -lpthread - LDFLAGS += -L/usr/local/lib + LDLIBS += -lthr -lpthread + LDFLAGS += -L/usr/local/lib INCFLAGS += -I/usr/local/include else # Win32 - LIBS += -lws2_32 -lwsock32 -lgdi32 -liphlpapi -lstdc++ -lpthread - LDFLAGS += -s -Wl,-Bstatic -static-libgcc -static-libstdc++ + LDLIBS += -lwsock32 -lws2_32 -liphlpapi -lpthread + LDFLAGS += -s -static endif all: $(I2PD_LIB) keygen keyinfo famtool routerinfo regaddr regaddr_3ld vain i2pbase64 offlinekeys b33address regaddralias x25519 verifyhost routerinfo: routerinfo.o $(I2PD_LIB) - $(CXX) -o routerinfo routerinfo.o $(LDFLAGS) $(LIBS) + $(CXX) -o routerinfo $(LDFLAGS) routerinfo.o $(LDLIBS) keygen: keygen.o $(I2PD_LIB) - $(CXX) -o keygen keygen.o $(LDFLAGS) $(LIBS) + $(CXX) -o keygen $(DEFINES) $(LDFLAGS) keygen.o $(LDLIBS) keyinfo: keyinfo.o $(I2PD_LIB) - $(CXX) -o keyinfo keyinfo.o $(LDFLAGS) $(LIBS) + $(CXX) -o keyinfo $(DEFINES) $(LDFLAGS) keyinfo.o $(LDLIBS) famtool: famtool.o $(I2PD_LIB) - $(CXX) -o famtool famtool.o $(LDFLAGS) $(LIBS) + $(CXX) -o famtool $(DEFINES) $(LDFLAGS) famtool.o $(LDLIBS) regaddr: regaddr.o $(I2PD_LIB) - $(CXX) -o regaddr regaddr.o $(LDFLAGS) $(LIBS) + $(CXX) -o regaddr $(DEFINES) $(LDFLAGS) regaddr.o $(LDLIBS) regaddr_3ld: regaddr_3ld.o $(I2PD_LIB) - $(CXX) -o regaddr_3ld regaddr_3ld.o $(LDFLAGS) $(LIBS) + $(CXX) -o regaddr_3ld $(DEFINES) $(LDFLAGS) regaddr_3ld.o $(LDLIBS) vain: vanitygen.o $(I2PD_LIB) - $(CXX) -o vain vanitygen.o $(LDFLAGS) $(LIBS) + $(CXX) -o vain $(DEFINES) $(LDFLAGS) vanitygen.o $(LDLIBS) i2pbase64: i2pbase64.o $(I2PD_LIB) - $(CXX) -o i2pbase64 i2pbase64.o $(LDFLAGS) $(LIBS) + $(CXX) -o i2pbase64 $(DEFINES) $(LDFLAGS) i2pbase64.o $(LDLIBS) offlinekeys: offlinekeys.o $(I2PD_LIB) - $(CXX) -o offlinekeys offlinekeys.o $(LDFLAGS) $(LIBS) + $(CXX) -o offlinekeys $(DEFINES) $(LDFLAGS) offlinekeys.o $(LDLIBS) b33address: b33address.o $(I2PD_LIB) - $(CXX) -o b33address b33address.o $(LDFLAGS) $(LIBS) + $(CXX) -o b33address $(DEFINES) $(LDFLAGS) b33address.o $(LDLIBS) regaddralias: regaddralias.o $(I2PD_LIB) - $(CXX) -o regaddralias regaddralias.o $(LDFLAGS) $(LIBS) - + $(CXX) -o regaddralias $(DEFINES) $(LDFLAGS) regaddralias.o $(LDLIBS) + x25519: x25519.o $(I2PD_LIB) - $(CXX) -o x25519 x25519.o $(LDFLAGS) $(LIBS) + $(CXX) -o x25519 $(DEFINES) $(LDFLAGS) x25519.o $(LDLIBS) verifyhost: verifyhost.o $(I2PD_LIB) - $(CXX) -o verifyhost verifyhost.o $(LDFLAGS) $(LIBS) + $(CXX) -o verifyhost $(DEFINES) $(LDFLAGS) verifyhost.o $(LDLIBS) .SUFFIXES: .SUFFIXES: .c .cc .C .cpp .o @@ -89,7 +91,7 @@ $(I2PD_LIB): $(MAKE) -C $(I2PD_PATH) mk_obj_dir $(I2PD_LIB) %.o: %.cpp $(I2PD_LIB) - $(CXX) -o $@ -c $(CXXFLAGS) $(INCFLAGS) $< + $(CXX) $(CXXFLAGS) $(DEFINES) $(INCFLAGS) -c -o $@ $< count: wc *.c *.cc *.C *.cpp *.h *.hpp diff --git a/i2pd b/i2pd index aead9db..a6bd827 160000 --- a/i2pd +++ b/i2pd @@ -1 +1 @@ -Subproject commit aead9db9712f8b07828a264a40898643385d7553 +Subproject commit a6bd8275ca496c75c84d7eb890c0071569d28f55 diff --git a/keyinfo.cpp b/keyinfo.cpp index 4a8d19e..2f79bb8 100644 --- a/keyinfo.cpp +++ b/keyinfo.cpp @@ -12,7 +12,7 @@ static int printHelp(const char * exe, int exitcode) { - std::cout << "usage: " << exe << " [-v] [-d] [-b] privatekey.dat" << std::endl; + std::cout << "usage: " << exe << " [-v] [-d] [-p] [-b] privatekey.dat" << std::endl; return exitcode; } @@ -31,10 +31,11 @@ int main(int argc, char * argv[]) } int opt; - bool print_full = false; + bool print_dest = false; + bool print_private = false; bool print_blinded = false; bool verbose = false; - while((opt = getopt(argc, argv, "hvdb")) != -1) { + while((opt = getopt(argc, argv, "hvdpb")) != -1) { switch(opt){ case 'h': return printHelp(argv[0], 0); @@ -42,7 +43,10 @@ int main(int argc, char * argv[]) verbose = true; break; case 'd': - print_full = true; + print_dest = true; + break; + case 'p': + print_private = true; break; case 'b': print_blinded = true; @@ -54,23 +58,22 @@ int main(int argc, char * argv[]) std::string fname(argv[optind]); i2p::data::PrivateKeys keys; - { - std::vector buff; - std::ifstream inf; - inf.open(fname); - if (!inf.is_open()) { - std::cout << "cannot open private key file " << fname << std::endl; - return 2; - } - inf.seekg(0, std::ios::end); - const std::size_t len = inf.tellg(); - inf.seekg(0, std::ios::beg); - buff.resize(len); - inf.read((char*)buff.data(), buff.size()); - if (!keys.FromBuffer(buff.data(), buff.size())) { - std::cout << "bad key file format" << std::endl; - return 3; - } + std::ifstream s(fname, std::ifstream::binary); + + if (!s.is_open()) { + std::cout << "cannot open private key file " << fname << std::endl; + return 2; + } + + s.seekg(0, std::ios::end); + size_t len = s.tellg(); + s.seekg(0, std::ios::beg); + uint8_t * buf = new uint8_t[len]; + s.read((char*)buf, len); + + if (!keys.FromBuffer(buf, len)) { + std::cout << "bad key file format" << std::endl; + return 3; } auto dest = keys.GetPublic(); @@ -94,7 +97,9 @@ int main(int argc, char * argv[]) std::cout << "Transient Signature Type: " << SigTypeToName(bufbe16toh(offlineSignature.data () + 4)) << std::endl; } } else { - if(print_full) { + if(print_private) { + std::cout << keys.ToBase64() << std::endl; + } else if(print_dest) { std::cout << dest->ToBase64() << std::endl; } else { std::cout << ident.ToBase32() << ".b32.i2p" << std::endl; @@ -112,4 +117,7 @@ int main(int argc, char * argv[]) else std::cout << "Invalid signature type " << SigTypeToName (dest->GetSigningKeyType ()) << std::endl; } + + i2p::crypto::TerminateCrypto (); + return 0; } diff --git a/regaddr.cpp b/regaddr.cpp index 9890830..5f16c01 100644 --- a/regaddr.cpp +++ b/regaddr.cpp @@ -16,6 +16,7 @@ int main (int argc, char * argv[]) i2p::data::PrivateKeys keys; std::ifstream s(argv[1], std::ifstream::binary); + if (s.is_open ()) { s.seekg (0, std::ios::end); @@ -23,6 +24,7 @@ int main (int argc, char * argv[]) s.seekg (0, std::ios::beg); uint8_t * buf = new uint8_t[len]; s.read ((char *)buf, len); + if(keys.FromBuffer (buf, len)) { auto signatureLen = keys.GetPublic ()->GetSignatureLen (); @@ -41,10 +43,10 @@ int main (int argc, char * argv[]) } else std::cout << "Failed to load keyfile " << argv[1] << std::endl; + delete[] buf; } i2p::crypto::TerminateCrypto (); - return 0; } From 14d4a902b0d43158cfdb385618539e4a688eda74 Mon Sep 17 00:00:00 2001 From: acetone Date: Fri, 26 May 2023 09:27:39 +0300 Subject: [PATCH 17/45] vanity generator optimization --- vanity.hpp | 69 -------------- vanitygen.cpp | 242 +++++++++++++++++++++++++++++--------------------- 2 files changed, 142 insertions(+), 169 deletions(-) delete mode 100644 vanity.hpp diff --git a/vanity.hpp b/vanity.hpp deleted file mode 100644 index 4c46d3a..0000000 --- a/vanity.hpp +++ /dev/null @@ -1,69 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include "Crypto.h" -#include "Identity.h" -#include "I2PEndian.h" -#include "common/key.hpp" -#include -#include -#include - -#ifdef _WIN32 -#include -#endif - -// sha256 -#define Ch(x, y, z) ((x & (y ^ z)) ^ z) -#define Maj(x, y, z) ((x & (y | z)) | (y & z)) -#define SHR(x, n) (x >> n) -#define ROTR(x, n) ((x >> n) | (x << (32 - n))) -#define S0(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22)) -#define S1(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25)) -#define s0(x) (ROTR(x, 7) ^ ROTR(x, 18) ^ SHR(x, 3)) -#define s1(x) (ROTR(x, 17) ^ ROTR(x, 19) ^ SHR(x, 10)) - -#define RND(a, b, c, d, e, f, g, h, k) \ - t0 = h + S1(e) + Ch(e, f, g) + k; \ - t1 = S0(a) + Maj(a, b, c); \ - d += t0; \ - h = t0 + t1; - -#define RNDr(S, W, i, k) \ - RND(S[(64 - i) % 8], S[(65 - i) % 8], \ - S[(66 - i) % 8], S[(67 - i) % 8], \ - S[(68 - i) % 8], S[(69 - i) % 8], \ - S[(70 - i) % 8], S[(71 - i) % 8], \ - W[i] + k) - -#define DEF_OUTNAME "private.dat" - - -//static i2p::data::SigningKeyType type; -//static i2p::data::PrivateKeys keys; -static bool found=false; - -static size_t MutateByte; - -static uint32_t FoundNonce=0; - -static uint8_t * KeyBuf; - -//static uint8_t * PaddingBuf; -static unsigned long long hashescounter; -unsigned int count_cpu; - -const uint8_t lastBlock[64] = -{ - 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, 0x0C, 0x38 // 3128 bits (391 bytes) -}; - diff --git a/vanitygen.cpp b/vanitygen.cpp index 1ea3f31..13b3303 100644 --- a/vanitygen.cpp +++ b/vanitygen.cpp @@ -1,15 +1,72 @@ -#include "vanity.hpp" +#include "Crypto.h" +#include "Identity.h" +#include "I2PEndian.h" +#include "common/key.hpp" + #include #include #include +#include +#include +#include +#include +#include +#include +#include +#ifdef _WIN32 +#include +#endif + +// sha256 +#define Ch(x, y, z) ((x & (y ^ z)) ^ z) +#define Maj(x, y, z) ((x & (y | z)) | (y & z)) +#define SHR(x, n) (x >> n) +#define ROTR(x, n) ((x >> n) | (x << (32 - n))) +#define S0(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22)) +#define S1(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25)) +#define s0(x) (ROTR(x, 7) ^ ROTR(x, 18) ^ SHR(x, 3)) +#define s1(x) (ROTR(x, 17) ^ ROTR(x, 19) ^ SHR(x, 10)) + +#define RND(a, b, c, d, e, f, g, h, k) \ + t0 = h + S1(e) + Ch(e, f, g) + k; \ + t1 = S0(a) + Maj(a, b, c); \ + d += t0; \ + h = t0 + t1; + +#define RNDr(S, W, i, k) \ + RND(S[(64 - i) % 8], S[(65 - i) % 8], \ + S[(66 - i) % 8], S[(67 - i) % 8], \ + S[(68 - i) % 8], S[(69 - i) % 8], \ + S[(70 - i) % 8], S[(71 - i) % 8], \ + W[i] + k) + +#define DEF_OUTNAME "private.dat" + +static bool found = false; +static size_t MutateByte; +static uint8_t * KeyBuf; + +unsigned int count_cpu; + +const uint8_t lastBlock[64] = +{ + 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, 0x0C, 0x38 // 3128 bits (391 bytes) +}; static struct { - bool reg=false; - int threads=-1; + bool reg = false; + int threads = -1; i2p::data::SigningKeyType signature; - std::string outputpath=""; + std::string outputpath = ""; std::regex regex; bool sig_type = true; } options; @@ -23,7 +80,7 @@ void check_sig_type() } } -static void inline CalculateW (const uint8_t block[64], uint32_t W[64]) +void inline CalculateW (const uint8_t block[64], uint32_t W[64]) { /** * implementation of orignal @@ -39,7 +96,7 @@ static void inline CalculateW (const uint8_t block[64], uint32_t W[64]) W[i] = s1(W[i - 2]) + W[i - 7] + s0(W[i - 15]) + W[i - 16]; } -static void inline TransformBlock (uint32_t state[8], const uint32_t W[64]) +void inline TransformBlock (uint32_t state[8], const uint32_t W[64]) { /** * implementation of orignal @@ -78,9 +135,9 @@ void inline HashNextBlock (uint32_t state[8], const uint8_t * block) TransformBlock (state, W); } -static bool check_prefix(const char * buf) +bool check_prefix(const char * buf) { - unsigned short size_str=0; + unsigned short size_str = 0; while(*buf) { if(!((*buf > 49 && *buf < 56) || (*buf > 96 && *buf < 123)) || size_str > 52) @@ -91,7 +148,7 @@ static bool check_prefix(const char * buf) return true; } -static inline size_t ByteStreamToBase32 (const uint8_t * inBuf, size_t len, char * outBuf, size_t outLen) +inline size_t ByteStreamToBase32 (const uint8_t * inBuf, size_t len, char * outBuf, size_t outLen) { size_t ret = 0, pos = 1; int bits = 8, tmp = inBuf[0]; @@ -122,11 +179,11 @@ static inline size_t ByteStreamToBase32 (const uint8_t * inBuf, size_t len, char return ret; } -static inline bool NotThat(const char * what, const std::regex & reg){ +inline bool NotThat(const char * what, const std::regex & reg){ return std::regex_match(what,reg) == 1 ? false : true; } -static inline bool NotThat(const char * a, const char *b) +inline bool NotThat(const char * a, const char *b) { while(*b) if(*a++!=*b++) @@ -134,29 +191,53 @@ static inline bool NotThat(const char * a, const char *b) return false; } -std::mutex mtx; -static inline bool thread_find(uint8_t * buf, const char * prefix, int id_thread, unsigned long long throughput) +void processFlipper(const std::string string) { -/** - * Thanks to orignal ^-^ - * For idea and example ^-^ - * Orignal is sensei of crypto ;) - */ - mtx.lock(); - std::cout << "[+] thread " << id_thread << " bound" << std::endl; - mtx.unlock(); -/* - union - { - uint8_t b[391]; - uint32_t ll; - } local; - union - { - uint8_t b[32]; - uint32_t ll[8]; - } hash; -*/ + constexpr char SYMBOLS[] {'-', '\\', '|', '/'}; + uint8_t symbol_counter = 0; + std::string payload = string; + if (payload.back() != ' ') payload += ' '; + + size_t current_state = payload.size(); + enum { left, right } direction = left; + + std::cout << payload << SYMBOLS[symbol_counter++]; + while (!found) + { + std::cout << '\b' << SYMBOLS[symbol_counter++]; + std::cout.flush(); + + if (symbol_counter == sizeof(SYMBOLS)) + { + if (direction == left) + { + std::cout << '\b'; + std::cout.flush(); + symbol_counter = 0; + if (!--current_state) + { + direction = right; + } + } + else if (direction == right) + { + std::cout << '\b' << payload[current_state] << " "; + std::cout.flush(); + symbol_counter = 0; + + if (++current_state == payload.size()) + { + direction = left; + } + } + } + std::this_thread::sleep_for(std::chrono::milliseconds(80)); + } +} + +bool thread_find(uint8_t * buf, const char * prefix, int id_thread, unsigned long long throughput) +{ + const unsigned long long original_throughput = throughput; uint8_t b[391]; uint32_t hash[8]; @@ -185,8 +266,13 @@ static inline bool thread_find(uint8_t * buf, const char * prefix, int id_thread char addr[53]; uint32_t state1[8]; - while(throughput-- and !found) + while(!found) { + if (! throughput--) + { + throughput = original_throughput; + } + memcpy (state1, state, 32); // calculate hash of block with nonce HashNextBlock (state1, b + 320); @@ -196,32 +282,22 @@ static inline bool thread_find(uint8_t * buf, const char * prefix, int id_thread for (int j = 8; j--;) hash[j] = htobe32(state1[j]); ByteStreamToBase32 ((uint8_t*)hash, 32, addr, len); - // std::cout << addr << std::endl; - // bool result = options.reg ? !NotThat(addr, &options.regex) : !NotThat(addr,prefix); - - if( ( options.reg ? !NotThat(addr, options.regex) : !NotThat(addr,prefix) ) ) - // if(result) + if( options.reg ? !NotThat(addr, options.regex) : !NotThat(addr, prefix) ) { ByteStreamToBase32 ((uint8_t*)hash, 32, addr, 52); std::cout << "\nFound address: " << addr << std::endl; - found=true; - FoundNonce=*nonce; - // free(hash); - // free(b); + found = true; return true; } - (*nonce)++; - hashescounter++; if (found) { - // free(hash); - // free(b); break; } - } // while + } + return true; } @@ -292,6 +368,7 @@ int main (int argc, char * argv[]) usage(); return 0; } + parsing( argc > 2 ? argc-1 : argc, argc > 2 ? argv+1 : argv); // if(!options.reg && !check_prefix( argv[1] )) @@ -301,25 +378,17 @@ int main (int argc, char * argv[]) return 1; }else{ 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; -// } } i2p::crypto::InitCrypto (false, true, true, false); options.signature = i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519; -/////////////// -//For while + if(options.signature != i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519) { std::cout << "ED25519-SHA512 are currently the only signing keys supported." << std::endl; return 0; } -/////////////// -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// if (!options.sig_type) return -2; auto keys = i2p::data::PrivateKeys::CreateRandomKeys (options.signature); switch(options.signature) @@ -362,55 +431,28 @@ int main (int argc, char * argv[]) if(options.threads <= 0) { -#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 + options.threads = std::thread::hardware_concurrency(); } + + std::cout << "Vanity generator started in " << options.threads << " threads" << std::endl; - std::cout << "Initializing vanity generator (" << options.threads << " threads)\n" << std::endl; + std::vector threads(options.threads); + unsigned long long thoughtput = 0x4F4B5A37; - unsigned short attempts = 0; - while(!found) - { // while - { // stack(for destructors(vector/thread)) + for (unsigned int j = options.threads; j--; ) + { + threads[j] = std::thread(thread_find, KeyBuf, argv[1], j, thoughtput); + thoughtput += 1000; + } - std::vector threads(options.threads); - unsigned long long thoughtput = 0x4F4B5A37; + processFlipper(argv[1]); + + for (unsigned int j = 0; j < (unsigned int)options.threads;j++) + threads[j].join(); - std::cout << "Starting attempt #" << ++attempts << ":" << std::endl; - for (unsigned int j = options.threads;j--;) - { - threads[j] = std::thread(thread_find,KeyBuf,argv[1],j,thoughtput); - thoughtput+=1000; - } // for + if(options.outputpath.empty()) options.outputpath.assign(DEF_OUTNAME); - for (unsigned int j = 0; j < (unsigned int)options.threads;j++) - threads[j].join(); - - if (FoundNonce == 0) - { - RAND_bytes( KeyBuf+MutateByte , 90 ); - } - - } // stack - } // while - - memcpy (KeyBuf + MutateByte, &FoundNonce, 4); - std::cout << "Hashes calculated: " << hashescounter << std::endl; - - if(options.outputpath.size() == 0) options.outputpath.assign(DEF_OUTNAME); - - std::ofstream f (options.outputpath, std::ofstream::binary | std::ofstream::out); + std::ofstream f (options.outputpath, std::ofstream::binary); if (f) { f.write ((char *)KeyBuf, keys.GetFullLen ()); From fe84f6a996caf3a6bd4bf01df0fcef32ecf4fec3 Mon Sep 17 00:00:00 2001 From: acetone Date: Fri, 26 May 2023 09:37:02 +0300 Subject: [PATCH 18/45] tabs formatting --- vanitygen.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/vanitygen.cpp b/vanitygen.cpp index 13b3303..dc3beb2 100644 --- a/vanitygen.cpp +++ b/vanitygen.cpp @@ -268,10 +268,10 @@ bool thread_find(uint8_t * buf, const char * prefix, int id_thread, unsigned lon while(!found) { - if (! throughput--) - { - throughput = original_throughput; - } + if (! throughput--) + { + throughput = original_throughput; + } memcpy (state1, state, 32); // calculate hash of block with nonce @@ -431,24 +431,24 @@ int main (int argc, char * argv[]) if(options.threads <= 0) { - options.threads = std::thread::hardware_concurrency(); + options.threads = std::thread::hardware_concurrency(); } std::cout << "Vanity generator started in " << options.threads << " threads" << std::endl; - std::vector threads(options.threads); - unsigned long long thoughtput = 0x4F4B5A37; + std::vector threads(options.threads); + unsigned long long thoughtput = 0x4F4B5A37; - for (unsigned int j = options.threads; j--; ) - { - threads[j] = std::thread(thread_find, KeyBuf, argv[1], j, thoughtput); - thoughtput += 1000; - } + for (unsigned int j = options.threads; j--; ) + { + threads[j] = std::thread(thread_find, KeyBuf, argv[1], j, thoughtput); + thoughtput += 1000; + } - processFlipper(argv[1]); + processFlipper(argv[1]); - for (unsigned int j = 0; j < (unsigned int)options.threads;j++) - threads[j].join(); + for (unsigned int j = 0; j < (unsigned int)options.threads;j++) + threads[j].join(); if(options.outputpath.empty()) options.outputpath.assign(DEF_OUTNAME); From 74173a26b117dce6ac56caebcf106d72d299180b Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 30 Jun 2023 11:25:57 -0400 Subject: [PATCH 19/45] removed vain --- Makefile | 7 +- README.md | 8 - vanitygen.cpp | 467 -------------------------------------------------- 3 files changed, 2 insertions(+), 480 deletions(-) delete mode 100644 vanitygen.cpp diff --git a/Makefile b/Makefile index f0a251c..3c38c46 100644 --- a/Makefile +++ b/Makefile @@ -43,7 +43,7 @@ else LDFLAGS += -s -static endif -all: $(I2PD_LIB) keygen keyinfo famtool routerinfo regaddr regaddr_3ld vain i2pbase64 offlinekeys b33address regaddralias x25519 verifyhost +all: $(I2PD_LIB) keygen keyinfo famtool routerinfo regaddr regaddr_3ld i2pbase64 offlinekeys b33address regaddralias x25519 verifyhost routerinfo: routerinfo.o $(I2PD_LIB) $(CXX) -o routerinfo $(LDFLAGS) routerinfo.o $(LDLIBS) @@ -63,9 +63,6 @@ regaddr: regaddr.o $(I2PD_LIB) regaddr_3ld: regaddr_3ld.o $(I2PD_LIB) $(CXX) -o regaddr_3ld $(DEFINES) $(LDFLAGS) regaddr_3ld.o $(LDLIBS) -vain: vanitygen.o $(I2PD_LIB) - $(CXX) -o vain $(DEFINES) $(LDFLAGS) vanitygen.o $(LDLIBS) - i2pbase64: i2pbase64.o $(I2PD_LIB) $(CXX) -o i2pbase64 $(DEFINES) $(LDFLAGS) i2pbase64.o $(LDLIBS) @@ -103,7 +100,7 @@ clean-obj: rm -f $(wildcard *.o) clean-bin: - rm -f b33address famtool i2pbase64 keygen keyinfo offlinekeys regaddr regaddr_3ld regaddralias routerinfo vain x25519 verifyhost + rm -f b33address famtool i2pbase64 keygen keyinfo offlinekeys regaddr regaddr_3ld regaddralias routerinfo x25519 verifyhost clean: clean-i2pd clean-obj clean-bin diff --git a/README.md b/README.md index 3a55aa1..51dc29e 100755 --- a/README.md +++ b/README.md @@ -80,14 +80,6 @@ or For more information on the types of signatures, see the [documentation](https://i2pd.readthedocs.io/en/latest/user-guide/tunnels/#signature-types). -### vain - -Vanity generation address. - -#### Usage - -./vain --usage - #### Time to Generate on a 2.70GHz Processor | characters| time to generate (approx.) | | -------------------- | --------------- | diff --git a/vanitygen.cpp b/vanitygen.cpp deleted file mode 100644 index dc3beb2..0000000 --- a/vanitygen.cpp +++ /dev/null @@ -1,467 +0,0 @@ -#include "Crypto.h" -#include "Identity.h" -#include "I2PEndian.h" -#include "common/key.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef _WIN32 -#include -#endif - -// sha256 -#define Ch(x, y, z) ((x & (y ^ z)) ^ z) -#define Maj(x, y, z) ((x & (y | z)) | (y & z)) -#define SHR(x, n) (x >> n) -#define ROTR(x, n) ((x >> n) | (x << (32 - n))) -#define S0(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22)) -#define S1(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25)) -#define s0(x) (ROTR(x, 7) ^ ROTR(x, 18) ^ SHR(x, 3)) -#define s1(x) (ROTR(x, 17) ^ ROTR(x, 19) ^ SHR(x, 10)) - -#define RND(a, b, c, d, e, f, g, h, k) \ - t0 = h + S1(e) + Ch(e, f, g) + k; \ - t1 = S0(a) + Maj(a, b, c); \ - d += t0; \ - h = t0 + t1; - -#define RNDr(S, W, i, k) \ - RND(S[(64 - i) % 8], S[(65 - i) % 8], \ - S[(66 - i) % 8], S[(67 - i) % 8], \ - S[(68 - i) % 8], S[(69 - i) % 8], \ - S[(70 - i) % 8], S[(71 - i) % 8], \ - W[i] + k) - -#define DEF_OUTNAME "private.dat" - -static bool found = false; -static size_t MutateByte; -static uint8_t * KeyBuf; - -unsigned int count_cpu; - -const uint8_t lastBlock[64] = -{ - 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, 0x0C, 0x38 // 3128 bits (391 bytes) -}; - -static struct -{ - bool reg = false; - int threads = -1; - i2p::data::SigningKeyType signature; - std::string outputpath = ""; - std::regex regex; - bool sig_type = true; -} options; - -void check_sig_type() -{ - if (SigTypeToName(options.signature).find("unknown") != std::string::npos) - { - std::cerr << "Incorrect signature type" << std::endl; - options.sig_type = false; - } -} - -void inline CalculateW (const uint8_t block[64], uint32_t W[64]) -{ -/** - * implementation of orignal - */ - for (int i = 0; i < 16; i++) -#ifdef _WIN32 - W[i] = htobe32(((uint32_t *)(block))[i]); -#else // from big endian to little endian ( swap ) - W[i] = be32toh(((uint32_t *)(block))[i]); -#endif - - for (int i = 16; i < 64; i++) - W[i] = s1(W[i - 2]) + W[i - 7] + s0(W[i - 15]) + W[i - 16]; -} - -void inline TransformBlock (uint32_t state[8], const uint32_t W[64]) -{ -/** - * implementation of orignal - */ - uint32_t S[8]; - memcpy(S, state, 32); - - uint32_t t0, t1; - RNDr(S, W, 0, 0x428a2f98); RNDr(S, W, 1, 0x71374491); RNDr(S, W, 2, 0xb5c0fbcf); RNDr(S, W, 3, 0xe9b5dba5); - RNDr(S, W, 4, 0x3956c25b); RNDr(S, W, 5, 0x59f111f1); RNDr(S, W, 6, 0x923f82a4); RNDr(S, W, 7, 0xab1c5ed5); - RNDr(S, W, 8, 0xd807aa98); RNDr(S, W, 9, 0x12835b01); RNDr(S, W, 10, 0x243185be); RNDr(S, W, 11, 0x550c7dc3); - RNDr(S, W, 12, 0x72be5d74); RNDr(S, W, 13, 0x80deb1fe); RNDr(S, W, 14, 0x9bdc06a7); RNDr(S, W, 15, 0xc19bf174); - RNDr(S, W, 16, 0xe49b69c1); RNDr(S, W, 17, 0xefbe4786); RNDr(S, W, 18, 0x0fc19dc6); RNDr(S, W, 19, 0x240ca1cc); - RNDr(S, W, 20, 0x2de92c6f); RNDr(S, W, 21, 0x4a7484aa); RNDr(S, W, 22, 0x5cb0a9dc); RNDr(S, W, 23, 0x76f988da); - RNDr(S, W, 24, 0x983e5152); RNDr(S, W, 25, 0xa831c66d); RNDr(S, W, 26, 0xb00327c8); RNDr(S, W, 27, 0xbf597fc7); - RNDr(S, W, 28, 0xc6e00bf3); RNDr(S, W, 29, 0xd5a79147); RNDr(S, W, 30, 0x06ca6351); RNDr(S, W, 31, 0x14292967); - RNDr(S, W, 32, 0x27b70a85); RNDr(S, W, 33, 0x2e1b2138); RNDr(S, W, 34, 0x4d2c6dfc); RNDr(S, W, 35, 0x53380d13); - RNDr(S, W, 36, 0x650a7354); RNDr(S, W, 37, 0x766a0abb); RNDr(S, W, 38, 0x81c2c92e); RNDr(S, W, 39, 0x92722c85); - RNDr(S, W, 40, 0xa2bfe8a1); RNDr(S, W, 41, 0xa81a664b); RNDr(S, W, 42, 0xc24b8b70); RNDr(S, W, 43, 0xc76c51a3); - RNDr(S, W, 44, 0xd192e819); RNDr(S, W, 45, 0xd6990624); RNDr(S, W, 46, 0xf40e3585); RNDr(S, W, 47, 0x106aa070); - RNDr(S, W, 48, 0x19a4c116); RNDr(S, W, 49, 0x1e376c08); RNDr(S, W, 50, 0x2748774c); RNDr(S, W, 51, 0x34b0bcb5); - RNDr(S, W, 52, 0x391c0cb3); RNDr(S, W, 53, 0x4ed8aa4a); RNDr(S, W, 54, 0x5b9cca4f); RNDr(S, W, 55, 0x682e6ff3); - RNDr(S, W, 56, 0x748f82ee); RNDr(S, W, 57, 0x78a5636f); RNDr(S, W, 58, 0x84c87814); RNDr(S, W, 59, 0x8cc70208); - RNDr(S, W, 60, 0x90befffa); RNDr(S, W, 61, 0xa4506ceb); RNDr(S, W, 62, 0xbef9a3f7); RNDr(S, W, 63, 0xc67178f2); - - for (int i = 0; i < 8; i++) state[i] += S[i]; -} - -void inline HashNextBlock (uint32_t state[8], const uint8_t * block) -{ -/** - * implementation of orignal - */ - uint32_t W[64]; - CalculateW (block, W); - TransformBlock (state, W); -} - -bool check_prefix(const char * buf) -{ - unsigned short size_str = 0; - while(*buf) - { - if(!((*buf > 49 && *buf < 56) || (*buf > 96 && *buf < 123)) || size_str > 52) - return false; - size_str++; - buf++; - } - return true; -} - -inline size_t ByteStreamToBase32 (const uint8_t * inBuf, size_t len, char * outBuf, size_t outLen) -{ - size_t ret = 0, pos = 1; - int bits = 8, tmp = inBuf[0]; - while (ret < outLen && (bits > 0 || pos < len)) - { - if (bits < 5) - { - if (pos < len) - { - tmp <<= 8; - tmp |= inBuf[pos] & 0xFF; - pos++; - bits += 8; - } - else // last byte - { - tmp <<= (5 - bits); - bits = 5; - } - } - - bits -= 5; - int ind = (tmp >> bits) & 0x1F; - outBuf[ret] = (ind < 26) ? (ind + 'a') : ((ind - 26) + '2'); - ret++; - } - outBuf[ret]='\0'; - return ret; -} - -inline bool NotThat(const char * what, const std::regex & reg){ - return std::regex_match(what,reg) == 1 ? false : true; -} - -inline bool NotThat(const char * a, const char *b) -{ - while(*b) - if(*a++!=*b++) - return true; - return false; -} - -void processFlipper(const std::string string) -{ - constexpr char SYMBOLS[] {'-', '\\', '|', '/'}; - uint8_t symbol_counter = 0; - std::string payload = string; - if (payload.back() != ' ') payload += ' '; - - size_t current_state = payload.size(); - enum { left, right } direction = left; - - std::cout << payload << SYMBOLS[symbol_counter++]; - while (!found) - { - std::cout << '\b' << SYMBOLS[symbol_counter++]; - std::cout.flush(); - - if (symbol_counter == sizeof(SYMBOLS)) - { - if (direction == left) - { - std::cout << '\b'; - std::cout.flush(); - symbol_counter = 0; - if (!--current_state) - { - direction = right; - } - } - else if (direction == right) - { - std::cout << '\b' << payload[current_state] << " "; - std::cout.flush(); - symbol_counter = 0; - - if (++current_state == payload.size()) - { - direction = left; - } - } - } - std::this_thread::sleep_for(std::chrono::milliseconds(80)); - } -} - -bool thread_find(uint8_t * buf, const char * prefix, int id_thread, unsigned long long throughput) -{ - const unsigned long long original_throughput = throughput; - uint8_t b[391]; - uint32_t hash[8]; - - memcpy (b, buf, 391); - - size_t len = 52; - - if (!options.reg) - len = strlen(prefix); - - // precalculate first 5 blocks (320 bytes) - uint32_t state[8] = { 0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19 }; - HashNextBlock (state, b); - HashNextBlock (state, b + 64); - HashNextBlock (state, b + 128); - HashNextBlock (state, b + 192); - HashNextBlock (state, b + 256); - - // pre-calculate last W - uint32_t lastW[64]; - CalculateW (lastBlock, lastW); - - uint32_t * nonce = (uint32_t *)(b+320); - (*nonce) += id_thread*throughput; - - char addr[53]; - uint32_t state1[8]; - - while(!found) - { - if (! throughput--) - { - throughput = original_throughput; - } - - memcpy (state1, state, 32); - // calculate hash of block with nonce - HashNextBlock (state1, b + 320); - // apply last block - TransformBlock (state1, lastW); - // get final hash - for (int j = 8; j--;) - hash[j] = htobe32(state1[j]); - ByteStreamToBase32 ((uint8_t*)hash, 32, addr, len); - - if( options.reg ? !NotThat(addr, options.regex) : !NotThat(addr, prefix) ) - { - ByteStreamToBase32 ((uint8_t*)hash, 32, addr, 52); - std::cout << "\nFound address: " << addr << std::endl; - found = true; - return true; - } - - (*nonce)++; - if (found) - { - break; - } - } - - return true; -} - -void usage(void){ - const constexpr char * help="Usage:\n" - " vain [text-pattern|regex-pattern] [options]\n\n" - "OPTIONS:\n" - " -h --help show this help (same as --usage)\n" - " -r --reg use regexp instead of simple text pattern, ex.: vain '(one|two).*' -r\n" - " -t --threads number of threads to use (default: one per processor)\n" -// " -s --signature (signature type)\n" // NOT IMPLEMENTED FUCKING PLAZ! - " -o --output privkey output file name (default: ./" DEF_OUTNAME ")\n" - ""; - puts(help); -} - -void parsing(int argc, char ** args){ - 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") ){ - usage(); - exit(1); - } - case 'h': - usage(); - exit(0); - break; - case 'r': - options.reg=true; - break; - case 't': - options.threads=atoi(optarg); - break; - case 's': - options.signature = NameToSigType(std::string(optarg)); - check_sig_type(); - 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[]) -{ - if ( argc < 2 ) - { - usage(); - return 0; - } - - parsing( argc > 2 ? argc-1 : argc, argc > 2 ? argv+1 : argv); - // - if(!options.reg && !check_prefix( argv[1] )) - { - std::cout << "Invalid pattern." << std::endl; - usage(); - return 1; - }else{ - options.regex=std::regex(argv[1]); - } - - i2p::crypto::InitCrypto (false, true, true, false); - options.signature = i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519; - - if(options.signature != i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519) - { - std::cout << "ED25519-SHA512 are currently the only signing keys supported." << std::endl; - return 0; - } - - if (!options.sig_type) return -2; - auto keys = i2p::data::PrivateKeys::CreateRandomKeys (options.signature); - switch(options.signature) - { - case i2p::data::SIGNING_KEY_TYPE_DSA_SHA1: - case i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA512_P521: - case i2p::data::SIGNING_KEY_TYPE_RSA_SHA256_2048: - case i2p::data::SIGNING_KEY_TYPE_RSA_SHA384_3072: - case i2p::data::SIGNING_KEY_TYPE_RSA_SHA512_4096: - case i2p::data::SIGNING_KEY_TYPE_GOSTR3410_TC26_A_512_GOSTR3411_512: - std::cout << "Sorry, selected signature type is not supported for address generation." << std::endl; - return 0; - break; - } - -//TODO: for other types. - switch(options.signature) - { - case i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA256_P256: - break; - case i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA384_P384: - break; - case i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA512_P521: - break; - case i2p::data::SIGNING_KEY_TYPE_RSA_SHA256_2048: - break; - case i2p::data::SIGNING_KEY_TYPE_RSA_SHA384_3072: - break; - case i2p::data::SIGNING_KEY_TYPE_RSA_SHA512_4096: - break; - case i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519: - MutateByte=320; - break; - case i2p::data::SIGNING_KEY_TYPE_GOSTR3410_CRYPTO_PRO_A_GOSTR3411_256: - break; - } - - KeyBuf = new uint8_t[keys.GetFullLen()]; - keys.ToBuffer (KeyBuf, keys.GetFullLen ()); - - if(options.threads <= 0) - { - options.threads = std::thread::hardware_concurrency(); - } - - std::cout << "Vanity generator started in " << options.threads << " threads" << std::endl; - - std::vector threads(options.threads); - unsigned long long thoughtput = 0x4F4B5A37; - - for (unsigned int j = options.threads; j--; ) - { - threads[j] = std::thread(thread_find, KeyBuf, argv[1], j, thoughtput); - thoughtput += 1000; - } - - processFlipper(argv[1]); - - for (unsigned int j = 0; j < (unsigned int)options.threads;j++) - threads[j].join(); - - if(options.outputpath.empty()) options.outputpath.assign(DEF_OUTNAME); - - std::ofstream f (options.outputpath, std::ofstream::binary); - if (f) - { - f.write ((char *)KeyBuf, keys.GetFullLen ()); - delete [] KeyBuf; - } - else - std::cout << "Can't create output file: " << options.outputpath << std::endl; - - i2p::crypto::TerminateCrypto (); - - return 0; -} From 114fd1cfe701425c8b5f363e06a790981901eb40 Mon Sep 17 00:00:00 2001 From: wipedlifepotato Date: Mon, 31 Jul 2023 22:18:34 +0700 Subject: [PATCH 20/45] LSB Release instead uname if we can --- dependencies.sh | 59 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 9 deletions(-) diff --git a/dependencies.sh b/dependencies.sh index 2b2b7d6..d44f3dd 100755 --- a/dependencies.sh +++ b/dependencies.sh @@ -14,14 +14,55 @@ dependWin="mingw-w64-x86_64-boost \ mingw-w64-x86_64-zlib" kernel=`uname -a` +function isLsbReleaseExists() { + if which lsb_release > /dev/null; # do whereis can be too? + then + return 0 + else + return 1 + fi +} -case "$kernel" in -*Ubuntu*|*Debian*) - sudo apt install $dependNix;; -*gentoo*) - sudo emerge --deep --newuse dev-libs/boost dev-libs/openssl;; -*MINGW64*) - pacman -S $dependWin;; -*) - echo "Just install libboost and libopenssl dev packages on your pc";; +function anotherDistr(){ + echo "Just install libboost and libopenssl dev packages on your pc"; + return 0 +} + +function installDeb(){ + sudo apt-get install $dependNix; + return 0 +} +function installOnGentoo(){ + sudo emerge --deep --newuse dev-libs/boost dev-libs/openssl; + return 0 +} +function installOnWin() { + pacman -S $depenWin; + return 0 +} + +function doInstallDepencies() { +case "$1" in + *Ubuntu*|*Debian*) + installDeb + ;; + *gentoo*) + installOnGentoo + ;; + *MINGW64*) + installOnWin + ;; + *) + anotherDistr + ;; esac +} + +if isLsbReleaseExists ; +then + distr=`lsb_release -i` + doInstallDepencies "$distr" +else # + doInstallDepencies "$kernel" +fi + From 32b01c2e7be4e74278bfb747605d110aa4cdaf44 Mon Sep 17 00:00:00 2001 From: wipedlifepotato Date: Mon, 31 Jul 2023 23:27:01 +0700 Subject: [PATCH 21/45] undo old vain version + pre init macros for InitCrypto --- .../vanitygen.cpp | 467 ++++++++++++++++++ todelete/old_vanity/vain.cpp | 417 ++++++++++++++++ todelete/old_vanity/vanity.hpp | 66 +++ vain.cpp | 432 ++++++++++++++++ vanity.hpp | 66 +++ 5 files changed, 1448 insertions(+) create mode 100755 todelete/new_vanity_last_version_from_github/vanitygen.cpp create mode 100755 todelete/old_vanity/vain.cpp create mode 100755 todelete/old_vanity/vanity.hpp create mode 100755 vain.cpp create mode 100755 vanity.hpp diff --git a/todelete/new_vanity_last_version_from_github/vanitygen.cpp b/todelete/new_vanity_last_version_from_github/vanitygen.cpp new file mode 100755 index 0000000..13b3303 --- /dev/null +++ b/todelete/new_vanity_last_version_from_github/vanitygen.cpp @@ -0,0 +1,467 @@ +#include "Crypto.h" +#include "Identity.h" +#include "I2PEndian.h" +#include "common/key.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef _WIN32 +#include +#endif + +// sha256 +#define Ch(x, y, z) ((x & (y ^ z)) ^ z) +#define Maj(x, y, z) ((x & (y | z)) | (y & z)) +#define SHR(x, n) (x >> n) +#define ROTR(x, n) ((x >> n) | (x << (32 - n))) +#define S0(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22)) +#define S1(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25)) +#define s0(x) (ROTR(x, 7) ^ ROTR(x, 18) ^ SHR(x, 3)) +#define s1(x) (ROTR(x, 17) ^ ROTR(x, 19) ^ SHR(x, 10)) + +#define RND(a, b, c, d, e, f, g, h, k) \ + t0 = h + S1(e) + Ch(e, f, g) + k; \ + t1 = S0(a) + Maj(a, b, c); \ + d += t0; \ + h = t0 + t1; + +#define RNDr(S, W, i, k) \ + RND(S[(64 - i) % 8], S[(65 - i) % 8], \ + S[(66 - i) % 8], S[(67 - i) % 8], \ + S[(68 - i) % 8], S[(69 - i) % 8], \ + S[(70 - i) % 8], S[(71 - i) % 8], \ + W[i] + k) + +#define DEF_OUTNAME "private.dat" + +static bool found = false; +static size_t MutateByte; +static uint8_t * KeyBuf; + +unsigned int count_cpu; + +const uint8_t lastBlock[64] = +{ + 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, 0x0C, 0x38 // 3128 bits (391 bytes) +}; + +static struct +{ + bool reg = false; + int threads = -1; + i2p::data::SigningKeyType signature; + std::string outputpath = ""; + std::regex regex; + bool sig_type = true; +} options; + +void check_sig_type() +{ + if (SigTypeToName(options.signature).find("unknown") != std::string::npos) + { + std::cerr << "Incorrect signature type" << std::endl; + options.sig_type = false; + } +} + +void inline CalculateW (const uint8_t block[64], uint32_t W[64]) +{ +/** + * implementation of orignal + */ + for (int i = 0; i < 16; i++) +#ifdef _WIN32 + W[i] = htobe32(((uint32_t *)(block))[i]); +#else // from big endian to little endian ( swap ) + W[i] = be32toh(((uint32_t *)(block))[i]); +#endif + + for (int i = 16; i < 64; i++) + W[i] = s1(W[i - 2]) + W[i - 7] + s0(W[i - 15]) + W[i - 16]; +} + +void inline TransformBlock (uint32_t state[8], const uint32_t W[64]) +{ +/** + * implementation of orignal + */ + uint32_t S[8]; + memcpy(S, state, 32); + + uint32_t t0, t1; + RNDr(S, W, 0, 0x428a2f98); RNDr(S, W, 1, 0x71374491); RNDr(S, W, 2, 0xb5c0fbcf); RNDr(S, W, 3, 0xe9b5dba5); + RNDr(S, W, 4, 0x3956c25b); RNDr(S, W, 5, 0x59f111f1); RNDr(S, W, 6, 0x923f82a4); RNDr(S, W, 7, 0xab1c5ed5); + RNDr(S, W, 8, 0xd807aa98); RNDr(S, W, 9, 0x12835b01); RNDr(S, W, 10, 0x243185be); RNDr(S, W, 11, 0x550c7dc3); + RNDr(S, W, 12, 0x72be5d74); RNDr(S, W, 13, 0x80deb1fe); RNDr(S, W, 14, 0x9bdc06a7); RNDr(S, W, 15, 0xc19bf174); + RNDr(S, W, 16, 0xe49b69c1); RNDr(S, W, 17, 0xefbe4786); RNDr(S, W, 18, 0x0fc19dc6); RNDr(S, W, 19, 0x240ca1cc); + RNDr(S, W, 20, 0x2de92c6f); RNDr(S, W, 21, 0x4a7484aa); RNDr(S, W, 22, 0x5cb0a9dc); RNDr(S, W, 23, 0x76f988da); + RNDr(S, W, 24, 0x983e5152); RNDr(S, W, 25, 0xa831c66d); RNDr(S, W, 26, 0xb00327c8); RNDr(S, W, 27, 0xbf597fc7); + RNDr(S, W, 28, 0xc6e00bf3); RNDr(S, W, 29, 0xd5a79147); RNDr(S, W, 30, 0x06ca6351); RNDr(S, W, 31, 0x14292967); + RNDr(S, W, 32, 0x27b70a85); RNDr(S, W, 33, 0x2e1b2138); RNDr(S, W, 34, 0x4d2c6dfc); RNDr(S, W, 35, 0x53380d13); + RNDr(S, W, 36, 0x650a7354); RNDr(S, W, 37, 0x766a0abb); RNDr(S, W, 38, 0x81c2c92e); RNDr(S, W, 39, 0x92722c85); + RNDr(S, W, 40, 0xa2bfe8a1); RNDr(S, W, 41, 0xa81a664b); RNDr(S, W, 42, 0xc24b8b70); RNDr(S, W, 43, 0xc76c51a3); + RNDr(S, W, 44, 0xd192e819); RNDr(S, W, 45, 0xd6990624); RNDr(S, W, 46, 0xf40e3585); RNDr(S, W, 47, 0x106aa070); + RNDr(S, W, 48, 0x19a4c116); RNDr(S, W, 49, 0x1e376c08); RNDr(S, W, 50, 0x2748774c); RNDr(S, W, 51, 0x34b0bcb5); + RNDr(S, W, 52, 0x391c0cb3); RNDr(S, W, 53, 0x4ed8aa4a); RNDr(S, W, 54, 0x5b9cca4f); RNDr(S, W, 55, 0x682e6ff3); + RNDr(S, W, 56, 0x748f82ee); RNDr(S, W, 57, 0x78a5636f); RNDr(S, W, 58, 0x84c87814); RNDr(S, W, 59, 0x8cc70208); + RNDr(S, W, 60, 0x90befffa); RNDr(S, W, 61, 0xa4506ceb); RNDr(S, W, 62, 0xbef9a3f7); RNDr(S, W, 63, 0xc67178f2); + + for (int i = 0; i < 8; i++) state[i] += S[i]; +} + +void inline HashNextBlock (uint32_t state[8], const uint8_t * block) +{ +/** + * implementation of orignal + */ + uint32_t W[64]; + CalculateW (block, W); + TransformBlock (state, W); +} + +bool check_prefix(const char * buf) +{ + unsigned short size_str = 0; + while(*buf) + { + if(!((*buf > 49 && *buf < 56) || (*buf > 96 && *buf < 123)) || size_str > 52) + return false; + size_str++; + buf++; + } + return true; +} + +inline size_t ByteStreamToBase32 (const uint8_t * inBuf, size_t len, char * outBuf, size_t outLen) +{ + size_t ret = 0, pos = 1; + int bits = 8, tmp = inBuf[0]; + while (ret < outLen && (bits > 0 || pos < len)) + { + if (bits < 5) + { + if (pos < len) + { + tmp <<= 8; + tmp |= inBuf[pos] & 0xFF; + pos++; + bits += 8; + } + else // last byte + { + tmp <<= (5 - bits); + bits = 5; + } + } + + bits -= 5; + int ind = (tmp >> bits) & 0x1F; + outBuf[ret] = (ind < 26) ? (ind + 'a') : ((ind - 26) + '2'); + ret++; + } + outBuf[ret]='\0'; + return ret; +} + +inline bool NotThat(const char * what, const std::regex & reg){ + return std::regex_match(what,reg) == 1 ? false : true; +} + +inline bool NotThat(const char * a, const char *b) +{ + while(*b) + if(*a++!=*b++) + return true; + return false; +} + +void processFlipper(const std::string string) +{ + constexpr char SYMBOLS[] {'-', '\\', '|', '/'}; + uint8_t symbol_counter = 0; + std::string payload = string; + if (payload.back() != ' ') payload += ' '; + + size_t current_state = payload.size(); + enum { left, right } direction = left; + + std::cout << payload << SYMBOLS[symbol_counter++]; + while (!found) + { + std::cout << '\b' << SYMBOLS[symbol_counter++]; + std::cout.flush(); + + if (symbol_counter == sizeof(SYMBOLS)) + { + if (direction == left) + { + std::cout << '\b'; + std::cout.flush(); + symbol_counter = 0; + if (!--current_state) + { + direction = right; + } + } + else if (direction == right) + { + std::cout << '\b' << payload[current_state] << " "; + std::cout.flush(); + symbol_counter = 0; + + if (++current_state == payload.size()) + { + direction = left; + } + } + } + std::this_thread::sleep_for(std::chrono::milliseconds(80)); + } +} + +bool thread_find(uint8_t * buf, const char * prefix, int id_thread, unsigned long long throughput) +{ + const unsigned long long original_throughput = throughput; + uint8_t b[391]; + uint32_t hash[8]; + + memcpy (b, buf, 391); + + size_t len = 52; + + if (!options.reg) + len = strlen(prefix); + + // precalculate first 5 blocks (320 bytes) + uint32_t state[8] = { 0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19 }; + HashNextBlock (state, b); + HashNextBlock (state, b + 64); + HashNextBlock (state, b + 128); + HashNextBlock (state, b + 192); + HashNextBlock (state, b + 256); + + // pre-calculate last W + uint32_t lastW[64]; + CalculateW (lastBlock, lastW); + + uint32_t * nonce = (uint32_t *)(b+320); + (*nonce) += id_thread*throughput; + + char addr[53]; + uint32_t state1[8]; + + while(!found) + { + if (! throughput--) + { + throughput = original_throughput; + } + + memcpy (state1, state, 32); + // calculate hash of block with nonce + HashNextBlock (state1, b + 320); + // apply last block + TransformBlock (state1, lastW); + // get final hash + for (int j = 8; j--;) + hash[j] = htobe32(state1[j]); + ByteStreamToBase32 ((uint8_t*)hash, 32, addr, len); + + if( options.reg ? !NotThat(addr, options.regex) : !NotThat(addr, prefix) ) + { + ByteStreamToBase32 ((uint8_t*)hash, 32, addr, 52); + std::cout << "\nFound address: " << addr << std::endl; + found = true; + return true; + } + + (*nonce)++; + if (found) + { + break; + } + } + + return true; +} + +void usage(void){ + const constexpr char * help="Usage:\n" + " vain [text-pattern|regex-pattern] [options]\n\n" + "OPTIONS:\n" + " -h --help show this help (same as --usage)\n" + " -r --reg use regexp instead of simple text pattern, ex.: vain '(one|two).*' -r\n" + " -t --threads number of threads to use (default: one per processor)\n" +// " -s --signature (signature type)\n" // NOT IMPLEMENTED FUCKING PLAZ! + " -o --output privkey output file name (default: ./" DEF_OUTNAME ")\n" + ""; + puts(help); +} + +void parsing(int argc, char ** args){ + 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") ){ + usage(); + exit(1); + } + case 'h': + usage(); + exit(0); + break; + case 'r': + options.reg=true; + break; + case 't': + options.threads=atoi(optarg); + break; + case 's': + options.signature = NameToSigType(std::string(optarg)); + check_sig_type(); + 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[]) +{ + if ( argc < 2 ) + { + usage(); + return 0; + } + + parsing( argc > 2 ? argc-1 : argc, argc > 2 ? argv+1 : argv); + // + if(!options.reg && !check_prefix( argv[1] )) + { + std::cout << "Invalid pattern." << std::endl; + usage(); + return 1; + }else{ + options.regex=std::regex(argv[1]); + } + + i2p::crypto::InitCrypto (false, true, true, false); + options.signature = i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519; + + if(options.signature != i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519) + { + std::cout << "ED25519-SHA512 are currently the only signing keys supported." << std::endl; + return 0; + } + + if (!options.sig_type) return -2; + auto keys = i2p::data::PrivateKeys::CreateRandomKeys (options.signature); + switch(options.signature) + { + case i2p::data::SIGNING_KEY_TYPE_DSA_SHA1: + case i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA512_P521: + case i2p::data::SIGNING_KEY_TYPE_RSA_SHA256_2048: + case i2p::data::SIGNING_KEY_TYPE_RSA_SHA384_3072: + case i2p::data::SIGNING_KEY_TYPE_RSA_SHA512_4096: + case i2p::data::SIGNING_KEY_TYPE_GOSTR3410_TC26_A_512_GOSTR3411_512: + std::cout << "Sorry, selected signature type is not supported for address generation." << std::endl; + return 0; + break; + } + +//TODO: for other types. + switch(options.signature) + { + case i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA256_P256: + break; + case i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA384_P384: + break; + case i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA512_P521: + break; + case i2p::data::SIGNING_KEY_TYPE_RSA_SHA256_2048: + break; + case i2p::data::SIGNING_KEY_TYPE_RSA_SHA384_3072: + break; + case i2p::data::SIGNING_KEY_TYPE_RSA_SHA512_4096: + break; + case i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519: + MutateByte=320; + break; + case i2p::data::SIGNING_KEY_TYPE_GOSTR3410_CRYPTO_PRO_A_GOSTR3411_256: + break; + } + + KeyBuf = new uint8_t[keys.GetFullLen()]; + keys.ToBuffer (KeyBuf, keys.GetFullLen ()); + + if(options.threads <= 0) + { + options.threads = std::thread::hardware_concurrency(); + } + + std::cout << "Vanity generator started in " << options.threads << " threads" << std::endl; + + std::vector threads(options.threads); + unsigned long long thoughtput = 0x4F4B5A37; + + for (unsigned int j = options.threads; j--; ) + { + threads[j] = std::thread(thread_find, KeyBuf, argv[1], j, thoughtput); + thoughtput += 1000; + } + + processFlipper(argv[1]); + + for (unsigned int j = 0; j < (unsigned int)options.threads;j++) + threads[j].join(); + + if(options.outputpath.empty()) options.outputpath.assign(DEF_OUTNAME); + + std::ofstream f (options.outputpath, std::ofstream::binary); + if (f) + { + f.write ((char *)KeyBuf, keys.GetFullLen ()); + delete [] KeyBuf; + } + else + std::cout << "Can't create output file: " << options.outputpath << std::endl; + + i2p::crypto::TerminateCrypto (); + + return 0; +} diff --git a/todelete/old_vanity/vain.cpp b/todelete/old_vanity/vain.cpp new file mode 100755 index 0000000..3c41631 --- /dev/null +++ b/todelete/old_vanity/vain.cpp @@ -0,0 +1,417 @@ +#include "vanity.hpp" +#include +#include + + +static struct{ + bool reg=false; + int threads=-1; + i2p::data::SigningKeyType signature; + std::string outputpath=""; + std::regex regex; + +}options; + + +static void inline CalculateW (const uint8_t block[64], uint32_t W[64]) +{ +/* +implementation of orignal +*/ + for (int i = 0; i < 16; i++) +#ifdef _WIN32 + W[i] = htobe32(((uint32_t *)(block))[i]); +#else // from big endian to little endian ( swap ) + W[i] = be32toh(((uint32_t *)(block))[i]); +#endif + + for (int i = 16; i < 64; i++) + W[i] = s1(W[i - 2]) + W[i - 7] + s0(W[i - 15]) + W[i - 16]; +} + +static void inline TransformBlock (uint32_t state[8], const uint32_t W[64]) +{ +/* +implementation of orignal +*/ + uint32_t S[8]; + memcpy(S, state, 32); + + uint32_t t0, t1; + RNDr(S, W, 0, 0x428a2f98); RNDr(S, W, 1, 0x71374491); RNDr(S, W, 2, 0xb5c0fbcf); RNDr(S, W, 3, 0xe9b5dba5); + RNDr(S, W, 4, 0x3956c25b); RNDr(S, W, 5, 0x59f111f1); RNDr(S, W, 6, 0x923f82a4); RNDr(S, W, 7, 0xab1c5ed5); + RNDr(S, W, 8, 0xd807aa98); RNDr(S, W, 9, 0x12835b01); RNDr(S, W, 10, 0x243185be); RNDr(S, W, 11, 0x550c7dc3); + RNDr(S, W, 12, 0x72be5d74); RNDr(S, W, 13, 0x80deb1fe); RNDr(S, W, 14, 0x9bdc06a7); RNDr(S, W, 15, 0xc19bf174); + RNDr(S, W, 16, 0xe49b69c1); RNDr(S, W, 17, 0xefbe4786); RNDr(S, W, 18, 0x0fc19dc6); RNDr(S, W, 19, 0x240ca1cc); + RNDr(S, W, 20, 0x2de92c6f); RNDr(S, W, 21, 0x4a7484aa); RNDr(S, W, 22, 0x5cb0a9dc); RNDr(S, W, 23, 0x76f988da); + RNDr(S, W, 24, 0x983e5152); RNDr(S, W, 25, 0xa831c66d); RNDr(S, W, 26, 0xb00327c8); RNDr(S, W, 27, 0xbf597fc7); + RNDr(S, W, 28, 0xc6e00bf3); RNDr(S, W, 29, 0xd5a79147); RNDr(S, W, 30, 0x06ca6351); RNDr(S, W, 31, 0x14292967); + RNDr(S, W, 32, 0x27b70a85); RNDr(S, W, 33, 0x2e1b2138); RNDr(S, W, 34, 0x4d2c6dfc); RNDr(S, W, 35, 0x53380d13); + RNDr(S, W, 36, 0x650a7354); RNDr(S, W, 37, 0x766a0abb); RNDr(S, W, 38, 0x81c2c92e); RNDr(S, W, 39, 0x92722c85); + RNDr(S, W, 40, 0xa2bfe8a1); RNDr(S, W, 41, 0xa81a664b); RNDr(S, W, 42, 0xc24b8b70); RNDr(S, W, 43, 0xc76c51a3); + RNDr(S, W, 44, 0xd192e819); RNDr(S, W, 45, 0xd6990624); RNDr(S, W, 46, 0xf40e3585); RNDr(S, W, 47, 0x106aa070); + RNDr(S, W, 48, 0x19a4c116); RNDr(S, W, 49, 0x1e376c08); RNDr(S, W, 50, 0x2748774c); RNDr(S, W, 51, 0x34b0bcb5); + RNDr(S, W, 52, 0x391c0cb3); RNDr(S, W, 53, 0x4ed8aa4a); RNDr(S, W, 54, 0x5b9cca4f); RNDr(S, W, 55, 0x682e6ff3); + RNDr(S, W, 56, 0x748f82ee); RNDr(S, W, 57, 0x78a5636f); RNDr(S, W, 58, 0x84c87814); RNDr(S, W, 59, 0x8cc70208); + RNDr(S, W, 60, 0x90befffa); RNDr(S, W, 61, 0xa4506ceb); RNDr(S, W, 62, 0xbef9a3f7); RNDr(S, W, 63, 0xc67178f2); + + for (int i = 0; i < 8; i++) state[i] += S[i]; +} + +void inline HashNextBlock (uint32_t state[8], const uint8_t * block) +{ +/* +implementation of orignal +*/ + uint32_t W[64]; + CalculateW (block, W); + TransformBlock (state, W); +} + +static bool check_prefix(const char * buf) +{ + unsigned short size_str=0; + while(*buf) + { + if(*buf < 48 || (*buf > 57 && *buf < 65) || (*buf > 64 && *buf < 94) || *buf > 125 || size_str > 52) + return false; + size_str++; + buf++; + } + return true; +} + +static inline size_t ByteStreamToBase32 (const uint8_t * inBuf, size_t len, char * outBuf, size_t outLen) +{ + size_t ret = 0, pos = 1; + int bits = 8, tmp = inBuf[0]; + while (ret < outLen && (bits > 0 || pos < len)) + { + if (bits < 5) + { + if (pos < len) + { + tmp <<= 8; + tmp |= inBuf[pos] & 0xFF; + pos++; + bits += 8; + } + else // last byte + { + tmp <<= (5 - bits); + bits = 5; + } + } + + bits -= 5; + int ind = (tmp >> bits) & 0x1F; + outBuf[ret] = (ind < 26) ? (ind + 'a') : ((ind - 26) + '2'); + ret++; + } + outBuf[ret]='\0'; + return ret; +} + +static inline bool NotThat(const char * what, const std::regex & reg){ + return std::regex_match(what,reg) == 1 ? false : true; +} + +static inline bool NotThat(const char * a, const char *b) +{ + while(*b) + if(*a++!=*b++) + return true; + return false; +} + +static inline bool thread_find(uint8_t * buf, const char * prefix, int id_thread, unsigned long long throughput) +{ +/* +Thanks to orignal ^-^ +For idea and example ^-^ +Orignal is sensei of crypto ;) +*/ + std::cout << "Thread " << id_thread << " binded" << std::endl; +/* + union + { + uint8_t b[391]; + uint32_t ll; + } local; + union + { + uint8_t b[32]; + uint32_t ll[8]; + } hash; +*/ + uint8_t b[391]; + uint32_t hash[8]; + + memcpy (b, buf, 391); + + auto len = strlen (prefix); + // precalculate first 5 blocks (320 bytes) + uint32_t state[8] = { 0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19 }; + HashNextBlock (state, b); + HashNextBlock (state, b + 64); + HashNextBlock (state, b + 128); + HashNextBlock (state, b + 192); + HashNextBlock (state, b + 256); + + // pre-calculate last W + uint32_t lastW[64]; + CalculateW (lastBlock, lastW); + + uint32_t * nonce = (uint32_t *)(b+320); + (*nonce) += id_thread*throughput; + + char addr[53]; + uint32_t state1[8]; + + while(throughput-- and !found) + { + memcpy (state1, state, 32); + // calculate hash of block with nonce + HashNextBlock (state1, b + 320); + // apply last block + TransformBlock (state1, lastW); + // get final hash + for (int j = 8; j--;) + hash[j] = htobe32(state1[j]); + ByteStreamToBase32 ((uint8_t*)hash, 32, addr, len); + // std::cout << addr << std::endl; + + //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); + std::cout << "Address found " << addr << " in " << id_thread << std::endl; + found=true; + FoundNonce=*nonce; + // free(hash); + // free(b); + return true; + } + + + (*nonce)++; + hashescounter++; + if (found) + { + // free(hash); + // free(b); + break; + } + }//while + return true; +} + + + + + +void usage(void){ + 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 usage\n" + //"--prefix -p\n" + ""; + puts(help); +} + + +void parsing(int argc, char ** args){ + 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") ){ + usage(); + exit(1); + } + case 'h': + usage(); + 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[]) +{ + + + + + if ( argc < 2 ) + { + usage(); + return 0; + } + parsing( argc > 2 ? argc-1 : argc, argc > 2 ? argv+1 : argv); + // + if(!options.reg && !check_prefix( argv[1] )) + { + std::cout << "Not correct prefix(just string)" << std::endl; + return 1; + }else{ + 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; +// } + } + + i2p::crypto::InitCrypto (false); + options.signature = i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519; +/////////////// +//For while + if(options.signature != i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519) + { + std::cout << "For a while only ED25519-SHA512" << std::endl; + return 0; + } +/////////////// + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + auto keys = i2p::data::PrivateKeys::CreateRandomKeys (options.signature); + switch(options.signature) + { + case i2p::data::SIGNING_KEY_TYPE_DSA_SHA1: + case i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA512_P521: + case i2p::data::SIGNING_KEY_TYPE_RSA_SHA256_2048: + case i2p::data::SIGNING_KEY_TYPE_RSA_SHA384_3072: + case i2p::data::SIGNING_KEY_TYPE_RSA_SHA512_4096: + 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; + return 0; + break; + } + +//TODO: for other types. + switch(options.signature) + { + case i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA256_P256: + break; + case i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA384_P384: + break; + case i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA512_P521: + break; + case i2p::data::SIGNING_KEY_TYPE_RSA_SHA256_2048: + break; + case i2p::data::SIGNING_KEY_TYPE_RSA_SHA384_3072: + break; + case i2p::data::SIGNING_KEY_TYPE_RSA_SHA512_4096: + break; + case i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519: + MutateByte=320; + break; + case i2p::data::SIGNING_KEY_TYPE_GOSTR3410_CRYPTO_PRO_A_GOSTR3411_256: + break; + } + + KeyBuf = new uint8_t[keys.GetFullLen()]; + keys.ToBuffer (KeyBuf, keys.GetFullLen ()); + + if(options.threads <= 0) + { +#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 + } + + std::cout << "Start vanity generator in " << options.threads << " threads" << std::endl; + + unsigned short attempts = 0; + while(!found) + {//while + {//stack(for destructors(vector/thread)) + + std::vector threads(options.threads); + unsigned long long thoughtput = 0x4F4B5A37; + + for ( unsigned int j = options.threads;j--;) + { + threads[j] = std::thread(thread_find,KeyBuf,argv[1],j,thoughtput); + thoughtput+=1000; + }//for + + for(unsigned int j = 0; j < (unsigned int)options.threads;j++) + threads[j].join(); + + if(FoundNonce == 0) + { + RAND_bytes( KeyBuf+MutateByte , 90 ); + std::cout << "Attempts #" << ++attempts << std::endl; + } + + }//stack + }//while + + memcpy (KeyBuf + MutateByte, &FoundNonce, 4); + std::cout << "Hashes: " << hashescounter << std::endl; + + if(options.outputpath.size() == 0) options.outputpath="private.dat"; + + std::ofstream f (options.outputpath, std::ofstream::binary | std::ofstream::out); + if (f) + { + f.write ((char *)KeyBuf, keys.GetFullLen ()); + delete [] KeyBuf; + } + else + std::cout << "Can't create file " << options.outputpath << std::endl; + + i2p::crypto::TerminateCrypto (); + + return 0; +} + + +// diff --git a/todelete/old_vanity/vanity.hpp b/todelete/old_vanity/vanity.hpp new file mode 100755 index 0000000..453e7f7 --- /dev/null +++ b/todelete/old_vanity/vanity.hpp @@ -0,0 +1,66 @@ +#pragma once +#include +#include +#include +#include +#include "Crypto.h" +#include "Identity.h" +#include "I2PEndian.h" +#include "common/key.hpp" +#include +#include +#include + +#ifdef _WIN32 +#include +#endif + +// sha256 +#define Ch(x, y, z) ((x & (y ^ z)) ^ z) +#define Maj(x, y, z) ((x & (y | z)) | (y & z)) +#define SHR(x, n) (x >> n) +#define ROTR(x, n) ((x >> n) | (x << (32 - n))) +#define S0(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22)) +#define S1(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25)) +#define s0(x) (ROTR(x, 7) ^ ROTR(x, 18) ^ SHR(x, 3)) +#define s1(x) (ROTR(x, 17) ^ ROTR(x, 19) ^ SHR(x, 10)) + +#define RND(a, b, c, d, e, f, g, h, k) \ + t0 = h + S1(e) + Ch(e, f, g) + k; \ + t1 = S0(a) + Maj(a, b, c); \ + d += t0; \ + h = t0 + t1; + +#define RNDr(S, W, i, k) \ + RND(S[(64 - i) % 8], S[(65 - i) % 8], \ + S[(66 - i) % 8], S[(67 - i) % 8], \ + S[(68 - i) % 8], S[(69 - i) % 8], \ + S[(70 - i) % 8], S[(71 - i) % 8], \ + W[i] + k) + + +//static i2p::data::SigningKeyType type; +//static i2p::data::PrivateKeys keys; +static bool found=false; + +static size_t MutateByte; + +static uint32_t FoundNonce=0; + +static uint8_t * KeyBuf; + +//static uint8_t * PaddingBuf; +static unsigned long long hashescounter; +unsigned int count_cpu; + +const uint8_t lastBlock[64] = + { + 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, 0x0C, 0x38 // 3128 bits (391 bytes) + }; diff --git a/vain.cpp b/vain.cpp new file mode 100755 index 0000000..f746534 --- /dev/null +++ b/vain.cpp @@ -0,0 +1,432 @@ +#include "vanity.hpp" +#include +#include +/// Crypto InitCrypto. TODO: to makefile/another place get the macro +#ifndef PRECOMPUTATION_CRYPTO +#define PRECOMPUTATION_CRYPTO false +#endif +#ifndef AESNI_CRYPTO +#define AESNI_CRYPTO false +#endif +#ifndef AVX_CRYPTO +#define AVX_CRYPTO false +#endif +#ifndef FORCE_CRYPTO +#define FORCE_CRYPTO false +#endif + +static struct{ + bool reg=false; + int threads=-1; + i2p::data::SigningKeyType signature; + std::string outputpath=""; + std::regex regex; + +}options; + + +static void inline CalculateW (const uint8_t block[64], uint32_t W[64]) +{ +/* +implementation of orignal +*/ + for (int i = 0; i < 16; i++) +#ifdef _WIN32 + W[i] = htobe32(((uint32_t *)(block))[i]); +#else // from big endian to little endian ( swap ) + W[i] = be32toh(((uint32_t *)(block))[i]); +#endif + + for (int i = 16; i < 64; i++) + W[i] = s1(W[i - 2]) + W[i - 7] + s0(W[i - 15]) + W[i - 16]; +} + +static void inline TransformBlock (uint32_t state[8], const uint32_t W[64]) +{ +/* +implementation of orignal +*/ + uint32_t S[8]; + memcpy(S, state, 32); + + uint32_t t0, t1; + RNDr(S, W, 0, 0x428a2f98); RNDr(S, W, 1, 0x71374491); RNDr(S, W, 2, 0xb5c0fbcf); RNDr(S, W, 3, 0xe9b5dba5); + RNDr(S, W, 4, 0x3956c25b); RNDr(S, W, 5, 0x59f111f1); RNDr(S, W, 6, 0x923f82a4); RNDr(S, W, 7, 0xab1c5ed5); + RNDr(S, W, 8, 0xd807aa98); RNDr(S, W, 9, 0x12835b01); RNDr(S, W, 10, 0x243185be); RNDr(S, W, 11, 0x550c7dc3); + RNDr(S, W, 12, 0x72be5d74); RNDr(S, W, 13, 0x80deb1fe); RNDr(S, W, 14, 0x9bdc06a7); RNDr(S, W, 15, 0xc19bf174); + RNDr(S, W, 16, 0xe49b69c1); RNDr(S, W, 17, 0xefbe4786); RNDr(S, W, 18, 0x0fc19dc6); RNDr(S, W, 19, 0x240ca1cc); + RNDr(S, W, 20, 0x2de92c6f); RNDr(S, W, 21, 0x4a7484aa); RNDr(S, W, 22, 0x5cb0a9dc); RNDr(S, W, 23, 0x76f988da); + RNDr(S, W, 24, 0x983e5152); RNDr(S, W, 25, 0xa831c66d); RNDr(S, W, 26, 0xb00327c8); RNDr(S, W, 27, 0xbf597fc7); + RNDr(S, W, 28, 0xc6e00bf3); RNDr(S, W, 29, 0xd5a79147); RNDr(S, W, 30, 0x06ca6351); RNDr(S, W, 31, 0x14292967); + RNDr(S, W, 32, 0x27b70a85); RNDr(S, W, 33, 0x2e1b2138); RNDr(S, W, 34, 0x4d2c6dfc); RNDr(S, W, 35, 0x53380d13); + RNDr(S, W, 36, 0x650a7354); RNDr(S, W, 37, 0x766a0abb); RNDr(S, W, 38, 0x81c2c92e); RNDr(S, W, 39, 0x92722c85); + RNDr(S, W, 40, 0xa2bfe8a1); RNDr(S, W, 41, 0xa81a664b); RNDr(S, W, 42, 0xc24b8b70); RNDr(S, W, 43, 0xc76c51a3); + RNDr(S, W, 44, 0xd192e819); RNDr(S, W, 45, 0xd6990624); RNDr(S, W, 46, 0xf40e3585); RNDr(S, W, 47, 0x106aa070); + RNDr(S, W, 48, 0x19a4c116); RNDr(S, W, 49, 0x1e376c08); RNDr(S, W, 50, 0x2748774c); RNDr(S, W, 51, 0x34b0bcb5); + RNDr(S, W, 52, 0x391c0cb3); RNDr(S, W, 53, 0x4ed8aa4a); RNDr(S, W, 54, 0x5b9cca4f); RNDr(S, W, 55, 0x682e6ff3); + RNDr(S, W, 56, 0x748f82ee); RNDr(S, W, 57, 0x78a5636f); RNDr(S, W, 58, 0x84c87814); RNDr(S, W, 59, 0x8cc70208); + RNDr(S, W, 60, 0x90befffa); RNDr(S, W, 61, 0xa4506ceb); RNDr(S, W, 62, 0xbef9a3f7); RNDr(S, W, 63, 0xc67178f2); + + for (int i = 0; i < 8; i++) state[i] += S[i]; +} + +void inline HashNextBlock (uint32_t state[8], const uint8_t * block) +{ +/* +implementation of orignal +*/ + uint32_t W[64]; + CalculateW (block, W); + TransformBlock (state, W); +} + +static bool check_prefix(const char * buf) +{ + unsigned short size_str=0; + while(*buf) + { + if(*buf < 48 || (*buf > 57 && *buf < 65) || (*buf > 64 && *buf < 94) || *buf > 125 || size_str > 52) + return false; + size_str++; + buf++; + } + return true; +} + +static inline size_t ByteStreamToBase32 (const uint8_t * inBuf, size_t len, char * outBuf, size_t outLen) +{ + size_t ret = 0, pos = 1; + int bits = 8, tmp = inBuf[0]; + while (ret < outLen && (bits > 0 || pos < len)) + { + if (bits < 5) + { + if (pos < len) + { + tmp <<= 8; + tmp |= inBuf[pos] & 0xFF; + pos++; + bits += 8; + } + else // last byte + { + tmp <<= (5 - bits); + bits = 5; + } + } + + bits -= 5; + int ind = (tmp >> bits) & 0x1F; + outBuf[ret] = (ind < 26) ? (ind + 'a') : ((ind - 26) + '2'); + ret++; + } + outBuf[ret]='\0'; + return ret; +} + +static inline bool NotThat(const char * what, const std::regex & reg){ + return std::regex_match(what,reg) == 1 ? false : true; +} + +static inline bool NotThat(const char * a, const char *b) +{ + while(*b) + if(*a++!=*b++) + return true; + return false; +} + +static inline bool thread_find(uint8_t * buf, const char * prefix, int id_thread, unsigned long long throughput) +{ +/* +Thanks to orignal ^-^ +For idea and example ^-^ +Orignal is sensei of crypto ;) +*/ + std::cout << "Thread " << id_thread << " binded" << std::endl; +/* + union + { + uint8_t b[391]; + uint32_t ll; + } local; + union + { + uint8_t b[32]; + uint32_t ll[8]; + } hash; +*/ + uint8_t b[391]; + uint32_t hash[8]; + + memcpy (b, buf, 391); + + auto len = strlen (prefix); + // precalculate first 5 blocks (320 bytes) + uint32_t state[8] = { 0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19 }; + HashNextBlock (state, b); + HashNextBlock (state, b + 64); + HashNextBlock (state, b + 128); + HashNextBlock (state, b + 192); + HashNextBlock (state, b + 256); + + // pre-calculate last W + uint32_t lastW[64]; + CalculateW (lastBlock, lastW); + + uint32_t * nonce = (uint32_t *)(b+320); + (*nonce) += id_thread*throughput; + + char addr[53]; + uint32_t state1[8]; + + while(throughput-- and !found) + { + memcpy (state1, state, 32); + // calculate hash of block with nonce + HashNextBlock (state1, b + 320); + // apply last block + TransformBlock (state1, lastW); + // get final hash + for (int j = 8; j--;) + hash[j] = htobe32(state1[j]); + ByteStreamToBase32 ((uint8_t*)hash, 32, addr, len); + // std::cout << addr << std::endl; + + //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); + std::cout << "Address found " << addr << " in " << id_thread << std::endl; + found=true; + FoundNonce=*nonce; + // free(hash); + // free(b); + return true; + } + + + (*nonce)++; + hashescounter++; + if (found) + { + // free(hash); + // free(b); + break; + } + }//while + return true; +} + + + + + +void usage(void){ + 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 usage\n" + //"--prefix -p\n" + ""; + puts(help); +} + + +void parsing(int argc, char ** args){ + 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") ){ + usage(); + exit(1); + } + case 'h': + usage(); + 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[]) +{ + + + + + if ( argc < 2 ) + { + usage(); + return 0; + } + parsing( argc > 2 ? argc-1 : argc, argc > 2 ? argv+1 : argv); + // + if(!options.reg && !check_prefix( argv[1] )) + { + std::cout << "Not correct prefix(just string)" << std::endl; + return 1; + }else{ + 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 +//// init and terminate +// void InitCrypto (bool precomputation, bool aesni, bool avx, bool force); +// By default false to all. + i2p::crypto::InitCrypto (PRECOMPUTATION_CRYPTO, AESNI_CRYPTO, AVX_CRYPTO, FORCE_CRYPTO); + options.signature = i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519; +/////////////// +//For while + if(options.signature != i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519) + { + std::cout << "For a while only ED25519-SHA512" << std::endl; + return 0; + } +/////////////// + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + auto keys = i2p::data::PrivateKeys::CreateRandomKeys (options.signature); + switch(options.signature) + { + case i2p::data::SIGNING_KEY_TYPE_DSA_SHA1: + case i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA512_P521: + case i2p::data::SIGNING_KEY_TYPE_RSA_SHA256_2048: + case i2p::data::SIGNING_KEY_TYPE_RSA_SHA384_3072: + case i2p::data::SIGNING_KEY_TYPE_RSA_SHA512_4096: + 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; + return 0; + break; + } + +//TODO: for other types. + switch(options.signature) + { + case i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA256_P256: + break; + case i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA384_P384: + break; + case i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA512_P521: + break; + case i2p::data::SIGNING_KEY_TYPE_RSA_SHA256_2048: + break; + case i2p::data::SIGNING_KEY_TYPE_RSA_SHA384_3072: + break; + case i2p::data::SIGNING_KEY_TYPE_RSA_SHA512_4096: + break; + case i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519: + MutateByte=320; + break; + case i2p::data::SIGNING_KEY_TYPE_GOSTR3410_CRYPTO_PRO_A_GOSTR3411_256: + break; + } + + KeyBuf = new uint8_t[keys.GetFullLen()]; + keys.ToBuffer (KeyBuf, keys.GetFullLen ()); + + if(options.threads <= 0) + { +#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 + } + + std::cout << "Start vanity generator in " << options.threads << " threads" << std::endl; + + unsigned short attempts = 0; + while(!found) + {//while + {//stack(for destructors(vector/thread)) + + std::vector threads(options.threads); + unsigned long long thoughtput = 0x4F4B5A37; + + for ( unsigned int j = options.threads;j--;) + { + threads[j] = std::thread(thread_find,KeyBuf,argv[1],j,thoughtput); + thoughtput+=1000; + }//for + + for(unsigned int j = 0; j < (unsigned int)options.threads;j++) + threads[j].join(); + + if(FoundNonce == 0) + { + RAND_bytes( KeyBuf+MutateByte , 90 ); + std::cout << "Attempts #" << ++attempts << std::endl; + } + + }//stack + }//while + + memcpy (KeyBuf + MutateByte, &FoundNonce, 4); + std::cout << "Hashes: " << hashescounter << std::endl; + + if(options.outputpath.size() == 0) options.outputpath="private.dat"; + + std::ofstream f (options.outputpath, std::ofstream::binary | std::ofstream::out); + if (f) + { + f.write ((char *)KeyBuf, keys.GetFullLen ()); + delete [] KeyBuf; + } + else + std::cout << "Can't create file " << options.outputpath << std::endl; + + i2p::crypto::TerminateCrypto (); + + return 0; +} + + +// diff --git a/vanity.hpp b/vanity.hpp new file mode 100755 index 0000000..453e7f7 --- /dev/null +++ b/vanity.hpp @@ -0,0 +1,66 @@ +#pragma once +#include +#include +#include +#include +#include "Crypto.h" +#include "Identity.h" +#include "I2PEndian.h" +#include "common/key.hpp" +#include +#include +#include + +#ifdef _WIN32 +#include +#endif + +// sha256 +#define Ch(x, y, z) ((x & (y ^ z)) ^ z) +#define Maj(x, y, z) ((x & (y | z)) | (y & z)) +#define SHR(x, n) (x >> n) +#define ROTR(x, n) ((x >> n) | (x << (32 - n))) +#define S0(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22)) +#define S1(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25)) +#define s0(x) (ROTR(x, 7) ^ ROTR(x, 18) ^ SHR(x, 3)) +#define s1(x) (ROTR(x, 17) ^ ROTR(x, 19) ^ SHR(x, 10)) + +#define RND(a, b, c, d, e, f, g, h, k) \ + t0 = h + S1(e) + Ch(e, f, g) + k; \ + t1 = S0(a) + Maj(a, b, c); \ + d += t0; \ + h = t0 + t1; + +#define RNDr(S, W, i, k) \ + RND(S[(64 - i) % 8], S[(65 - i) % 8], \ + S[(66 - i) % 8], S[(67 - i) % 8], \ + S[(68 - i) % 8], S[(69 - i) % 8], \ + S[(70 - i) % 8], S[(71 - i) % 8], \ + W[i] + k) + + +//static i2p::data::SigningKeyType type; +//static i2p::data::PrivateKeys keys; +static bool found=false; + +static size_t MutateByte; + +static uint32_t FoundNonce=0; + +static uint8_t * KeyBuf; + +//static uint8_t * PaddingBuf; +static unsigned long long hashescounter; +unsigned int count_cpu; + +const uint8_t lastBlock[64] = + { + 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, 0x0C, 0x38 // 3128 bits (391 bytes) + }; From e0b0a3f9df817ab185df76bb6a2555f025e3153e Mon Sep 17 00:00:00 2001 From: wipedlifepotato Date: Tue, 1 Aug 2023 00:50:48 +0700 Subject: [PATCH 22/45] vain ressurect --- vain.cpp | 140 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 97 insertions(+), 43 deletions(-) diff --git a/vain.cpp b/vain.cpp index f746534..3e16d70 100755 --- a/vain.cpp +++ b/vain.cpp @@ -1,6 +1,10 @@ #include "vanity.hpp" #include #include +#include +#include +//#include // is not supports for me + /// Crypto InitCrypto. TODO: to makefile/another place get the macro #ifndef PRECOMPUTATION_CRYPTO #define PRECOMPUTATION_CRYPTO false @@ -15,6 +19,8 @@ #define FORCE_CRYPTO false #endif +#define DEF_OUT_FILE "private.dat" + static struct{ bool reg=false; int threads=-1; @@ -156,10 +162,10 @@ Orignal is sensei of crypto ;) uint32_t ll[8]; } hash; */ - uint8_t b[391]; + uint8_t b[391]; // b length is 391. uint32_t hash[8]; - memcpy (b, buf, 391); + memcpy (b, buf, 391); // we copy in b our buf, that we give in function. auto len = strlen (prefix); // precalculate first 5 blocks (320 bytes) @@ -174,7 +180,7 @@ Orignal is sensei of crypto ;) uint32_t lastW[64]; CalculateW (lastBlock, lastW); - uint32_t * nonce = (uint32_t *)(b+320); + uint32_t * nonce = (uint32_t *)(b+320); // our nonce is place in memory, where is b after 320 bytes (characters) (*nonce) += id_thread*throughput; char addr[53]; @@ -204,13 +210,14 @@ Orignal is sensei of crypto ;) FoundNonce=*nonce; // free(hash); // free(b); + // From there place we get a nonce, for some one a byte. return true; } (*nonce)++; hashescounter++; - if (found) + if (found) // for another threads { // free(hash); // free(b); @@ -225,14 +232,14 @@ Orignal is sensei of crypto ;) void usage(void){ - const constexpr char * help="vain pattern [options]\n" + constexpr auto 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 usage\n" - //"--prefix -p\n" +//"--signature -s (signature type)\n" + "-o --output output file(default " DEF_OUT_FILE ")\n" +//"--usage usage\n" +//"--prefix -p\n" ""; puts(help); } @@ -246,18 +253,18 @@ void parsing(int argc, char ** args){ {"threads", required_argument, 0, 't'}, {"signature", required_argument,0,'s'}, {"output", required_argument,0,'o'}, - {"usage", no_argument,0,0}, + //{"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") ){ - usage(); - exit(1); - } + //case 0: + // if ( std::string(long_options[option_index].name) == std::string("usage") ){ + // usage(); + // exit(1); + // } case 'h': usage(); exit(0); @@ -277,7 +284,7 @@ void parsing(int argc, char ** args){ case '?': std::cerr << "Undefined argument" << std::endl; default: - std::cerr << args[0] << " --usage / --help" << std::endl; + std::cerr << args[0] << "--help" << std::endl; exit(1); break; } @@ -295,7 +302,9 @@ int main (int argc, char * argv[]) usage(); return 0; } - parsing( argc > 2 ? argc-1 : argc, argc > 2 ? argv+1 : argv); + 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 + // TODO: ? // if(!options.reg && !check_prefix( argv[1] )) { @@ -323,9 +332,49 @@ int main (int argc, char * argv[]) return 0; } /////////////// +// if threads less than 0, then we get from system count of CPUs cores + if(options.threads <= 0) + { + 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 + } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// Isntead proccess flipper? + if ( !std::regex_match( std::string(argv[1]), std::regex("[a-zA-Z0-9\\.]{1,}")) ) { + std::cerr << "Please, change the outputfile name" << std::endl; + } 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 + // If file not exists we create a dump file. (a bug was found in issues) switch(options.signature) { case i2p::data::SIGNING_KEY_TYPE_DSA_SHA1: @@ -360,59 +409,64 @@ int main (int argc, char * argv[]) case i2p::data::SIGNING_KEY_TYPE_GOSTR3410_CRYPTO_PRO_A_GOSTR3411_256: break; } - +// there we gen key to buffer. That we mem allocate... KeyBuf = new uint8_t[keys.GetFullLen()]; keys.ToBuffer (KeyBuf, keys.GetFullLen ()); - - if(options.threads <= 0) - { -#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 - } - +/// there was some things for cpu 665% usage, but is not helpful even std::cout << "Start vanity generator in " << options.threads << " threads" << std::endl; - - unsigned short attempts = 0; +// 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)) std::vector threads(options.threads); - unsigned long long thoughtput = 0x4F4B5A37; + unsigned long long thoughtput = 0x4F4B5A37; // is a magic number. for ( unsigned int j = options.threads;j--;) { + // our buf is our key, but in uint8 type, unsigned integ... another argument + // is our prefix that we search in address + // and j is magic number, is thread id. + // 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); - thoughtput+=1000; + thoughtput+=1000; }//for + //There will be proccessFlipper by accetone + // if I correctly understand it's drop a payload things in a prefix/search data + // or simmilar. We can just use regex. I would to use regex + + // So I put it ^^^ for(unsigned int j = 0; j < (unsigned int)options.threads;j++) threads[j].join(); if(FoundNonce == 0) { - RAND_bytes( KeyBuf+MutateByte , 90 ); + RAND_bytes( KeyBuf+MutateByte , 90 ); // FoundNonce is std::cout << "Attempts #" << ++attempts << std::endl; } }//stack }//while - + // before we write result we would to create private.dat a file. dump file. we can use for it keygen + // so. memcpy (KeyBuf + MutateByte, &FoundNonce, 4); std::cout << "Hashes: " << hashescounter << std::endl; - if(options.outputpath.size() == 0) options.outputpath="private.dat"; + // IDK. what for acetone change this line to if (options.output...empty() ... assign + // 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 . empty () ) options . outputpath . assign ( DEF_OUT_FILE ) ; + + // there we generate a key, like as in keygen.cpp + // before a mining we would to create a dump file + + 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); if (f) From a5eed1682e679457ba402585ddf588a2be2eed4e Mon Sep 17 00:00:00 2001 From: wipedlifepotato Date: Tue, 1 Aug 2023 00:51:04 +0700 Subject: [PATCH 23/45] add vain to makefile --- Makefile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) mode change 100644 => 100755 Makefile diff --git a/Makefile b/Makefile old mode 100644 new mode 100755 index 3c38c46..eb65559 --- a/Makefile +++ b/Makefile @@ -43,8 +43,9 @@ else LDFLAGS += -s -static endif -all: $(I2PD_LIB) keygen keyinfo famtool routerinfo regaddr regaddr_3ld i2pbase64 offlinekeys b33address regaddralias x25519 verifyhost - +all: $(I2PD_LIB) vain keygen keyinfo famtool routerinfo regaddr regaddr_3ld i2pbase64 offlinekeys b33address regaddralias x25519 verifyhost +vain: vain.o $(I2PD_LIB) + $(CXX) -o vain $(LDFLAGS) vain.o $(LDLIBS) routerinfo: routerinfo.o $(I2PD_LIB) $(CXX) -o routerinfo $(LDFLAGS) routerinfo.o $(LDLIBS) @@ -100,7 +101,7 @@ clean-obj: rm -f $(wildcard *.o) clean-bin: - rm -f b33address famtool i2pbase64 keygen keyinfo offlinekeys regaddr regaddr_3ld regaddralias routerinfo x25519 verifyhost + rm -f b33address famtool i2pbase64 keygen keyinfo offlinekeys regaddr regaddr_3ld regaddralias routerinfo x25519 verifyhost vain clean: clean-i2pd clean-obj clean-bin From 3acfdccac3deee967234c5f260da41dc697e804d Mon Sep 17 00:00:00 2001 From: wipedlifepotato Date: Tue, 1 Aug 2023 02:07:08 +0700 Subject: [PATCH 24/45] multiple search addresses --- vain.cpp | 281 +++++++++++++++++++++++++++-------------------------- vanity.hpp | 21 +++- 2 files changed, 164 insertions(+), 138 deletions(-) diff --git a/vain.cpp b/vain.cpp index 3e16d70..9b23145 100755 --- a/vain.cpp +++ b/vain.cpp @@ -3,24 +3,10 @@ #include #include #include +//#include //#include // is not supports for me -/// Crypto InitCrypto. TODO: to makefile/another place get the macro -#ifndef PRECOMPUTATION_CRYPTO -#define PRECOMPUTATION_CRYPTO false -#endif -#ifndef AESNI_CRYPTO -#define AESNI_CRYPTO false -#endif -#ifndef AVX_CRYPTO -#define AVX_CRYPTO false -#endif -#ifndef FORCE_CRYPTO -#define FORCE_CRYPTO false -#endif - -#define DEF_OUT_FILE "private.dat" - +// some global vars in vanitygen.hpp static struct{ bool reg=false; int threads=-1; @@ -240,6 +226,7 @@ void usage(void){ "-o --output output file(default " DEF_OUT_FILE ")\n" //"--usage usage\n" //"--prefix -p\n" + "--multiplymode -m - multiple addresses search" ""; puts(help); } @@ -253,18 +240,22 @@ void parsing(int argc, char ** args){ {"threads", required_argument, 0, 't'}, {"signature", required_argument,0,'s'}, {"output", required_argument,0,'o'}, + {"multiplymode", no_argument, 0, 'm'}, //{"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){ + while( (c=getopt_long(argc,args, "hrt:s:o:m", long_options, &option_index))!=-1){ switch(c){ //case 0: // if ( std::string(long_options[option_index].name) == std::string("usage") ){ // usage(); // exit(1); // } + case 'm': + multipleSearchMode=true; + break; case 'h': usage(); exit(0); @@ -357,129 +348,145 @@ int main (int argc, char * argv[]) if ( !std::regex_match( std::string(argv[1]), std::regex("[a-zA-Z0-9\\.]{1,}")) ) { std::cerr << "Please, change the outputfile name" << std::endl; } - 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 - // If file not exists we create a dump file. (a bug was found in issues) - switch(options.signature) - { - case i2p::data::SIGNING_KEY_TYPE_DSA_SHA1: - case i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA512_P521: - case i2p::data::SIGNING_KEY_TYPE_RSA_SHA256_2048: - case i2p::data::SIGNING_KEY_TYPE_RSA_SHA384_3072: - case i2p::data::SIGNING_KEY_TYPE_RSA_SHA512_4096: - 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; - return 0; - break; - } + // + if ( options . outputpath . empty () ) options . outputpath . assign ( DEF_OUT_FILE ) ; + static std::string outPutFileName = options.outputpath; + auto doSearch = [argc,argv] () { + 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 + // If file not exists we create a dump file. (a bug was found in issues) + switch(options.signature) + { + case i2p::data::SIGNING_KEY_TYPE_DSA_SHA1: + case i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA512_P521: + case i2p::data::SIGNING_KEY_TYPE_RSA_SHA256_2048: + case i2p::data::SIGNING_KEY_TYPE_RSA_SHA384_3072: + case i2p::data::SIGNING_KEY_TYPE_RSA_SHA512_4096: + 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; + return 0; + break; + } + + //TODO: for other types. + switch(options.signature) + { + case i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA256_P256: + break; + case i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA384_P384: + break; + case i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA512_P521: + break; + case i2p::data::SIGNING_KEY_TYPE_RSA_SHA256_2048: + break; + case i2p::data::SIGNING_KEY_TYPE_RSA_SHA384_3072: + break; + case i2p::data::SIGNING_KEY_TYPE_RSA_SHA512_4096: + break; + case i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519: + MutateByte=320; + break; + case i2p::data::SIGNING_KEY_TYPE_GOSTR3410_CRYPTO_PRO_A_GOSTR3411_256: + break; + } + // there we gen key to buffer. That we mem allocate... + KeyBuf = new uint8_t[keys.GetFullLen()]; + keys.ToBuffer (KeyBuf, keys.GetFullLen ()); + /// 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 + // 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)) + + std::vector threads(options.threads); + unsigned long long thoughtput = 0x4F4B5A37; // is a magic number. + + for ( unsigned int j = options.threads;j--;) + { + // our buf is our key, but in uint8 type, unsigned integ... another argument + // is our prefix that we search in address + // and j is magic number, is thread id. + // 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); + thoughtput+=1000; + }//for + + //There will be proccessFlipper by accetone + // if I correctly understand it's drop a payload things in a prefix/search data + // or simmilar. We can just use regex. I would to use regex + + // So I put it ^^^ + for(unsigned int j = 0; j < (unsigned int)options.threads;j++) + threads[j].join(); + + if(FoundNonce == 0) + { + RAND_bytes( KeyBuf+MutateByte , 90 ); // FoundNonce is + std::cout << "Attempts #" << ++attempts << std::endl; + } + + }//stack + }//while + // before we write result we would to create private.dat a file. dump file. we can use for it keygen + // so. + memcpy (KeyBuf + MutateByte, &FoundNonce, 4); + std::cout << "Hashes: " << hashescounter << std::endl; + + // IDK. what for acetone change this line to if (options.output...empty() ... assign + // 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; + options.outputpath = options.outputpath + std::to_string(foundKeys) + std::string(".dat"); -//TODO: for other types. - switch(options.signature) - { - case i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA256_P256: - break; - case i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA384_P384: - break; - case i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA512_P521: - break; - case i2p::data::SIGNING_KEY_TYPE_RSA_SHA256_2048: - break; - case i2p::data::SIGNING_KEY_TYPE_RSA_SHA384_3072: - break; - case i2p::data::SIGNING_KEY_TYPE_RSA_SHA512_4096: - break; - case i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519: - MutateByte=320; - break; - case i2p::data::SIGNING_KEY_TYPE_GOSTR3410_CRYPTO_PRO_A_GOSTR3411_256: - break; - } -// there we gen key to buffer. That we mem allocate... - KeyBuf = new uint8_t[keys.GetFullLen()]; - keys.ToBuffer (KeyBuf, keys.GetFullLen ()); -/// 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 -// 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)) + //if ( ! boost::algorithm::ends_with(options.outputpath, ".dat") ) + // options.outputpath = options.outputpath + ".dat"; + + // there we generate a key, like as in keygen.cpp + // before a mining we would to create a dump file + + 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); + if (f) + { + f.write ((char *)KeyBuf, keys.GetFullLen ()); + delete [] KeyBuf; + } + else + std::cout << "Can't create file " << options.outputpath << std::endl; + + }; // void doSearch lamda - std::vector threads(options.threads); - unsigned long long thoughtput = 0x4F4B5A37; // is a magic number. + do { + doSearch(); + foundKeys++; + options.outputpath.assign(outPutFileName); + found = false; + FoundNonce = 0; + } while(multipleSearchMode); - for ( unsigned int j = options.threads;j--;) - { - // our buf is our key, but in uint8 type, unsigned integ... another argument - // is our prefix that we search in address - // and j is magic number, is thread id. - // 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); - thoughtput+=1000; - }//for - - //There will be proccessFlipper by accetone - // if I correctly understand it's drop a payload things in a prefix/search data - // or simmilar. We can just use regex. I would to use regex - - // So I put it ^^^ - for(unsigned int j = 0; j < (unsigned int)options.threads;j++) - threads[j].join(); - - if(FoundNonce == 0) - { - RAND_bytes( KeyBuf+MutateByte , 90 ); // FoundNonce is - std::cout << "Attempts #" << ++attempts << std::endl; - } - - }//stack - }//while - // before we write result we would to create private.dat a file. dump file. we can use for it keygen - // so. - memcpy (KeyBuf + MutateByte, &FoundNonce, 4); - std::cout << "Hashes: " << hashescounter << std::endl; - - // IDK. what for acetone change this line to if (options.output...empty() ... assign - // 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 . empty () ) options . outputpath . assign ( DEF_OUT_FILE ) ; - - // there we generate a key, like as in keygen.cpp - // before a mining we would to create a dump file - - 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); - if (f) - { - f.write ((char *)KeyBuf, keys.GetFullLen ()); - delete [] KeyBuf; - } - else - std::cout << "Can't create file " << options.outputpath << std::endl; - - i2p::crypto::TerminateCrypto (); - - return 0; + i2p::crypto::TerminateCrypto (); + return 0; } diff --git a/vanity.hpp b/vanity.hpp index 453e7f7..0a8a5cd 100755 --- a/vanity.hpp +++ b/vanity.hpp @@ -41,8 +41,27 @@ //static i2p::data::SigningKeyType type; //static i2p::data::PrivateKeys keys; -static bool found=false; + +// for InitCrypto. TODO: to makefile/another place get the macro +#ifndef PRECOMPUTATION_CRYPTO +#define PRECOMPUTATION_CRYPTO false +#endif +#ifndef AESNI_CRYPTO +#define AESNI_CRYPTO false +#endif +#ifndef AVX_CRYPTO +#define AVX_CRYPTO false +#endif +#ifndef FORCE_CRYPTO +#define FORCE_CRYPTO false +#endif +// def out file name +#define DEF_OUT_FILE "private" +// Global vars +static bool found=false; +static bool multipleSearchMode = false; +static unsigned int foundKeys = 0; static size_t MutateByte; static uint32_t FoundNonce=0; From 377b3c0ea5fd5511722df992575d18325dfcafd2 Mon Sep 17 00:00:00 2001 From: wipedlifepotato Date: Tue, 1 Aug 2023 02:23:09 +0700 Subject: [PATCH 25/45] -latomic to famtool and routerinfo #80 --- Makefile | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) mode change 100644 => 100755 Makefile diff --git a/Makefile b/Makefile old mode 100644 new mode 100755 index 3c38c46..924bfc0 --- a/Makefile +++ b/Makefile @@ -12,7 +12,8 @@ INCFLAGS = -I$(LIBI2PD_PATH) -I$(LIBI2PD_CLIENT_PATH) DEFINES = -DOPENSSL_SUPPRESS_DEPRECATED LDFLAGS = -LDLIBS = $(I2PD_PATH)/$(I2PD_LIB) -lboost_system$(BOOST_SUFFIX) -lboost_date_time$(BOOST_SUFFIX) -lboost_filesystem$(BOOST_SUFFIX) -lboost_program_options$(BOOST_SUFFIX) -lssl -lcrypto -lz +LDLIBS = $(I2PD_PATH)/$(I2PD_LIB) -lboost_system$(BOOST_SUFFIX) -lboost_date_time$(BOOST_SUFFIX) -lboost_filesystem$(BOOST_SUFFIX) -lboost_program_options$(BOOST_SUFFIX) -lssl -lcrypto -lz + ifeq ($(UNAME),Linux) CXXFLAGS += -g @@ -43,10 +44,13 @@ else LDFLAGS += -s -static endif -all: $(I2PD_LIB) keygen keyinfo famtool routerinfo regaddr regaddr_3ld i2pbase64 offlinekeys b33address regaddralias x25519 verifyhost +all: $(I2PD_LIB) vain keygen keyinfo famtool routerinfo regaddr regaddr_3ld i2pbase64 offlinekeys b33address regaddralias x25519 verifyhost + +vain: vain.o $(I2PD_LIB) + $(CXX) -o vain $(LDFLAGS) vain.o $(LDLIBS) routerinfo: routerinfo.o $(I2PD_LIB) - $(CXX) -o routerinfo $(LDFLAGS) routerinfo.o $(LDLIBS) + $(CXX) -o routerinfo $(LDFLAGS) routerinfo.o $(LDLIBS) -latomic keygen: keygen.o $(I2PD_LIB) $(CXX) -o keygen $(DEFINES) $(LDFLAGS) keygen.o $(LDLIBS) @@ -55,7 +59,7 @@ keyinfo: keyinfo.o $(I2PD_LIB) $(CXX) -o keyinfo $(DEFINES) $(LDFLAGS) keyinfo.o $(LDLIBS) famtool: famtool.o $(I2PD_LIB) - $(CXX) -o famtool $(DEFINES) $(LDFLAGS) famtool.o $(LDLIBS) + $(CXX) -o famtool $(DEFINES) $(LDFLAGS) famtool.o $(LDLIBS) -latomic regaddr: regaddr.o $(I2PD_LIB) $(CXX) -o regaddr $(DEFINES) $(LDFLAGS) regaddr.o $(LDLIBS) From 82e7be68efd683694e297a616f1e291633a3aba5 Mon Sep 17 00:00:00 2001 From: wipedlifepotato <60944239+wipedlifepotato@users.noreply.github.com> Date: Tue, 1 Aug 2023 02:33:13 +0700 Subject: [PATCH 26/45] Add famtool example and vain usage to README.md --- README.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/README.md b/README.md index 51dc29e..f9e2172 100755 --- a/README.md +++ b/README.md @@ -79,6 +79,13 @@ or | RED25519-SHA512 | 11 | For more information on the types of signatures, see the [documentation](https://i2pd.readthedocs.io/en/latest/user-guide/tunnels/#signature-types). +### vain + +Vanity generation address. + +#### Usage + +./vain --usage #### Time to Generate on a 2.70GHz Processor | characters| time to generate (approx.) | @@ -143,3 +150,41 @@ Send output of auth_string to http://reg.i2p/add and http://stats.i2p/i2p/addkey ### x25519 Generate key pair with output in base64 encoding. Now the x25519 keys are used for authentication with an encrypted LeaseSet. + +### famtool +[this is program for works with family of routers in i2p-network. ](https://i2pd.readthedocs.io/en/latest/user-guide/family/) + +usage: ```./famtool [-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]``` + +generate a new family signing key for family called ``i2pfam'' +```./famtool -g -n i2pfam -c myfam.crt -k myfam.pem``` + +sign a router info with family signing key +```./famtool -s -n i2pfam -k myfam.pem -i router.keys -f router.info``` + +verify signed router.info +```./famtool -V -n i2pfam -c myfam.pem -f router.info``` +#### Example of usage + $ ./famtool -g -n i2pfam -c myfam.crt -k myfam.pem + family i2pfam made + $ cat myfam.crt + -----BEGIN CERTIFICATE----- + MIIB3TCCAYOgAwIBAgIBADAKBggqhkjOPQQDAjB4MQswCQYDVQQGEwJYWDELMAkG + A1UECAwCWFgxCzAJBgNVBAcMAlhYMR4wHAYDVQQKDBVJMlAgQW5vbnltb3VzIE5l + dHdvcmsxDzANBgNVBAsMBmZhbWlseTEeMBwGA1UEAwwVaTJwZmFtLmZhbWlseS5p + MnAubmV0MB4XDTIzMDczMTE5MjQ1MFoXDTMzMDcyODE5MjQ1MFoweDELMAkGA1UE + BhMCWFgxCzAJBgNVBAgMAlhYMQswCQYDVQQHDAJYWDEeMBwGA1UECgwVSTJQIEFu + b255bW91cyBOZXR3b3JrMQ8wDQYDVQQLDAZmYW1pbHkxHjAcBgNVBAMMFWkycGZh + bS5mYW1pbHkuaTJwLm5ldDBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABLejNp1Y + 1tnMGFaUIuzNpNL8B9KvaeSSh+OWhRcHn2x1D8TPCVA4IMS0jiMIodCcdyTmz0Qg + SXsWDqT2CbBMENQwCgYIKoZIzj0EAwIDSAAwRQIgU58CeHXlluPZNxpmxb7HSHsJ + STCA8C946oas+8uLU+MCIQDe6Km/h8w+oCh+j6UHobN0EAVtQPQGwkq2XXs1jqX2 + bQ== + -----END CERTIFICATE----- + $ cat myfam.pem + -----BEGIN EC PRIVATE KEY----- + MHcCAQEEIAFA82vZzZN8nZIOVnadSS73G2NNc5pUsh4qmpK2M0nsoAoGCCqGSM49 + AwEHoUQDQgAEt6M2nVjW2cwYVpQi7M2k0vwH0q9p5JKH45aFFwefbHUPxM8JUDgg + xLSOIwih0Jx3JObPRCBJexYOpPYJsEwQ1A== + -----END EC PRIVATE KEY----- + From 8cb453176195a584f06742c8e91e87ade56c630b Mon Sep 17 00:00:00 2001 From: wipedlifepotato Date: Tue, 1 Aug 2023 02:43:13 +0700 Subject: [PATCH 27/45] drop assets files --- .../vanitygen.cpp | 467 ------------------ todelete/old_vanity/vain.cpp | 417 ---------------- todelete/old_vanity/vanity.hpp | 66 --- 3 files changed, 950 deletions(-) delete mode 100755 todelete/new_vanity_last_version_from_github/vanitygen.cpp delete mode 100755 todelete/old_vanity/vain.cpp delete mode 100755 todelete/old_vanity/vanity.hpp diff --git a/todelete/new_vanity_last_version_from_github/vanitygen.cpp b/todelete/new_vanity_last_version_from_github/vanitygen.cpp deleted file mode 100755 index 13b3303..0000000 --- a/todelete/new_vanity_last_version_from_github/vanitygen.cpp +++ /dev/null @@ -1,467 +0,0 @@ -#include "Crypto.h" -#include "Identity.h" -#include "I2PEndian.h" -#include "common/key.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef _WIN32 -#include -#endif - -// sha256 -#define Ch(x, y, z) ((x & (y ^ z)) ^ z) -#define Maj(x, y, z) ((x & (y | z)) | (y & z)) -#define SHR(x, n) (x >> n) -#define ROTR(x, n) ((x >> n) | (x << (32 - n))) -#define S0(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22)) -#define S1(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25)) -#define s0(x) (ROTR(x, 7) ^ ROTR(x, 18) ^ SHR(x, 3)) -#define s1(x) (ROTR(x, 17) ^ ROTR(x, 19) ^ SHR(x, 10)) - -#define RND(a, b, c, d, e, f, g, h, k) \ - t0 = h + S1(e) + Ch(e, f, g) + k; \ - t1 = S0(a) + Maj(a, b, c); \ - d += t0; \ - h = t0 + t1; - -#define RNDr(S, W, i, k) \ - RND(S[(64 - i) % 8], S[(65 - i) % 8], \ - S[(66 - i) % 8], S[(67 - i) % 8], \ - S[(68 - i) % 8], S[(69 - i) % 8], \ - S[(70 - i) % 8], S[(71 - i) % 8], \ - W[i] + k) - -#define DEF_OUTNAME "private.dat" - -static bool found = false; -static size_t MutateByte; -static uint8_t * KeyBuf; - -unsigned int count_cpu; - -const uint8_t lastBlock[64] = -{ - 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, 0x0C, 0x38 // 3128 bits (391 bytes) -}; - -static struct -{ - bool reg = false; - int threads = -1; - i2p::data::SigningKeyType signature; - std::string outputpath = ""; - std::regex regex; - bool sig_type = true; -} options; - -void check_sig_type() -{ - if (SigTypeToName(options.signature).find("unknown") != std::string::npos) - { - std::cerr << "Incorrect signature type" << std::endl; - options.sig_type = false; - } -} - -void inline CalculateW (const uint8_t block[64], uint32_t W[64]) -{ -/** - * implementation of orignal - */ - for (int i = 0; i < 16; i++) -#ifdef _WIN32 - W[i] = htobe32(((uint32_t *)(block))[i]); -#else // from big endian to little endian ( swap ) - W[i] = be32toh(((uint32_t *)(block))[i]); -#endif - - for (int i = 16; i < 64; i++) - W[i] = s1(W[i - 2]) + W[i - 7] + s0(W[i - 15]) + W[i - 16]; -} - -void inline TransformBlock (uint32_t state[8], const uint32_t W[64]) -{ -/** - * implementation of orignal - */ - uint32_t S[8]; - memcpy(S, state, 32); - - uint32_t t0, t1; - RNDr(S, W, 0, 0x428a2f98); RNDr(S, W, 1, 0x71374491); RNDr(S, W, 2, 0xb5c0fbcf); RNDr(S, W, 3, 0xe9b5dba5); - RNDr(S, W, 4, 0x3956c25b); RNDr(S, W, 5, 0x59f111f1); RNDr(S, W, 6, 0x923f82a4); RNDr(S, W, 7, 0xab1c5ed5); - RNDr(S, W, 8, 0xd807aa98); RNDr(S, W, 9, 0x12835b01); RNDr(S, W, 10, 0x243185be); RNDr(S, W, 11, 0x550c7dc3); - RNDr(S, W, 12, 0x72be5d74); RNDr(S, W, 13, 0x80deb1fe); RNDr(S, W, 14, 0x9bdc06a7); RNDr(S, W, 15, 0xc19bf174); - RNDr(S, W, 16, 0xe49b69c1); RNDr(S, W, 17, 0xefbe4786); RNDr(S, W, 18, 0x0fc19dc6); RNDr(S, W, 19, 0x240ca1cc); - RNDr(S, W, 20, 0x2de92c6f); RNDr(S, W, 21, 0x4a7484aa); RNDr(S, W, 22, 0x5cb0a9dc); RNDr(S, W, 23, 0x76f988da); - RNDr(S, W, 24, 0x983e5152); RNDr(S, W, 25, 0xa831c66d); RNDr(S, W, 26, 0xb00327c8); RNDr(S, W, 27, 0xbf597fc7); - RNDr(S, W, 28, 0xc6e00bf3); RNDr(S, W, 29, 0xd5a79147); RNDr(S, W, 30, 0x06ca6351); RNDr(S, W, 31, 0x14292967); - RNDr(S, W, 32, 0x27b70a85); RNDr(S, W, 33, 0x2e1b2138); RNDr(S, W, 34, 0x4d2c6dfc); RNDr(S, W, 35, 0x53380d13); - RNDr(S, W, 36, 0x650a7354); RNDr(S, W, 37, 0x766a0abb); RNDr(S, W, 38, 0x81c2c92e); RNDr(S, W, 39, 0x92722c85); - RNDr(S, W, 40, 0xa2bfe8a1); RNDr(S, W, 41, 0xa81a664b); RNDr(S, W, 42, 0xc24b8b70); RNDr(S, W, 43, 0xc76c51a3); - RNDr(S, W, 44, 0xd192e819); RNDr(S, W, 45, 0xd6990624); RNDr(S, W, 46, 0xf40e3585); RNDr(S, W, 47, 0x106aa070); - RNDr(S, W, 48, 0x19a4c116); RNDr(S, W, 49, 0x1e376c08); RNDr(S, W, 50, 0x2748774c); RNDr(S, W, 51, 0x34b0bcb5); - RNDr(S, W, 52, 0x391c0cb3); RNDr(S, W, 53, 0x4ed8aa4a); RNDr(S, W, 54, 0x5b9cca4f); RNDr(S, W, 55, 0x682e6ff3); - RNDr(S, W, 56, 0x748f82ee); RNDr(S, W, 57, 0x78a5636f); RNDr(S, W, 58, 0x84c87814); RNDr(S, W, 59, 0x8cc70208); - RNDr(S, W, 60, 0x90befffa); RNDr(S, W, 61, 0xa4506ceb); RNDr(S, W, 62, 0xbef9a3f7); RNDr(S, W, 63, 0xc67178f2); - - for (int i = 0; i < 8; i++) state[i] += S[i]; -} - -void inline HashNextBlock (uint32_t state[8], const uint8_t * block) -{ -/** - * implementation of orignal - */ - uint32_t W[64]; - CalculateW (block, W); - TransformBlock (state, W); -} - -bool check_prefix(const char * buf) -{ - unsigned short size_str = 0; - while(*buf) - { - if(!((*buf > 49 && *buf < 56) || (*buf > 96 && *buf < 123)) || size_str > 52) - return false; - size_str++; - buf++; - } - return true; -} - -inline size_t ByteStreamToBase32 (const uint8_t * inBuf, size_t len, char * outBuf, size_t outLen) -{ - size_t ret = 0, pos = 1; - int bits = 8, tmp = inBuf[0]; - while (ret < outLen && (bits > 0 || pos < len)) - { - if (bits < 5) - { - if (pos < len) - { - tmp <<= 8; - tmp |= inBuf[pos] & 0xFF; - pos++; - bits += 8; - } - else // last byte - { - tmp <<= (5 - bits); - bits = 5; - } - } - - bits -= 5; - int ind = (tmp >> bits) & 0x1F; - outBuf[ret] = (ind < 26) ? (ind + 'a') : ((ind - 26) + '2'); - ret++; - } - outBuf[ret]='\0'; - return ret; -} - -inline bool NotThat(const char * what, const std::regex & reg){ - return std::regex_match(what,reg) == 1 ? false : true; -} - -inline bool NotThat(const char * a, const char *b) -{ - while(*b) - if(*a++!=*b++) - return true; - return false; -} - -void processFlipper(const std::string string) -{ - constexpr char SYMBOLS[] {'-', '\\', '|', '/'}; - uint8_t symbol_counter = 0; - std::string payload = string; - if (payload.back() != ' ') payload += ' '; - - size_t current_state = payload.size(); - enum { left, right } direction = left; - - std::cout << payload << SYMBOLS[symbol_counter++]; - while (!found) - { - std::cout << '\b' << SYMBOLS[symbol_counter++]; - std::cout.flush(); - - if (symbol_counter == sizeof(SYMBOLS)) - { - if (direction == left) - { - std::cout << '\b'; - std::cout.flush(); - symbol_counter = 0; - if (!--current_state) - { - direction = right; - } - } - else if (direction == right) - { - std::cout << '\b' << payload[current_state] << " "; - std::cout.flush(); - symbol_counter = 0; - - if (++current_state == payload.size()) - { - direction = left; - } - } - } - std::this_thread::sleep_for(std::chrono::milliseconds(80)); - } -} - -bool thread_find(uint8_t * buf, const char * prefix, int id_thread, unsigned long long throughput) -{ - const unsigned long long original_throughput = throughput; - uint8_t b[391]; - uint32_t hash[8]; - - memcpy (b, buf, 391); - - size_t len = 52; - - if (!options.reg) - len = strlen(prefix); - - // precalculate first 5 blocks (320 bytes) - uint32_t state[8] = { 0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19 }; - HashNextBlock (state, b); - HashNextBlock (state, b + 64); - HashNextBlock (state, b + 128); - HashNextBlock (state, b + 192); - HashNextBlock (state, b + 256); - - // pre-calculate last W - uint32_t lastW[64]; - CalculateW (lastBlock, lastW); - - uint32_t * nonce = (uint32_t *)(b+320); - (*nonce) += id_thread*throughput; - - char addr[53]; - uint32_t state1[8]; - - while(!found) - { - if (! throughput--) - { - throughput = original_throughput; - } - - memcpy (state1, state, 32); - // calculate hash of block with nonce - HashNextBlock (state1, b + 320); - // apply last block - TransformBlock (state1, lastW); - // get final hash - for (int j = 8; j--;) - hash[j] = htobe32(state1[j]); - ByteStreamToBase32 ((uint8_t*)hash, 32, addr, len); - - if( options.reg ? !NotThat(addr, options.regex) : !NotThat(addr, prefix) ) - { - ByteStreamToBase32 ((uint8_t*)hash, 32, addr, 52); - std::cout << "\nFound address: " << addr << std::endl; - found = true; - return true; - } - - (*nonce)++; - if (found) - { - break; - } - } - - return true; -} - -void usage(void){ - const constexpr char * help="Usage:\n" - " vain [text-pattern|regex-pattern] [options]\n\n" - "OPTIONS:\n" - " -h --help show this help (same as --usage)\n" - " -r --reg use regexp instead of simple text pattern, ex.: vain '(one|two).*' -r\n" - " -t --threads number of threads to use (default: one per processor)\n" -// " -s --signature (signature type)\n" // NOT IMPLEMENTED FUCKING PLAZ! - " -o --output privkey output file name (default: ./" DEF_OUTNAME ")\n" - ""; - puts(help); -} - -void parsing(int argc, char ** args){ - 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") ){ - usage(); - exit(1); - } - case 'h': - usage(); - exit(0); - break; - case 'r': - options.reg=true; - break; - case 't': - options.threads=atoi(optarg); - break; - case 's': - options.signature = NameToSigType(std::string(optarg)); - check_sig_type(); - 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[]) -{ - if ( argc < 2 ) - { - usage(); - return 0; - } - - parsing( argc > 2 ? argc-1 : argc, argc > 2 ? argv+1 : argv); - // - if(!options.reg && !check_prefix( argv[1] )) - { - std::cout << "Invalid pattern." << std::endl; - usage(); - return 1; - }else{ - options.regex=std::regex(argv[1]); - } - - i2p::crypto::InitCrypto (false, true, true, false); - options.signature = i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519; - - if(options.signature != i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519) - { - std::cout << "ED25519-SHA512 are currently the only signing keys supported." << std::endl; - return 0; - } - - if (!options.sig_type) return -2; - auto keys = i2p::data::PrivateKeys::CreateRandomKeys (options.signature); - switch(options.signature) - { - case i2p::data::SIGNING_KEY_TYPE_DSA_SHA1: - case i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA512_P521: - case i2p::data::SIGNING_KEY_TYPE_RSA_SHA256_2048: - case i2p::data::SIGNING_KEY_TYPE_RSA_SHA384_3072: - case i2p::data::SIGNING_KEY_TYPE_RSA_SHA512_4096: - case i2p::data::SIGNING_KEY_TYPE_GOSTR3410_TC26_A_512_GOSTR3411_512: - std::cout << "Sorry, selected signature type is not supported for address generation." << std::endl; - return 0; - break; - } - -//TODO: for other types. - switch(options.signature) - { - case i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA256_P256: - break; - case i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA384_P384: - break; - case i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA512_P521: - break; - case i2p::data::SIGNING_KEY_TYPE_RSA_SHA256_2048: - break; - case i2p::data::SIGNING_KEY_TYPE_RSA_SHA384_3072: - break; - case i2p::data::SIGNING_KEY_TYPE_RSA_SHA512_4096: - break; - case i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519: - MutateByte=320; - break; - case i2p::data::SIGNING_KEY_TYPE_GOSTR3410_CRYPTO_PRO_A_GOSTR3411_256: - break; - } - - KeyBuf = new uint8_t[keys.GetFullLen()]; - keys.ToBuffer (KeyBuf, keys.GetFullLen ()); - - if(options.threads <= 0) - { - options.threads = std::thread::hardware_concurrency(); - } - - std::cout << "Vanity generator started in " << options.threads << " threads" << std::endl; - - std::vector threads(options.threads); - unsigned long long thoughtput = 0x4F4B5A37; - - for (unsigned int j = options.threads; j--; ) - { - threads[j] = std::thread(thread_find, KeyBuf, argv[1], j, thoughtput); - thoughtput += 1000; - } - - processFlipper(argv[1]); - - for (unsigned int j = 0; j < (unsigned int)options.threads;j++) - threads[j].join(); - - if(options.outputpath.empty()) options.outputpath.assign(DEF_OUTNAME); - - std::ofstream f (options.outputpath, std::ofstream::binary); - if (f) - { - f.write ((char *)KeyBuf, keys.GetFullLen ()); - delete [] KeyBuf; - } - else - std::cout << "Can't create output file: " << options.outputpath << std::endl; - - i2p::crypto::TerminateCrypto (); - - return 0; -} diff --git a/todelete/old_vanity/vain.cpp b/todelete/old_vanity/vain.cpp deleted file mode 100755 index 3c41631..0000000 --- a/todelete/old_vanity/vain.cpp +++ /dev/null @@ -1,417 +0,0 @@ -#include "vanity.hpp" -#include -#include - - -static struct{ - bool reg=false; - int threads=-1; - i2p::data::SigningKeyType signature; - std::string outputpath=""; - std::regex regex; - -}options; - - -static void inline CalculateW (const uint8_t block[64], uint32_t W[64]) -{ -/* -implementation of orignal -*/ - for (int i = 0; i < 16; i++) -#ifdef _WIN32 - W[i] = htobe32(((uint32_t *)(block))[i]); -#else // from big endian to little endian ( swap ) - W[i] = be32toh(((uint32_t *)(block))[i]); -#endif - - for (int i = 16; i < 64; i++) - W[i] = s1(W[i - 2]) + W[i - 7] + s0(W[i - 15]) + W[i - 16]; -} - -static void inline TransformBlock (uint32_t state[8], const uint32_t W[64]) -{ -/* -implementation of orignal -*/ - uint32_t S[8]; - memcpy(S, state, 32); - - uint32_t t0, t1; - RNDr(S, W, 0, 0x428a2f98); RNDr(S, W, 1, 0x71374491); RNDr(S, W, 2, 0xb5c0fbcf); RNDr(S, W, 3, 0xe9b5dba5); - RNDr(S, W, 4, 0x3956c25b); RNDr(S, W, 5, 0x59f111f1); RNDr(S, W, 6, 0x923f82a4); RNDr(S, W, 7, 0xab1c5ed5); - RNDr(S, W, 8, 0xd807aa98); RNDr(S, W, 9, 0x12835b01); RNDr(S, W, 10, 0x243185be); RNDr(S, W, 11, 0x550c7dc3); - RNDr(S, W, 12, 0x72be5d74); RNDr(S, W, 13, 0x80deb1fe); RNDr(S, W, 14, 0x9bdc06a7); RNDr(S, W, 15, 0xc19bf174); - RNDr(S, W, 16, 0xe49b69c1); RNDr(S, W, 17, 0xefbe4786); RNDr(S, W, 18, 0x0fc19dc6); RNDr(S, W, 19, 0x240ca1cc); - RNDr(S, W, 20, 0x2de92c6f); RNDr(S, W, 21, 0x4a7484aa); RNDr(S, W, 22, 0x5cb0a9dc); RNDr(S, W, 23, 0x76f988da); - RNDr(S, W, 24, 0x983e5152); RNDr(S, W, 25, 0xa831c66d); RNDr(S, W, 26, 0xb00327c8); RNDr(S, W, 27, 0xbf597fc7); - RNDr(S, W, 28, 0xc6e00bf3); RNDr(S, W, 29, 0xd5a79147); RNDr(S, W, 30, 0x06ca6351); RNDr(S, W, 31, 0x14292967); - RNDr(S, W, 32, 0x27b70a85); RNDr(S, W, 33, 0x2e1b2138); RNDr(S, W, 34, 0x4d2c6dfc); RNDr(S, W, 35, 0x53380d13); - RNDr(S, W, 36, 0x650a7354); RNDr(S, W, 37, 0x766a0abb); RNDr(S, W, 38, 0x81c2c92e); RNDr(S, W, 39, 0x92722c85); - RNDr(S, W, 40, 0xa2bfe8a1); RNDr(S, W, 41, 0xa81a664b); RNDr(S, W, 42, 0xc24b8b70); RNDr(S, W, 43, 0xc76c51a3); - RNDr(S, W, 44, 0xd192e819); RNDr(S, W, 45, 0xd6990624); RNDr(S, W, 46, 0xf40e3585); RNDr(S, W, 47, 0x106aa070); - RNDr(S, W, 48, 0x19a4c116); RNDr(S, W, 49, 0x1e376c08); RNDr(S, W, 50, 0x2748774c); RNDr(S, W, 51, 0x34b0bcb5); - RNDr(S, W, 52, 0x391c0cb3); RNDr(S, W, 53, 0x4ed8aa4a); RNDr(S, W, 54, 0x5b9cca4f); RNDr(S, W, 55, 0x682e6ff3); - RNDr(S, W, 56, 0x748f82ee); RNDr(S, W, 57, 0x78a5636f); RNDr(S, W, 58, 0x84c87814); RNDr(S, W, 59, 0x8cc70208); - RNDr(S, W, 60, 0x90befffa); RNDr(S, W, 61, 0xa4506ceb); RNDr(S, W, 62, 0xbef9a3f7); RNDr(S, W, 63, 0xc67178f2); - - for (int i = 0; i < 8; i++) state[i] += S[i]; -} - -void inline HashNextBlock (uint32_t state[8], const uint8_t * block) -{ -/* -implementation of orignal -*/ - uint32_t W[64]; - CalculateW (block, W); - TransformBlock (state, W); -} - -static bool check_prefix(const char * buf) -{ - unsigned short size_str=0; - while(*buf) - { - if(*buf < 48 || (*buf > 57 && *buf < 65) || (*buf > 64 && *buf < 94) || *buf > 125 || size_str > 52) - return false; - size_str++; - buf++; - } - return true; -} - -static inline size_t ByteStreamToBase32 (const uint8_t * inBuf, size_t len, char * outBuf, size_t outLen) -{ - size_t ret = 0, pos = 1; - int bits = 8, tmp = inBuf[0]; - while (ret < outLen && (bits > 0 || pos < len)) - { - if (bits < 5) - { - if (pos < len) - { - tmp <<= 8; - tmp |= inBuf[pos] & 0xFF; - pos++; - bits += 8; - } - else // last byte - { - tmp <<= (5 - bits); - bits = 5; - } - } - - bits -= 5; - int ind = (tmp >> bits) & 0x1F; - outBuf[ret] = (ind < 26) ? (ind + 'a') : ((ind - 26) + '2'); - ret++; - } - outBuf[ret]='\0'; - return ret; -} - -static inline bool NotThat(const char * what, const std::regex & reg){ - return std::regex_match(what,reg) == 1 ? false : true; -} - -static inline bool NotThat(const char * a, const char *b) -{ - while(*b) - if(*a++!=*b++) - return true; - return false; -} - -static inline bool thread_find(uint8_t * buf, const char * prefix, int id_thread, unsigned long long throughput) -{ -/* -Thanks to orignal ^-^ -For idea and example ^-^ -Orignal is sensei of crypto ;) -*/ - std::cout << "Thread " << id_thread << " binded" << std::endl; -/* - union - { - uint8_t b[391]; - uint32_t ll; - } local; - union - { - uint8_t b[32]; - uint32_t ll[8]; - } hash; -*/ - uint8_t b[391]; - uint32_t hash[8]; - - memcpy (b, buf, 391); - - auto len = strlen (prefix); - // precalculate first 5 blocks (320 bytes) - uint32_t state[8] = { 0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19 }; - HashNextBlock (state, b); - HashNextBlock (state, b + 64); - HashNextBlock (state, b + 128); - HashNextBlock (state, b + 192); - HashNextBlock (state, b + 256); - - // pre-calculate last W - uint32_t lastW[64]; - CalculateW (lastBlock, lastW); - - uint32_t * nonce = (uint32_t *)(b+320); - (*nonce) += id_thread*throughput; - - char addr[53]; - uint32_t state1[8]; - - while(throughput-- and !found) - { - memcpy (state1, state, 32); - // calculate hash of block with nonce - HashNextBlock (state1, b + 320); - // apply last block - TransformBlock (state1, lastW); - // get final hash - for (int j = 8; j--;) - hash[j] = htobe32(state1[j]); - ByteStreamToBase32 ((uint8_t*)hash, 32, addr, len); - // std::cout << addr << std::endl; - - //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); - std::cout << "Address found " << addr << " in " << id_thread << std::endl; - found=true; - FoundNonce=*nonce; - // free(hash); - // free(b); - return true; - } - - - (*nonce)++; - hashescounter++; - if (found) - { - // free(hash); - // free(b); - break; - } - }//while - return true; -} - - - - - -void usage(void){ - 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 usage\n" - //"--prefix -p\n" - ""; - puts(help); -} - - -void parsing(int argc, char ** args){ - 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") ){ - usage(); - exit(1); - } - case 'h': - usage(); - 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[]) -{ - - - - - if ( argc < 2 ) - { - usage(); - return 0; - } - parsing( argc > 2 ? argc-1 : argc, argc > 2 ? argv+1 : argv); - // - if(!options.reg && !check_prefix( argv[1] )) - { - std::cout << "Not correct prefix(just string)" << std::endl; - return 1; - }else{ - 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; -// } - } - - i2p::crypto::InitCrypto (false); - options.signature = i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519; -/////////////// -//For while - if(options.signature != i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519) - { - std::cout << "For a while only ED25519-SHA512" << std::endl; - return 0; - } -/////////////// - -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - auto keys = i2p::data::PrivateKeys::CreateRandomKeys (options.signature); - switch(options.signature) - { - case i2p::data::SIGNING_KEY_TYPE_DSA_SHA1: - case i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA512_P521: - case i2p::data::SIGNING_KEY_TYPE_RSA_SHA256_2048: - case i2p::data::SIGNING_KEY_TYPE_RSA_SHA384_3072: - case i2p::data::SIGNING_KEY_TYPE_RSA_SHA512_4096: - 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; - return 0; - break; - } - -//TODO: for other types. - switch(options.signature) - { - case i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA256_P256: - break; - case i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA384_P384: - break; - case i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA512_P521: - break; - case i2p::data::SIGNING_KEY_TYPE_RSA_SHA256_2048: - break; - case i2p::data::SIGNING_KEY_TYPE_RSA_SHA384_3072: - break; - case i2p::data::SIGNING_KEY_TYPE_RSA_SHA512_4096: - break; - case i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519: - MutateByte=320; - break; - case i2p::data::SIGNING_KEY_TYPE_GOSTR3410_CRYPTO_PRO_A_GOSTR3411_256: - break; - } - - KeyBuf = new uint8_t[keys.GetFullLen()]; - keys.ToBuffer (KeyBuf, keys.GetFullLen ()); - - if(options.threads <= 0) - { -#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 - } - - std::cout << "Start vanity generator in " << options.threads << " threads" << std::endl; - - unsigned short attempts = 0; - while(!found) - {//while - {//stack(for destructors(vector/thread)) - - std::vector threads(options.threads); - unsigned long long thoughtput = 0x4F4B5A37; - - for ( unsigned int j = options.threads;j--;) - { - threads[j] = std::thread(thread_find,KeyBuf,argv[1],j,thoughtput); - thoughtput+=1000; - }//for - - for(unsigned int j = 0; j < (unsigned int)options.threads;j++) - threads[j].join(); - - if(FoundNonce == 0) - { - RAND_bytes( KeyBuf+MutateByte , 90 ); - std::cout << "Attempts #" << ++attempts << std::endl; - } - - }//stack - }//while - - memcpy (KeyBuf + MutateByte, &FoundNonce, 4); - std::cout << "Hashes: " << hashescounter << std::endl; - - if(options.outputpath.size() == 0) options.outputpath="private.dat"; - - std::ofstream f (options.outputpath, std::ofstream::binary | std::ofstream::out); - if (f) - { - f.write ((char *)KeyBuf, keys.GetFullLen ()); - delete [] KeyBuf; - } - else - std::cout << "Can't create file " << options.outputpath << std::endl; - - i2p::crypto::TerminateCrypto (); - - return 0; -} - - -// diff --git a/todelete/old_vanity/vanity.hpp b/todelete/old_vanity/vanity.hpp deleted file mode 100755 index 453e7f7..0000000 --- a/todelete/old_vanity/vanity.hpp +++ /dev/null @@ -1,66 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include "Crypto.h" -#include "Identity.h" -#include "I2PEndian.h" -#include "common/key.hpp" -#include -#include -#include - -#ifdef _WIN32 -#include -#endif - -// sha256 -#define Ch(x, y, z) ((x & (y ^ z)) ^ z) -#define Maj(x, y, z) ((x & (y | z)) | (y & z)) -#define SHR(x, n) (x >> n) -#define ROTR(x, n) ((x >> n) | (x << (32 - n))) -#define S0(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22)) -#define S1(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25)) -#define s0(x) (ROTR(x, 7) ^ ROTR(x, 18) ^ SHR(x, 3)) -#define s1(x) (ROTR(x, 17) ^ ROTR(x, 19) ^ SHR(x, 10)) - -#define RND(a, b, c, d, e, f, g, h, k) \ - t0 = h + S1(e) + Ch(e, f, g) + k; \ - t1 = S0(a) + Maj(a, b, c); \ - d += t0; \ - h = t0 + t1; - -#define RNDr(S, W, i, k) \ - RND(S[(64 - i) % 8], S[(65 - i) % 8], \ - S[(66 - i) % 8], S[(67 - i) % 8], \ - S[(68 - i) % 8], S[(69 - i) % 8], \ - S[(70 - i) % 8], S[(71 - i) % 8], \ - W[i] + k) - - -//static i2p::data::SigningKeyType type; -//static i2p::data::PrivateKeys keys; -static bool found=false; - -static size_t MutateByte; - -static uint32_t FoundNonce=0; - -static uint8_t * KeyBuf; - -//static uint8_t * PaddingBuf; -static unsigned long long hashescounter; -unsigned int count_cpu; - -const uint8_t lastBlock[64] = - { - 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, 0x0C, 0x38 // 3128 bits (391 bytes) - }; From 51c5ee8968f7b7a9134080c1ba1e444ed0309200 Mon Sep 17 00:00:00 2001 From: wipedlifepotato Date: Fri, 4 Aug 2023 12:13:30 +0700 Subject: [PATCH 28/45] Generate a new full keypair instead just RAND_bytes (will fix bug with bad key format) Also not rewrite exists .dat file if exists before --- vain.cpp | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/vain.cpp b/vain.cpp index 9b23145..1b0e82a 100755 --- a/vain.cpp +++ b/vain.cpp @@ -353,22 +353,7 @@ int main (int argc, char * argv[]) static std::string outPutFileName = options.outputpath; auto doSearch = [argc,argv] () { 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) switch(options.signature) { @@ -441,7 +426,8 @@ int main (int argc, char * argv[]) if(FoundNonce == 0) { - RAND_bytes( KeyBuf+MutateByte , 90 ); // FoundNonce is + keys = i2p::data::PrivateKeys::CreateRandomKeys (options.signature); + //RAND_bytes( KeyBuf+MutateByte , 90 ); // FoundNonce is std::cout << "Attempts #" << ++attempts << std::endl; } @@ -456,7 +442,12 @@ int main (int argc, char * argv[]) // 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; 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++; + }while( boost::filesystem::exists(options.outputpath) ); //if ( ! boost::algorithm::ends_with(options.outputpath, ".dat") ) // options.outputpath = options.outputpath + ".dat"; @@ -464,7 +455,6 @@ int main (int argc, char * argv[]) // before a mining we would to create a dump file 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); if (f) @@ -474,7 +464,7 @@ int main (int argc, char * argv[]) } else std::cout << "Can't create file " << options.outputpath << std::endl; - + return 0; }; // void doSearch lamda do { From a16075f22a8b7c4f8e1831b19158b64bc62d7542 Mon Sep 17 00:00:00 2001 From: wipedlifepotato Date: Sat, 5 Aug 2023 18:11:52 +0700 Subject: [PATCH 29/45] Generate a new full keypair instead just RAND_bytes (will fix bug with bad key format) Also not rewrite exists .dat file if exists before delete much commentaries Do a full new search instead new keypair fix a bug with double increment in multiple search mode --- vain.cpp | 55 ++++++++++++++---------------------------------------- vanity.hpp | 1 + 2 files changed, 15 insertions(+), 41 deletions(-) diff --git a/vain.cpp b/vain.cpp index 1b0e82a..104a36d 100755 --- a/vain.cpp +++ b/vain.cpp @@ -188,14 +188,11 @@ Orignal is sensei of crypto ;) //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); std::cout << "Address found " << addr << " in " << id_thread << std::endl; found=true; FoundNonce=*nonce; - // free(hash); - // free(b); // From there place we get a nonce, for some one a byte. return true; } @@ -203,10 +200,8 @@ Orignal is sensei of crypto ;) (*nonce)++; hashescounter++; - if (found) // for another threads + if (found) // for another threads (?) { - // free(hash); - // free(b); break; } }//while @@ -224,8 +219,6 @@ void usage(void){ "--threads -t (default count of system)\n" //"--signature -s (signature type)\n" "-o --output output file(default " DEF_OUT_FILE ")\n" -//"--usage usage\n" -//"--prefix -p\n" "--multiplymode -m - multiple addresses search" ""; puts(help); @@ -241,18 +234,12 @@ void parsing(int argc, char ** args){ {"signature", required_argument,0,'s'}, {"output", required_argument,0,'o'}, {"multiplymode", no_argument, 0, 'm'}, - //{"usage", no_argument,0,0}, {0,0,0,0} }; int c; while( (c=getopt_long(argc,args, "hrt:s:o:m", long_options, &option_index))!=-1){ switch(c){ - //case 0: - // if ( std::string(long_options[option_index].name) == std::string("usage") ){ - // usage(); - // exit(1); - // } case 'm': multipleSearchMode=true; 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. // if argc size more than 2. nameprogram is 1. and 2 is prefix. if not there is will be flags like regex // TODO: ? - // if(!options.reg && !check_prefix( argv[1] )) { std::cout << "Not correct prefix(just string)" << std::endl; return 1; }else{ 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 //// init and terminate // 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); options.signature = i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519; /////////////// @@ -327,20 +308,6 @@ int main (int argc, char * argv[]) if(options.threads <= 0) { 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,6 +319,7 @@ int main (int argc, char * argv[]) if ( options . outputpath . empty () ) options . outputpath . assign ( DEF_OUT_FILE ) ; 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) @@ -423,12 +391,12 @@ int main (int argc, char * argv[]) // So I put it ^^^ for(unsigned int j = 0; j < (unsigned int)options.threads;j++) threads[j].join(); - if(FoundNonce == 0) { - keys = i2p::data::PrivateKeys::CreateRandomKeys (options.signature); + //keys = i2p::data::PrivateKeys::CreateRandomKeys (options.signature); //RAND_bytes( KeyBuf+MutateByte , 90 ); // FoundNonce is - std::cout << "Attempts #" << ++attempts << std::endl; + std::cout << "(Generate a new keypair) Attempts #" << ++attempts << std::endl; + return 1; } }//stack @@ -447,7 +415,9 @@ int main (int argc, char * argv[]) 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") ) // options.outputpath = options.outputpath + ".dat"; @@ -469,11 +439,14 @@ int main (int argc, char * argv[]) do { 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); - found = false; FoundNonce = 0; - } while(multipleSearchMode); + } while(multipleSearchMode || !found); i2p::crypto::TerminateCrypto (); return 0; diff --git a/vanity.hpp b/vanity.hpp index 0a8a5cd..e552f1c 100755 --- a/vanity.hpp +++ b/vanity.hpp @@ -61,6 +61,7 @@ // Global vars static bool found=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 size_t MutateByte; From 2d06872f528ce26f758223c3b871a2a464e222d8 Mon Sep 17 00:00:00 2001 From: startyourday60 Date: Sun, 27 Aug 2023 13:27:30 +0300 Subject: [PATCH 30/45] (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 31/45] 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 32/45] 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)) From 92989e649af4a3fe1e31889189bde8883456afea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D1=88=D0=B5=20=D0=B8=D0=BC=D1=8F=D1=8D?= Date: Tue, 5 Sep 2023 15:45:03 +0700 Subject: [PATCH 33/45] o2 flag + fedora depedencies support + #92 issue --- Makefile | 2 +- dependencies.sh | 83 +++++++++++++++++++++++++------------------------ vain.cpp | 9 ++---- vanity.hpp | 5 +++ 4 files changed, 51 insertions(+), 48 deletions(-) diff --git a/Makefile b/Makefile index 19130fd..050eff9 100755 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ LIBI2PD_PATH = $(I2PD_PATH)/libi2pd LIBI2PD_CLIENT_PATH = $(I2PD_PATH)/libi2pd_client CXX ?= g++ -CXXFLAGS = -Wall -std=c++17 +CXXFLAGS = -Wall -std=c++17 -O2 INCFLAGS = -I$(LIBI2PD_PATH) -I$(LIBI2PD_CLIENT_PATH) DEFINES = -DOPENSSL_SUPPRESS_DEPRECATED diff --git a/dependencies.sh b/dependencies.sh index d44f3dd..aaddcaf 100755 --- a/dependencies.sh +++ b/dependencies.sh @@ -8,61 +8,64 @@ dependNix="libboost-chrono-dev \ libboost-thread-dev \ libssl-dev \ zlib1g-dev" - dependWin="mingw-w64-x86_64-boost \ mingw-w64-x86_64-openssl \ mingw-w64-x86_64-zlib" -kernel=`uname -a` -function isLsbReleaseExists() { - if which lsb_release > /dev/null; # do whereis can be too? - then - return 0 - else - return 1 - fi +kernel=$(uname -a) + +function anotherDistr() { + echo "Just install libboost and libopenssl dev packages on your pc" + return 0 } -function anotherDistr(){ - echo "Just install libboost and libopenssl dev packages on your pc"; - return 0 +function installDnf() { + sudo dnf install boost-devel g++ } -function installDeb(){ - sudo apt-get install $dependNix; - return 0 +function installDeb() { + sudo apt-get install $dependNix + return 0 } -function installOnGentoo(){ - sudo emerge --deep --newuse dev-libs/boost dev-libs/openssl; - return 0 + +function installOnGentoo() { + sudo emerge --deep --newuse dev-libs/boost dev-libs/openssl + return 0 } + function installOnWin() { - pacman -S $depenWin; - return 0 + pacman -S $dependWin + return 0 } function doInstallDepencies() { -case "$1" in - *Ubuntu*|*Debian*) - installDeb - ;; - *gentoo*) - installOnGentoo - ;; - *MINGW64*) - installOnWin - ;; - *) - anotherDistr - ;; -esac + case "$1" in + *Ubuntu* | *Debian*) + installDeb + ;; + *gentoo*) + installOnGentoo + ;; + *MINGW64*) + installOnWin + ;; + *dnf*) + installDnf + ;; + *) + anotherDistr + ;; + esac } -if isLsbReleaseExists ; -then - distr=`lsb_release -i` - doInstallDepencies "$distr" -else # - doInstallDepencies "$kernel" +isLsbReleaseExists=$(which lsb_release > /dev/null 2>&1; echo $?) +if [ $isLsbReleaseExists -eq 0 ]; then + distr=$(lsb_release -i) + doInstallDepencies "$distr" +elif test -e /etc/fedora-release || which dnf > /dev/null; then + printf "Like you use fedora/redhat distr\n" + doInstallDepencies "dnf" +else + doInstallDepencies "$kernel" fi diff --git a/vain.cpp b/vain.cpp index 4d2993b..148d33f 100755 --- a/vain.cpp +++ b/vain.cpp @@ -404,10 +404,7 @@ 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; + DELKEYBUFS(options.threads); std::cout << "(Generate a new keypair) Attempts #" << ++attempts << std::endl; return 1; } @@ -445,9 +442,7 @@ int main (int argc, char * argv[]) if (f) { f.write ((char *)KeyBuf, keys_len); - for (unsigned i = options.threads-1;i--;) - delete [] KeyBufs[i]; - delete [] KeyBufs; + DELKEYBUFS(options.threads); } else std::cout << "Can't create file " << options.outputpath << std::endl; diff --git a/vanity.hpp b/vanity.hpp index bc9b8f9..6ba379e 100755 --- a/vanity.hpp +++ b/vanity.hpp @@ -84,3 +84,8 @@ const uint8_t lastBlock[64] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x38 // 3128 bits (391 bytes) }; + +#define DELKEYBUFS(S) {\ +for (unsigned i = S-1;i--;) \ + delete [] KeyBufs[i];\ +delete [] KeyBufs;} From d7a079ad644be3e55d2f7c5074a732166ffec19f Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 7 May 2024 18:13:03 -0400 Subject: [PATCH 34/45] updated to 2.51.0 --- famtool.cpp | 11 ++++++++--- i2pd | 2 +- keygen.cpp | 2 +- offlinekeys.cpp | 2 +- regaddr.cpp | 2 +- regaddr_3ld.cpp | 2 +- regaddralias.cpp | 2 +- routerinfo.cpp | 2 +- vain.cpp | 2 +- verifyhost.cpp | 2 +- 10 files changed, 17 insertions(+), 12 deletions(-) diff --git a/famtool.cpp b/famtool.cpp index b117842..c8b5911 100644 --- a/famtool.cpp +++ b/famtool.cpp @@ -197,7 +197,7 @@ int main(int argc, char * argv[]) return 0; } - InitCrypto(false, true, true, false); + InitCrypto(false, true, false); if(!fam.size()) { // no family name @@ -319,7 +319,10 @@ int main(int argc, char * argv[]) delete [] k; } - LocalRouterInfo ri(infofile); + RouterInfo routerInfo(infofile); + LocalRouterInfo ri; + ri.Update (routerInfo.GetBuffer (), routerInfo.GetBufferLen ()); + auto ident = ri.GetIdentHash(); @@ -365,7 +368,9 @@ int main(int argc, char * argv[]) if (verbose) std::cout << "load " << infofile << std::endl; - LocalRouterInfo ri(infofile); + RouterInfo routerInfo(infofile); + LocalRouterInfo ri; + ri.Update (routerInfo.GetBuffer (), routerInfo.GetBufferLen ()); auto sig = ri.GetProperty(ROUTER_INFO_PROPERTY_FAMILY_SIG); if (ri.GetProperty(ROUTER_INFO_PROPERTY_FAMILY) != fam) { std::cout << infofile << " does not belong to " << fam << std::endl; diff --git a/i2pd b/i2pd index a6bd827..c98926a 160000 --- a/i2pd +++ b/i2pd @@ -1 +1 @@ -Subproject commit a6bd8275ca496c75c84d7eb890c0071569d28f55 +Subproject commit c98926abf2dcd3cbe2cbbfc00a9e9159240c3df9 diff --git a/keygen.cpp b/keygen.cpp index 81d184c..30df4a0 100644 --- a/keygen.cpp +++ b/keygen.cpp @@ -12,7 +12,7 @@ int main (int argc, char * argv[]) std::cout << "Usage: keygen filename " << std::endl; return -1; } - i2p::crypto::InitCrypto (false, true, true, false); + i2p::crypto::InitCrypto (false, true, false); i2p::data::SigningKeyType type = i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519; if (argc > 2) { std::string str(argv[2]); diff --git a/offlinekeys.cpp b/offlinekeys.cpp index 473c703..8a4a8c5 100644 --- a/offlinekeys.cpp +++ b/offlinekeys.cpp @@ -14,7 +14,7 @@ int main (int argc, char * argv[]) std::cout << "Usage: offlinekeys " << std::endl; return -1; } - i2p::crypto::InitCrypto (false, true, true, false); + i2p::crypto::InitCrypto (false, true, false); std::string fname(argv[2]); i2p::data::PrivateKeys keys; diff --git a/regaddr.cpp b/regaddr.cpp index 5f16c01..bd560c0 100644 --- a/regaddr.cpp +++ b/regaddr.cpp @@ -12,7 +12,7 @@ int main (int argc, char * argv[]) return -1; } - i2p::crypto::InitCrypto (false, true, true, false); + i2p::crypto::InitCrypto (false, true, false); i2p::data::PrivateKeys keys; std::ifstream s(argv[1], std::ifstream::binary); diff --git a/regaddr_3ld.cpp b/regaddr_3ld.cpp index bb1c703..561bbae 100644 --- a/regaddr_3ld.cpp +++ b/regaddr_3ld.cpp @@ -18,7 +18,7 @@ int main (int argc, char * argv[]) if (argc < 3) { help(); return -1;} std::string arg = argv[1]; - i2p::crypto::InitCrypto (false, true, true, false); + i2p::crypto::InitCrypto (false, true, false); i2p::data::PrivateKeys keys; if (arg == "step1") { diff --git a/regaddralias.cpp b/regaddralias.cpp index 921847e..96eafaa 100644 --- a/regaddralias.cpp +++ b/regaddralias.cpp @@ -12,7 +12,7 @@ int main (int argc, char * argv[]) return -1; } - i2p::crypto::InitCrypto (false, true, true, false); + i2p::crypto::InitCrypto (false, true, false); i2p::data::PrivateKeys oldkeys, newkeys; { diff --git a/routerinfo.cpp b/routerinfo.cpp index a2b1713..a56a273 100644 --- a/routerinfo.cpp +++ b/routerinfo.cpp @@ -46,7 +46,7 @@ int main(int argc, char * argv[]) usage(argv[0]); return 1; } - i2p::crypto::InitCrypto(false, true, true, false); + i2p::crypto::InitCrypto(false, true, false); int opt; bool ipv6 = false; bool firewall = false; diff --git a/vain.cpp b/vain.cpp index 148d33f..f2e11fa 100755 --- a/vain.cpp +++ b/vain.cpp @@ -296,7 +296,7 @@ int main (int argc, char * argv[]) //// init and terminate // void InitCrypto (bool precomputation, bool aesni, bool avx, bool force); // 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, FORCE_CRYPTO); options.signature = i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519; /////////////// //For while diff --git a/verifyhost.cpp b/verifyhost.cpp index 59779ac..482d7f8 100644 --- a/verifyhost.cpp +++ b/verifyhost.cpp @@ -12,7 +12,7 @@ int main (int argc, char * argv[]) return -1; } - i2p::crypto::InitCrypto (false, true, true, false); + i2p::crypto::InitCrypto (false, true, false); i2p::data::IdentityEx Identity, OldIdentity; From 309690575f5804497d4cc169b9f3ccb066e09d9c Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 23 Jul 2024 16:12:24 -0400 Subject: [PATCH 35/45] allow EdDSA for B33 --- b33address.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/b33address.cpp b/b33address.cpp index e239526..59dd96f 100644 --- a/b33address.cpp +++ b/b33address.cpp @@ -14,7 +14,8 @@ int main(int argc, char * argv[]) auto ident = std::make_shared(); if (ident->FromBase64 (base64)) { - if (ident->GetSigningKeyType () == i2p::data::SIGNING_KEY_TYPE_REDDSA_SHA512_ED25519) + if (ident->GetSigningKeyType () == i2p::data::SIGNING_KEY_TYPE_REDDSA_SHA512_ED25519 || + ident->GetSigningKeyType () == i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519) { i2p::data::BlindedPublicKey blindedKey (ident); std::cout << "b33 address: " << blindedKey.ToB33 () << ".b32.i2p" << std::endl; From 8fdec1f30ff0a713275da3b61e230eec58b2064b Mon Sep 17 00:00:00 2001 From: orignal Date: Mon, 2 Sep 2024 10:28:06 -0400 Subject: [PATCH 36/45] swithed to C++17 and std::filesystem --- Makefile | 2 +- i2pd | 2 +- vain.cpp | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 050eff9..818ea36 100755 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ INCFLAGS = -I$(LIBI2PD_PATH) -I$(LIBI2PD_CLIENT_PATH) DEFINES = -DOPENSSL_SUPPRESS_DEPRECATED LDFLAGS = -LDLIBS = $(I2PD_PATH)/$(I2PD_LIB) -lboost_system$(BOOST_SUFFIX) -lboost_date_time$(BOOST_SUFFIX) -lboost_filesystem$(BOOST_SUFFIX) -lboost_program_options$(BOOST_SUFFIX) -lssl -lcrypto -lz +LDLIBS = $(I2PD_PATH)/$(I2PD_LIB) -lboost_system$(BOOST_SUFFIX) -lboost_program_options$(BOOST_SUFFIX) -lssl -lcrypto -lz ifeq ($(UNAME),Linux) diff --git a/i2pd b/i2pd index c98926a..9668ea9 160000 --- a/i2pd +++ b/i2pd @@ -1 +1 @@ -Subproject commit c98926abf2dcd3cbe2cbbfc00a9e9159240c3df9 +Subproject commit 9668ea9338fe8524781d6966f576227775129769 diff --git a/vain.cpp b/vain.cpp index f2e11fa..ddee306 100755 --- a/vain.cpp +++ b/vain.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include //#include //#include // is not supports for me @@ -428,7 +428,7 @@ int main (int argc, char * argv[]) options.outputpath = options.outputpath + std::to_string(foundKeys) + std::string(".dat"); foundKeys++; //printf("foundKeys = %d\n", foundKeys); - }while( boost::filesystem::exists(options.outputpath) ); + }while( std::filesystem::exists(options.outputpath) ); //puts("do while cycle break"); //if ( ! boost::algorithm::ends_with(options.outputpath, ".dat") ) // options.outputpath = options.outputpath + ".dat"; From 35a2e59dc7f3c6a79700d2a881009b4ee33a39d6 Mon Sep 17 00:00:00 2001 From: WipedLifePotato Date: Thu, 19 Sep 2024 16:21:36 +0700 Subject: [PATCH 37/45] AutoConf program pre-init --- Makefile | 8 ++- autoconf.cpp | 171 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 177 insertions(+), 2 deletions(-) create mode 100644 autoconf.cpp diff --git a/Makefile b/Makefile index 818ea36..6af1fe0 100755 --- a/Makefile +++ b/Makefile @@ -45,9 +45,13 @@ else endif -all: $(I2PD_LIB) vain keygen keyinfo famtool routerinfo regaddr regaddr_3ld i2pbase64 offlinekeys b33address regaddralias x25519 verifyhost +all: $(I2PD_LIB) vain keygen keyinfo famtool routerinfo regaddr regaddr_3ld i2pbase64 offlinekeys b33address regaddralias x25519 verifyhost autoconf vain: vain.o $(I2PD_LIB) $(CXX) -o vain $(LDFLAGS) vain.o $(LDLIBS) + +autoconf: autoconf.o $(I2PD_LIB) + $(CXX) -o autoconf $(DEFINES) $(LDFLAGS) autoconf.o $(LDLIBS) + routerinfo: routerinfo.o $(I2PD_LIB) $(CXX) -o routerinfo $(LDFLAGS) routerinfo.o $(LDLIBS) -latomic @@ -103,7 +107,7 @@ clean-obj: rm -f $(wildcard *.o) clean-bin: - rm -f b33address famtool i2pbase64 keygen keyinfo offlinekeys regaddr regaddr_3ld regaddralias routerinfo x25519 verifyhost vain + rm -f b33address famtool i2pbase64 keygen keyinfo offlinekeys regaddr regaddr_3ld regaddralias routerinfo x25519 verifyhost vain autoconf clean: clean-i2pd clean-obj clean-bin diff --git a/autoconf.cpp b/autoconf.cpp new file mode 100644 index 0000000..d435b3f --- /dev/null +++ b/autoconf.cpp @@ -0,0 +1,171 @@ +#ifndef AUTOCONFC +#define AUTOCONFC +#include +#include +#include +#include +#include +namespace AutoConf { +namespace PreInitConfigs { + constexpr const char * yggOnlyConf = "ipv4=false\r\n" + "ipv6=false\r\n" + "ssu=false\r\n" + "ntcp2.enabled=false\r\n" + "ssu2.enabled=false\r\n" + "meshnets.yggdrasil=true\r\n"; +} +// Texts +using AsksT = std::map; +const std::map Texts = // maybe vector better + { + {"ru", { + {"WelcomeText","Привет. Выбери тип конфига\r\n1 - клирнет\r\n2 - только yggdrasil"}, + // Without section + {"TunConfYN", "Использовать другой путь для туннелей?"}, + {"TunConf", "Введите путь для туннелей"}, + {"TunnelsDirYN", "Использовать другой путь для папки туннелей?"}, + {"TunnelsDir","Введите путь для папки с туннелями"}, + {"certsdirYN", "Использовать другой путь для папки с сертификатами?"}, + {"certsdir", "Введите путь для папки с сертификатами"}, + {"pidfileYN","использовать другой путь для PID файла?"}, + {"pidfile", "Введите путь для pidfile"}, + {"logYN","Нужно ли изменить путь лога?"}, + {"log", "Введите тип лога(file,stdout,syslog)"}, + {"logfileYN","Нужно ли изменить путь logfile?"}, + {"logfile", "Введите путь logfile"}, + {"loglevelYN","Нужно ли изменить стандартный уровень логирования?"}, + {"loglevel","Введите уровень лога(warn,info,none,critical,error,debug)"}, + {"logCFLYN", "Использовать полный CFL-форму даты в логах? ПО умолчанию только время"}, + {"daemonYN", "Использовать режим демона?"}, + {"FamilyUsing", "Введите название фамилии или enter просто"}, + //TODO: an another + {"UseIPv6", "Использовать ipv6?"}, + {"UseIPv4", "Использовать ipv4?"}, + {"BeFloodfill", "Быть флудфиллом?"}, + {"NoTransit", "Отключить транзит? (это уменьшит анонимность)"} + }}, + {"en", { + {"WelcomeText","Hello. Select type of config\r\n1 - clearnet\r\n2 - only yggdrasil"}, + {"TunConfYN", "Use a different path for tunnels?"}, + {"TunConf", "Enter path for tunnels"}, + {"TunnelsDirYN", "Use a different path for the tunnels folder?"}, + {"TunnelsDir", "Enter path for the tunnels folder"}, + {"certsdirYN", "Use a different path for the certificates folder?"}, + {"certsdir", "Enter path for the certificates folder"}, + {"pidfileYN", "Use a different path for the PID file?"}, + {"pidfile", "Enter path for pidfile"}, + {"logYN", "Do you need to change the log path?"}, + {"log", "Enter log type (file, stdout, syslog)"}, + {"logfileYN", "Do you need to change the logfile path?"}, + {"logfile", "Enter path for logfile"}, + {"loglevelYN", "Do you need to change the default log level?"}, + {"loglevel", "Enter log level (warn, info, none, critical, error, debug)"}, + {"logCFLYN", "Use full CFL format for date in logs? Default is only time."}, + {"daemonYN", "Use daemon mode?"}, + {"FamilyUsing", "Enter your last name or just hit enter."}, + //TODO: an another + {"UseIPv6", "Use ipv6?"}, + {"UseIPv4", "Use ipv4?"}, + {"BeFloodfill", "Be a floodfill?"}, + {"NoTransit", "Disable transit? (this will reduce anonymity)"} + }} + }; + +// Functions +bool AskYN(void) noexcept { + char answ; + std::cout << " ? (y/n) "; + std::cin >> answ; + switch(answ) { + case 'y': + case 'Y': + return true; + case 'n': + case 'N': + return false; + default: + return AskYN(); // stack overflow, would use while(true) + } +} +std::string GetLanguage(void) noexcept { + std::string lang; + std::cout << "Language/Язык:\r\nru - русский\r\nen - английский\r\n"; + std::cin >> lang; + if (Texts.find(lang) != Texts.end()) { + return lang; + } else { + std::cerr << "Not correct language, try again" << std::endl; + return GetLanguage(); // stack overflow + } +} + +bool IsOnlyYggdrasil(const std::string & lang) noexcept { + unsigned short answ; + std::cout << AutoConf::Texts.at(lang).at("WelcomeText") << std::endl; + std::cin >> answ; + switch(answ) { + case 1: + return false; + case 2: + return true; + default: + return IsOnlyYggdrasil(lang); + } +} + +} + +int +main(void) { + std::cout << "https://i2pd.readthedocs.io/en/latest/user-guide/configuration/\r\nhttps://github.com/PurpleI2P/i2pd/blob/openssl/contrib/i2pd.conf\r\n"; + std::ostringstream conf; + auto lang = AutoConf::GetLanguage(); + auto isOnlyYgg = AutoConf::IsOnlyYggdrasil(lang); + if (isOnlyYgg) { + #ifndef _WIN32 + conf << "daemon=true\r\n"; + #endif + conf << AutoConf::PreInitConfigs::yggOnlyConf; + } else { + // Asks + using namespace AutoConf; + [](std::ostringstream &conf, const std::string &lang) { + std::cout << AutoConf::Texts.at(lang).at("TunConfYN") << std::endl; + if (AskYN()) { + std::cout << AutoConf::Texts.at(lang).at("TunConf") << "\r\n"; + std::string tunConf; + std::cin.ignore(); + std::getline(std::cin, tunConf); + conf << "tunnels.path=" << tunConf << "\r\n"; + } + + std::cout << AutoConf::Texts.at(lang).at("TunnelsDirYN") << std::endl; + if (AskYN()) { + std::cout << AutoConf::Texts.at(lang).at("TunnelsDir") << "\r\n"; + std::string tunnelsDir; + std::cin.ignore(); + std::getline(std::cin, tunnelsDir); + conf << "tunnels.dir=" << tunnelsDir << "\r\n"; + } + + // TODO: + { + std::cout << AutoConf::Texts.at(lang).at("UseIPv6") << "\r\n"; + bool useIPv6 = AskYN(); + conf << "ipv6=" << (useIPv6 ? "true" : "false") << "\r\n"; + } + + { + std::cout << AutoConf::Texts.at(lang).at("UseIPv4") << "\r\n"; + bool useIPv4 = AskYN(); + conf << "ipv4=" << (useIPv4 ? "true" : "false") << "\r\n"; + } + }(conf, lang); + } + std::cout << "Config: " << std::endl; + std::cout << conf.str() << std::endl; + std::ofstream confFile("i2pd_.conf"); + confFile << conf.str(); + confFile.close(); +} +#endif From 205f7c61ae37cb31008303983a5fd05b3973964b Mon Sep 17 00:00:00 2001 From: WipedLifePotato Date: Thu, 19 Sep 2024 21:11:33 +0700 Subject: [PATCH 38/45] [AutoConf] FirstSection --- autoconf.cpp | 77 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 29 deletions(-) diff --git a/autoconf.cpp b/autoconf.cpp index d435b3f..4d06205 100644 --- a/autoconf.cpp +++ b/autoconf.cpp @@ -41,7 +41,7 @@ const std::map Texts = // maybe vector better //TODO: an another {"UseIPv6", "Использовать ipv6?"}, {"UseIPv4", "Использовать ipv4?"}, - {"BeFloodfill", "Быть флудфиллом?"}, + {"BeFloodfillYN", "Быть флудфиллом?"}, {"NoTransit", "Отключить транзит? (это уменьшит анонимность)"} }}, {"en", { @@ -66,7 +66,7 @@ const std::map Texts = // maybe vector better //TODO: an another {"UseIPv6", "Use ipv6?"}, {"UseIPv4", "Use ipv4?"}, - {"BeFloodfill", "Be a floodfill?"}, + {"BeFloodfillYN", "Be a floodfill?"}, {"NoTransit", "Disable transit? (this will reduce anonymity)"} }} }; @@ -130,41 +130,60 @@ main(void) { // Asks using namespace AutoConf; [](std::ostringstream &conf, const std::string &lang) { - std::cout << AutoConf::Texts.at(lang).at("TunConfYN") << std::endl; - if (AskYN()) { - std::cout << AutoConf::Texts.at(lang).at("TunConf") << "\r\n"; - std::string tunConf; - std::cin.ignore(); - std::getline(std::cin, tunConf); - conf << "tunnels.path=" << tunConf << "\r\n"; - } - - std::cout << AutoConf::Texts.at(lang).at("TunnelsDirYN") << std::endl; - if (AskYN()) { - std::cout << AutoConf::Texts.at(lang).at("TunnelsDir") << "\r\n"; - std::string tunnelsDir; - std::cin.ignore(); - std::getline(std::cin, tunnelsDir); - conf << "tunnels.dir=" << tunnelsDir << "\r\n"; - } + #define ASKYN_MACRO(A,B,C) { \ + std::cout << AutoConf::Texts.at(lang).at(A) << std::endl; \ + if(AskYN()) { \ + std::cout << AutoConf::Texts.at(lang).at(B) << "\r\n"; \ + std::string inp; \ + std::cin.ignore(); \ + std::getline(std::cin, inp); \ + conf << C "=" << inp << "\r\n"; \ + } \ + }; + ASKYN_MACRO("TunConfYN","TunConf","tunconf"); + ASKYN_MACRO("TunnelsDirYN","TunnelsDir","tunnelsdir"); // TODO: - { - std::cout << AutoConf::Texts.at(lang).at("UseIPv6") << "\r\n"; - bool useIPv6 = AskYN(); - conf << "ipv6=" << (useIPv6 ? "true" : "false") << "\r\n"; - } + /* + {"daemonYN", "Use daemon mode?"}, + {"FamilyUsing", "Enter your last name or just hit enter."}, - { - std::cout << AutoConf::Texts.at(lang).at("UseIPv4") << "\r\n"; - bool useIPv4 = AskYN(); - conf << "ipv4=" << (useIPv4 ? "true" : "false") << "\r\n"; + */ + ASKYN_MACRO("certsdirYN","certsdir","certsdir"); + ASKYN_MACRO("pidfileYN","pidfile","pidfile"); + ASKYN_MACRO("logYN","log","log"); + ASKYN_MACRO("loglevelYN","loglevel","loglevel"); + #define ASK_BOOL(A,B) { \ + std::cout << AutoConf::Texts.at(lang).at(A) << std::endl; \ + bool v = AskYN();\ + conf << B "=" << (v ? "true":"false") << "\r\n";\ } + ASK_BOOL("UseIPv6", "ipv6"); + ASK_BOOL("UseIPv4", "ipv4"); + ASK_BOOL("logCFLYN", "logclftime"); + ASK_BOOL("daemonYN", "daemon"); + #define ASK_TEXT(A, B) {\ + std::cout << AutoConf::Texts.at(lang).at(A) << std::endl;\ + std::string inp; std::cin.ignore(); std::getline(std::cin, inp);; if (inp.length() != 0) {\ + conf << B "=" << inp << "\r\n";\ + }\ + } + ASK_TEXT("FamilyUsing","family"); + ASK_BOOL("BeFloodfillYN", "floodflill"); + + ///// }(conf, lang); } std::cout << "Config: " << std::endl; std::cout << conf.str() << std::endl; - std::ofstream confFile("i2pd_.conf"); + //TODO: To Constexpr + std::cout << "Save File: (\"i2pd_.conf\"):"; + std::string outFileName; + std::cin.ignore(); //maybe not need write everywhere cin.ignore() one time maybe will be enough + std::getline(std::cin, outFileName); + //TODO: to constxpr + if (outFileName.length() == 0) outFileName = "i2pd_.conf"; + std::ofstream confFile(outFileName); confFile << conf.str(); confFile.close(); } From 73c3b9ef8ce9b5da102083643fa42c60f9d6d137 Mon Sep 17 00:00:00 2001 From: WipedLifePotato Date: Thu, 19 Sep 2024 21:38:16 +0700 Subject: [PATCH 39/45] [AutoConf] SSU2, NTCP2 --- autoconf.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 8 deletions(-) diff --git a/autoconf.cpp b/autoconf.cpp index 4d06205..45c8d47 100644 --- a/autoconf.cpp +++ b/autoconf.cpp @@ -5,6 +5,9 @@ #include #include #include +#include +#define CIN_CLEAR std::cin.clear(); std::cin.ignore(std::numeric_limits::max(), '\n'); + namespace AutoConf { namespace PreInitConfigs { constexpr const char * yggOnlyConf = "ipv4=false\r\n" @@ -14,6 +17,7 @@ namespace PreInitConfigs { "ssu2.enabled=false\r\n" "meshnets.yggdrasil=true\r\n"; } + // Texts using AsksT = std::map; const std::map Texts = // maybe vector better @@ -42,7 +46,18 @@ const std::map Texts = // maybe vector better {"UseIPv6", "Использовать ipv6?"}, {"UseIPv4", "Использовать ipv4?"}, {"BeFloodfillYN", "Быть флудфиллом?"}, - {"NoTransit", "Отключить транзит? (это уменьшит анонимность)"} + {"NoTransitYN", "Отключить транзит? (это уменьшит анонимность)"}, + {"Bandwidth", "Напиши пропускную способность (Enter для по умолчанию) [L-32kbs,O-256kbs,P-2048kbs,X-unlimited]"}, + {"Share", "Процент шары (Enter для по умолчанию) [0-100]"}, + // + {"NTCPEnabledYN", "Использовать NTCP?"}, + {"NTCPPublishedYN", "Опубликовать IP В NTCP?"}, + {"NTCPPPort", "NTCP Порт. Либо энтер для пропуска"}, + {"NTCPPProxy", "NTCP Proxy, пример (socks://localhost:4545) или энтер для поумолчанию (неиспользуется)"}, + {"SSUEnabledYN", "Использовать SSU?"}, + {"SSUPPort", "SSU Порт. Либо энтер для пропуска"}, + {"SSUProxy", "SSU Proxy, пример (socks://localhost:4545) или энтер для поумолчанию (неиспользуется)"} + }}, {"en", { {"WelcomeText","Hello. Select type of config\r\n1 - clearnet\r\n2 - only yggdrasil"}, @@ -62,12 +77,23 @@ const std::map Texts = // maybe vector better {"loglevel", "Enter log level (warn, info, none, critical, error, debug)"}, {"logCFLYN", "Use full CFL format for date in logs? Default is only time."}, {"daemonYN", "Use daemon mode?"}, - {"FamilyUsing", "Enter your last name or just hit enter."}, + {"FamilyUsing", "Enter your netfamily or just hit enter."}, //TODO: an another {"UseIPv6", "Use ipv6?"}, {"UseIPv4", "Use ipv4?"}, {"BeFloodfillYN", "Be a floodfill?"}, - {"NoTransit", "Disable transit? (this will reduce anonymity)"} + {"NoTransitYN", "Disable transit? (this will reduce anonymity)"}, + {"Bandwidth", "Write bandwidth (enter for default) [L-32kbs,O-256kbs,P-2048kbs,X-unlimited]"}, + {"Share", "Share percents (enter for default) [0-100]"}, + // + {"NTCPEnabledYN", "Use NTCP?"}, + {"NTCPPublishedYN", "Publish IP in NTCP?"}, + {"NTCPPPort", "NTCP Port or enter for auto port (random)"}, + {"NTCPPProxy", "NTCP Proxy, example (socks://localhost:4545) or enter for default"}, + {"SSUEnabledYN", "Use SSU?"}, + {"SSUPPort", "SSU Port or enter for auto port (random)"}, + {"SSUProxy", "SSU Proxy, example (socks://localhost:4545) or enter for default"} + }} }; @@ -75,6 +101,7 @@ const std::map Texts = // maybe vector better bool AskYN(void) noexcept { char answ; std::cout << " ? (y/n) "; + CIN_CLEAR; std::cin >> answ; switch(answ) { case 'y': @@ -130,13 +157,12 @@ main(void) { // Asks using namespace AutoConf; [](std::ostringstream &conf, const std::string &lang) { - #define ASKYN_MACRO(A,B,C) { \ std::cout << AutoConf::Texts.at(lang).at(A) << std::endl; \ if(AskYN()) { \ std::cout << AutoConf::Texts.at(lang).at(B) << "\r\n"; \ std::string inp; \ - std::cin.ignore(); \ + CIN_CLEAR; \ std::getline(std::cin, inp); \ conf << C "=" << inp << "\r\n"; \ } \ @@ -164,14 +190,30 @@ main(void) { ASK_BOOL("daemonYN", "daemon"); #define ASK_TEXT(A, B) {\ std::cout << AutoConf::Texts.at(lang).at(A) << std::endl;\ - std::string inp; std::cin.ignore(); std::getline(std::cin, inp);; if (inp.length() != 0) {\ + std::string inp; CIN_CLEAR; std::getline(std::cin, inp); if (inp.length() > 0) {\ conf << B "=" << inp << "\r\n";\ }\ } ASK_TEXT("FamilyUsing","family"); ASK_BOOL("BeFloodfillYN", "floodflill"); + ASK_BOOL("NoTransitYN", "transit"); + ASK_TEXT("Bandwidth","bandwidth"); + ASK_TEXT("Share","share"); + ///// With sections + conf << "[ntcp2]\r\n"; + ASK_BOOL("NTCPEnabledYN", "enabled"); + ASK_BOOL("NTCPPublishedYN", "publish"); + ASK_TEXT("NTCPPPort", "port"); + ASK_TEXT("NTCPPProxy", "proxy"); + conf << "[ssu2]\r\n"; + ASK_BOOL("SSUEnabledYN", "enabled"); + ASK_TEXT("SSUPPort", "port"); + ASK_TEXT("SSUProxy", "proxy"); + + #undef ASK_TEXT + #undef ASK_BOOL + #undef ASKYN_MACRO - ///// }(conf, lang); } std::cout << "Config: " << std::endl; @@ -179,7 +221,7 @@ main(void) { //TODO: To Constexpr std::cout << "Save File: (\"i2pd_.conf\"):"; std::string outFileName; - std::cin.ignore(); //maybe not need write everywhere cin.ignore() one time maybe will be enough + std::cin.clear(); std::getline(std::cin, outFileName); //TODO: to constxpr if (outFileName.length() == 0) outFileName = "i2pd_.conf"; From 7e4d2c73cd1edf884620541e9b7543ace9589208 Mon Sep 17 00:00:00 2001 From: WipedLifePotato Date: Fri, 20 Sep 2024 12:49:25 +0700 Subject: [PATCH 40/45] [AutoConf] Fix multiply input, regex pre-init --- autoconf.cpp | 85 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 51 insertions(+), 34 deletions(-) diff --git a/autoconf.cpp b/autoconf.cpp index 45c8d47..1ed6596 100644 --- a/autoconf.cpp +++ b/autoconf.cpp @@ -6,9 +6,18 @@ #include #include #include +#include + #define CIN_CLEAR std::cin.clear(); std::cin.ignore(std::numeric_limits::max(), '\n'); namespace AutoConf { + namespace Regexps { + //const std::regex port("\\d{1,5}"); + std::regex path(R"([a-zA-Z0-9_\.\/\\]+)"); // (\w|\.|\\|\/)+ + std::regex proxy("\\w+:\\/\\/(\\w|\\d|\\.|\\-)+\\:\\d+"); + std::regex any(".*"); + + } namespace PreInitConfigs { constexpr const char * yggOnlyConf = "ipv4=false\r\n" "ipv6=false\r\n" @@ -41,22 +50,22 @@ const std::map Texts = // maybe vector better {"loglevel","Введите уровень лога(warn,info,none,critical,error,debug)"}, {"logCFLYN", "Использовать полный CFL-форму даты в логах? ПО умолчанию только время"}, {"daemonYN", "Использовать режим демона?"}, - {"FamilyUsing", "Введите название фамилии или enter просто"}, + {"FamilyUsing", "Введите название фамилии или -"}, //TODO: an another {"UseIPv6", "Использовать ipv6?"}, {"UseIPv4", "Использовать ipv4?"}, {"BeFloodfillYN", "Быть флудфиллом?"}, {"NoTransitYN", "Отключить транзит? (это уменьшит анонимность)"}, - {"Bandwidth", "Напиши пропускную способность (Enter для по умолчанию) [L-32kbs,O-256kbs,P-2048kbs,X-unlimited]"}, - {"Share", "Процент шары (Enter для по умолчанию) [0-100]"}, + {"Bandwidth", "Напиши пропускную способность (- для по умолчанию) [L-32kbs,O-256kbs,P-2048kbs,X-unlimited]"}, + {"Share", "Процент шары (- для по умолчанию) [0-100]"}, // {"NTCPEnabledYN", "Использовать NTCP?"}, {"NTCPPublishedYN", "Опубликовать IP В NTCP?"}, - {"NTCPPPort", "NTCP Порт. Либо энтер для пропуска"}, - {"NTCPPProxy", "NTCP Proxy, пример (socks://localhost:4545) или энтер для поумолчанию (неиспользуется)"}, + {"NTCPPPort", "NTCP Порт. Либо - для пропуска"}, + {"NTCPPProxy", "NTCP Proxy, пример (socks://localhost:4545) или - для по умолчанию (неиспользуется)"}, {"SSUEnabledYN", "Использовать SSU?"}, - {"SSUPPort", "SSU Порт. Либо энтер для пропуска"}, - {"SSUProxy", "SSU Proxy, пример (socks://localhost:4545) или энтер для поумолчанию (неиспользуется)"} + {"SSUPPort", "SSU Порт. Либо - для пропуска"}, + {"SSUProxy", "SSU Proxy, пример (socks://localhost:4545) или - для по умолчанию (неиспользуется)"} }}, {"en", { @@ -77,22 +86,22 @@ const std::map Texts = // maybe vector better {"loglevel", "Enter log level (warn, info, none, critical, error, debug)"}, {"logCFLYN", "Use full CFL format for date in logs? Default is only time."}, {"daemonYN", "Use daemon mode?"}, - {"FamilyUsing", "Enter your netfamily or just hit enter."}, + {"FamilyUsing", "Enter your netfamily or just hit -."}, //TODO: an another {"UseIPv6", "Use ipv6?"}, {"UseIPv4", "Use ipv4?"}, {"BeFloodfillYN", "Be a floodfill?"}, {"NoTransitYN", "Disable transit? (this will reduce anonymity)"}, - {"Bandwidth", "Write bandwidth (enter for default) [L-32kbs,O-256kbs,P-2048kbs,X-unlimited]"}, - {"Share", "Share percents (enter for default) [0-100]"}, + {"Bandwidth", "Write bandwidth (- for default) [L-32kbs,O-256kbs,P-2048kbs,X-unlimited]"}, + {"Share", "Share percents (- for default) [0-100]"}, // {"NTCPEnabledYN", "Use NTCP?"}, {"NTCPPublishedYN", "Publish IP in NTCP?"}, - {"NTCPPPort", "NTCP Port or enter for auto port (random)"}, - {"NTCPPProxy", "NTCP Proxy, example (socks://localhost:4545) or enter for default"}, + {"NTCPPPort", "NTCP Port or - for auto port (random)"}, + {"NTCPPProxy", "NTCP Proxy, example (socks://localhost:4545) or - for default"}, {"SSUEnabledYN", "Use SSU?"}, - {"SSUPPort", "SSU Port or enter for auto port (random)"}, - {"SSUProxy", "SSU Proxy, example (socks://localhost:4545) or enter for default"} + {"SSUPPort", "SSU Port or - for auto port (random)"}, + {"SSUProxy", "SSU Proxy, example (socks://localhost:4545) or - for default"} }} }; @@ -101,8 +110,9 @@ const std::map Texts = // maybe vector better bool AskYN(void) noexcept { char answ; std::cout << " ? (y/n) "; - CIN_CLEAR; std::cin >> answ; + CIN_CLEAR; + std::cout <<"answ: " << answ<> lang; + CIN_CLEAR; if (Texts.find(lang) != Texts.end()) { return lang; } else { @@ -130,6 +141,7 @@ bool IsOnlyYggdrasil(const std::string & lang) noexcept { unsigned short answ; std::cout << AutoConf::Texts.at(lang).at("WelcomeText") << std::endl; std::cin >> answ; + CIN_CLEAR; switch(answ) { case 1: return false; @@ -144,6 +156,7 @@ bool IsOnlyYggdrasil(const std::string & lang) noexcept { int main(void) { + std::cout << "RUn Program" << std::endl; std::cout << "https://i2pd.readthedocs.io/en/latest/user-guide/configuration/\r\nhttps://github.com/PurpleI2P/i2pd/blob/openssl/contrib/i2pd.conf\r\n"; std::ostringstream conf; auto lang = AutoConf::GetLanguage(); @@ -157,28 +170,32 @@ main(void) { // Asks using namespace AutoConf; [](std::ostringstream &conf, const std::string &lang) { - #define ASKYN_MACRO(A,B,C) { \ - std::cout << AutoConf::Texts.at(lang).at(A) << std::endl; \ + #define ASKYN_MACRO(A,B,C, REGEX) { \ + std::cout << "Cycle" << std::endl;\ + std::cout << AutoConf::Texts.at(lang).at(A); \ if(AskYN()) { \ + while(1) {\ + std::cout << "Cycle1" << std::endl;\ std::cout << AutoConf::Texts.at(lang).at(B) << "\r\n"; \ std::string inp; \ + std::cin >> inp;\ CIN_CLEAR; \ - std::getline(std::cin, inp); \ - conf << C "=" << inp << "\r\n"; \ - } \ + std::smatch bmatch;\ + std::regex_match(inp, bmatch, REGEX);\ + if (bmatch.length() > 0) {\ + conf << C "=" << inp << "\r\n"; \ + break;\ + }else {std::cerr<<"No correct input"< 0) {\ + std::string inp; std::cin >> inp;CIN_CLEAR; if (inp != "-") {\ conf << B "=" << inp << "\r\n";\ }\ } @@ -209,7 +227,6 @@ main(void) { ASK_BOOL("SSUEnabledYN", "enabled"); ASK_TEXT("SSUPPort", "port"); ASK_TEXT("SSUProxy", "proxy"); - #undef ASK_TEXT #undef ASK_BOOL #undef ASKYN_MACRO From 90905e35159e2624d21191d5c3b5dee315642a8e Mon Sep 17 00:00:00 2001 From: WipedLifePotato Date: Fri, 20 Sep 2024 13:15:45 +0700 Subject: [PATCH 41/45] [AutoConf] Fix options name --- autoconf.cpp | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/autoconf.cpp b/autoconf.cpp index 1ed6596..c687ab5 100644 --- a/autoconf.cpp +++ b/autoconf.cpp @@ -9,12 +9,13 @@ #include #define CIN_CLEAR std::cin.clear(); std::cin.ignore(std::numeric_limits::max(), '\n'); - +#define HTTP_SUPPORTS_LANGUAGE "german, italian, polish, portuguese, russian, spanish, turkish, turkmen, ukrainian, uzbek" namespace AutoConf { + // namespace Regexps { //const std::regex port("\\d{1,5}"); std::regex path(R"([a-zA-Z0-9_\.\/\\]+)"); // (\w|\.|\\|\/)+ - std::regex proxy("\\w+:\\/\\/(\\w|\\d|\\.|\\-)+\\:\\d+"); + //std::regex proxy("\\w+:\\/\\/(\\w|\\d|\\.|\\-)+\\:\\d+"); std::regex any(".*"); } @@ -65,8 +66,8 @@ const std::map Texts = // maybe vector better {"NTCPPProxy", "NTCP Proxy, пример (socks://localhost:4545) или - для по умолчанию (неиспользуется)"}, {"SSUEnabledYN", "Использовать SSU?"}, {"SSUPPort", "SSU Порт. Либо - для пропуска"}, - {"SSUProxy", "SSU Proxy, пример (socks://localhost:4545) или - для по умолчанию (неиспользуется)"} - + {"SSUProxy", "SSU Proxy, пример (socks://localhost:4545) или - для по умолчанию (неиспользуется)"}, + {"HTTPLang", "Выбрите язык веб-интерфейса, либо - для опции по умолчанию (" HTTP_SUPPORTS_LANGUAGE ")" } }}, {"en", { {"WelcomeText","Hello. Select type of config\r\n1 - clearnet\r\n2 - only yggdrasil"}, @@ -94,6 +95,7 @@ const std::map Texts = // maybe vector better {"NoTransitYN", "Disable transit? (this will reduce anonymity)"}, {"Bandwidth", "Write bandwidth (- for default) [L-32kbs,O-256kbs,P-2048kbs,X-unlimited]"}, {"Share", "Share percents (- for default) [0-100]"}, + {"HTTPLang", "Select Web-interface language or - for default (" HTTP_SUPPORTS_LANGUAGE ")" }, // {"NTCPEnabledYN", "Use NTCP?"}, {"NTCPPublishedYN", "Publish IP in NTCP?"}, @@ -112,7 +114,6 @@ bool AskYN(void) noexcept { std::cout << " ? (y/n) "; std::cin >> answ; CIN_CLEAR; - std::cout <<"answ: " << answ<> inp;\ @@ -189,12 +187,11 @@ main(void) { } \ }\ }; - std::cout << "ASKYN" << std::endl; ASKYN_MACRO("TunConfYN","TunConf","tunconf", AutoConf::Regexps::path); ASKYN_MACRO("TunnelsDirYN","TunnelsDir","tunnelsdir",AutoConf::Regexps::path); ASKYN_MACRO("certsdirYN","certsdir","certsdir",AutoConf::Regexps::path); ASKYN_MACRO("pidfileYN","pidfile","pidfile",AutoConf::Regexps::path); - ASKYN_MACRO("logYN","log","log",AutoConf::Regexps::any); + //ASKYN_MACRO("logYN","log","log",AutoConf::Regexps::any); ASKYN_MACRO("loglevelYN","loglevel","loglevel",AutoConf::Regexps::any); // TODO: word type #define ASK_BOOL(A,B) { \ std::cout << AutoConf::Texts.at(lang).at(A) << std::endl; \ @@ -213,20 +210,22 @@ main(void) { }\ } ASK_TEXT("FamilyUsing","family"); - ASK_BOOL("BeFloodfillYN", "floodflill"); - ASK_BOOL("NoTransitYN", "transit"); + ASK_BOOL("BeFloodfillYN", "floodfill"); + ASK_BOOL("NoTransitYN", "notransit"); ASK_TEXT("Bandwidth","bandwidth"); ASK_TEXT("Share","share"); ///// With sections conf << "[ntcp2]\r\n"; ASK_BOOL("NTCPEnabledYN", "enabled"); - ASK_BOOL("NTCPPublishedYN", "publish"); + ASK_BOOL("NTCPPublishedYN", "published"); ASK_TEXT("NTCPPPort", "port"); ASK_TEXT("NTCPPProxy", "proxy"); conf << "[ssu2]\r\n"; ASK_BOOL("SSUEnabledYN", "enabled"); ASK_TEXT("SSUPPort", "port"); ASK_TEXT("SSUProxy", "proxy"); + conf << "[http]\r\n"; + ASK_TEXT("HTTPLang", "lang"); #undef ASK_TEXT #undef ASK_BOOL #undef ASKYN_MACRO From ea98854c7e30ecf692914d6b14c39f377e86d059 Mon Sep 17 00:00:00 2001 From: wipedlifepotato <60944239+wipedlifepotato@users.noreply.github.com> Date: Fri, 20 Sep 2024 13:42:54 +0700 Subject: [PATCH 42/45] [AutoConf] Add information to README --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index f9e2172..e5921ee 100755 --- a/README.md +++ b/README.md @@ -188,3 +188,9 @@ verify signed router.info xLSOIwih0Jx3JObPRCBJexYOpPYJsEwQ1A== -----END EC PRIVATE KEY----- +#### AutoConf +A program for help create the config file for i2pd + +For a now a better way to manual write the config file + +For usage just run ./AutoConf or AutoConf.exe From 049ad0802b4fae15954cfdc160f764aefbea2d9e Mon Sep 17 00:00:00 2001 From: EKCKABATOP54 Date: Wed, 25 Sep 2024 12:18:25 +0200 Subject: [PATCH 43/45] print yggdrasil address --- routerinfo.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/routerinfo.cpp b/routerinfo.cpp index a56a273..1991c0a 100644 --- a/routerinfo.cpp +++ b/routerinfo.cpp @@ -6,7 +6,7 @@ static void usage(const char * argv) { - std::cout << "usage: " << argv << " [-6|-f|-p] routerinfo.dat" << std::endl; + std::cout << "usage: " << argv << " [-6|-f|-p|-y] routerinfo.dat" << std::endl; } template @@ -51,7 +51,8 @@ int main(int argc, char * argv[]) bool ipv6 = false; bool firewall = false; bool port = false; - while((opt = getopt(argc, argv, "6fp")) != -1) { + bool yggdrasil = false; + while((opt = getopt(argc, argv, "6fpy")) != -1) { switch(opt) { case '6': ipv6 = true; @@ -62,6 +63,9 @@ int main(int argc, char * argv[]) case 'p': port = true; break; + case 'y': + yggdrasil = true; + break; default: usage(argv[0]); return 1; @@ -89,7 +93,13 @@ int main(int argc, char * argv[]) a = ri.GetSSU2V6Address(); if(a) addrs.push_back(a); - } + } + + if(yggdrasil){ + a = ri.GetYggdrasilAddress(); + if(a) + addrs.push_back(a); + } if(firewall) std::cout << "# "; From be61895bdc48a4167d2fa887892886607a7fedd6 Mon Sep 17 00:00:00 2001 From: hcyp <161704246+hcyp@users.noreply.github.com> Date: Fri, 29 Nov 2024 20:43:48 +0000 Subject: [PATCH 44/45] update building instructions --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e5921ee..8fcaa27 100755 --- a/README.md +++ b/README.md @@ -26,7 +26,12 @@ Notice: git submodules are used so make sure to clone this repository recursivel ### Building - make +```sh +git submodule init && git submodule update +git submodule update --init +git pull --recurse-submodules +make +``` ## Tools included From 33fce4b087d92ee90653460bbe7a07cdc0c7b121 Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 25 Feb 2025 15:47:26 -0500 Subject: [PATCH 45/45] updated to 2.56.0 --- famtool.cpp | 2 +- i2pd | 2 +- keygen.cpp | 2 +- offlinekeys.cpp | 2 +- regaddr.cpp | 2 +- regaddr_3ld.cpp | 2 +- regaddralias.cpp | 2 +- routerinfo.cpp | 2 +- vain.cpp | 6 +++--- verifyhost.cpp | 2 +- 10 files changed, 12 insertions(+), 12 deletions(-) diff --git a/famtool.cpp b/famtool.cpp index c8b5911..0a40689 100644 --- a/famtool.cpp +++ b/famtool.cpp @@ -197,7 +197,7 @@ int main(int argc, char * argv[]) return 0; } - InitCrypto(false, true, false); + InitCrypto(false); if(!fam.size()) { // no family name diff --git a/i2pd b/i2pd index 9668ea9..dcd15cc 160000 --- a/i2pd +++ b/i2pd @@ -1 +1 @@ -Subproject commit 9668ea9338fe8524781d6966f576227775129769 +Subproject commit dcd15cc2449d6320de6351054e61ef2ee7ebee40 diff --git a/keygen.cpp b/keygen.cpp index 30df4a0..a9f72cf 100644 --- a/keygen.cpp +++ b/keygen.cpp @@ -12,7 +12,7 @@ int main (int argc, char * argv[]) std::cout << "Usage: keygen filename " << std::endl; return -1; } - i2p::crypto::InitCrypto (false, true, false); + i2p::crypto::InitCrypto (false); i2p::data::SigningKeyType type = i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519; if (argc > 2) { std::string str(argv[2]); diff --git a/offlinekeys.cpp b/offlinekeys.cpp index 8a4a8c5..c290465 100644 --- a/offlinekeys.cpp +++ b/offlinekeys.cpp @@ -14,7 +14,7 @@ int main (int argc, char * argv[]) std::cout << "Usage: offlinekeys " << std::endl; return -1; } - i2p::crypto::InitCrypto (false, true, false); + i2p::crypto::InitCrypto (false); std::string fname(argv[2]); i2p::data::PrivateKeys keys; diff --git a/regaddr.cpp b/regaddr.cpp index bd560c0..6dbf1fd 100644 --- a/regaddr.cpp +++ b/regaddr.cpp @@ -12,7 +12,7 @@ int main (int argc, char * argv[]) return -1; } - i2p::crypto::InitCrypto (false, true, false); + i2p::crypto::InitCrypto (false); i2p::data::PrivateKeys keys; std::ifstream s(argv[1], std::ifstream::binary); diff --git a/regaddr_3ld.cpp b/regaddr_3ld.cpp index 561bbae..4c94b09 100644 --- a/regaddr_3ld.cpp +++ b/regaddr_3ld.cpp @@ -18,7 +18,7 @@ int main (int argc, char * argv[]) if (argc < 3) { help(); return -1;} std::string arg = argv[1]; - i2p::crypto::InitCrypto (false, true, false); + i2p::crypto::InitCrypto (false); i2p::data::PrivateKeys keys; if (arg == "step1") { diff --git a/regaddralias.cpp b/regaddralias.cpp index 96eafaa..cc56bc0 100644 --- a/regaddralias.cpp +++ b/regaddralias.cpp @@ -12,7 +12,7 @@ int main (int argc, char * argv[]) return -1; } - i2p::crypto::InitCrypto (false, true, false); + i2p::crypto::InitCrypto (false); i2p::data::PrivateKeys oldkeys, newkeys; { diff --git a/routerinfo.cpp b/routerinfo.cpp index 1991c0a..5391e39 100644 --- a/routerinfo.cpp +++ b/routerinfo.cpp @@ -46,7 +46,7 @@ int main(int argc, char * argv[]) usage(argv[0]); return 1; } - i2p::crypto::InitCrypto(false, true, false); + i2p::crypto::InitCrypto(false); int opt; bool ipv6 = false; bool firewall = false; diff --git a/vain.cpp b/vain.cpp index ddee306..91227b9 100755 --- a/vain.cpp +++ b/vain.cpp @@ -294,9 +294,9 @@ int main (int argc, char * argv[]) } // https://github.com/PurpleI2P/i2pd/blob/ae5239de435e1dcdff342961af9b506f60a494d4/libi2pd/Crypto.h#L310 //// init and terminate -// void InitCrypto (bool precomputation, bool aesni, bool avx, bool force); -// By default false to all. But on much proccessors some things will be enabled. SO, TODO - i2p::crypto::InitCrypto (PRECOMPUTATION_CRYPTO, AESNI_CRYPTO, FORCE_CRYPTO); +// void InitCrypto (bool precomputation); +// By default false + i2p::crypto::InitCrypto (PRECOMPUTATION_CRYPTO); options.signature = i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519; /////////////// //For while diff --git a/verifyhost.cpp b/verifyhost.cpp index 482d7f8..52c4cff 100644 --- a/verifyhost.cpp +++ b/verifyhost.cpp @@ -12,7 +12,7 @@ int main (int argc, char * argv[]) return -1; } - i2p::crypto::InitCrypto (false, true, false); + i2p::crypto::InitCrypto (false); i2p::data::IdentityEx Identity, OldIdentity;