From 43487324e42babff82d99df60b4fef1c672e1654 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Mon, 7 Aug 2017 13:50:35 -0400 Subject: [PATCH] add vanity address generator toy --- Makefile | 5 ++++- vanitygen.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 vanitygen.cpp diff --git a/Makefile b/Makefile index 02143ad..9a108bd 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ OBJECTS = $(SOURCES:.cpp=.o) I2PD_LIB = libi2pd.a -all: keygen keyinfo famtool routerinfo regaddr +all: keygen keyinfo famtool routerinfo regaddr vain routerinfo: $(OBJECTS) $(CXX) -o routerinfo routerinfo.o $(LDFLAGS) $(LIBS) @@ -30,6 +30,9 @@ famtool: $(OBJECTS) regaddr: $(OBJECTS) $(CXX) -o regaddr regaddr.o $(LDFLAGS) $(LIBS) +vain: $(OBJECTS) + $(CXX) -o vain vanitygen.o $(LDFLAGS) $(LIBS) + $(OBJECTS): libi2pd.a .SUFFIXES: diff --git a/vanitygen.cpp b/vanitygen.cpp new file mode 100644 index 0000000..ae4fe1d --- /dev/null +++ b/vanitygen.cpp @@ -0,0 +1,58 @@ +#include +#include +#include +#include +#include "Crypto.h" +#include "Identity.h" +#include "common/key.hpp" + +// XXX: make this faster +static bool check_keys(const std::string & prefix, i2p::data::PrivateKeys & key) +{ + return key.GetPublic()->GetIdentHash().ToBase32().substr(0, prefix.length()) == prefix; +} + +// XXX: make this faster +static void mutate_keys(uint8_t * buf, i2p::data::PrivateKeys & key) +{ + uint8_t * ptr = key.GetPadding(); + // TODO: do not hard code for ed25519 + RAND_bytes(ptr, 96); + key.RecalculateIdentHash(buf); +} + +int main (int argc, char * argv[]) +{ + if (argc < 2) + { + std::cout << "Usage: " << argv[0] << " filename prefix" << std::endl; + return -1; + } + uint8_t buf[1024] = {0}; + std::string prefix(argv[2]); + i2p::crypto::InitCrypto (false); + // default to ed 25519 keys + i2p::data::SigningKeyType type = i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519; + auto keys = i2p::data::PrivateKeys::CreateRandomKeys (type); + + // TODO: multi threading + while(!check_keys(prefix, keys)) + mutate_keys(buf, keys); + + std::ofstream f (argv[1], std::ofstream::binary | std::ofstream::out); + if (f) + { + size_t len = keys.GetFullLen (); + uint8_t * buf = new uint8_t[len]; + len = keys.ToBuffer (buf, len); + f.write ((char *)buf, len); + delete[] buf; + std::cout << "Destination " << keys.GetPublic ()->GetIdentHash ().ToBase32 () << " created" << std::endl; + } + else + std::cout << "Can't create file " << argv[1] << std::endl; + + i2p::crypto::TerminateCrypto (); + + return 0; +}