diff --git a/CMakeLists.txt b/CMakeLists.txt index fc1bef7..b371bd8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,8 @@ option(FORCE_ANSI "Force ANSI console colors even on windows" OFF) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules") +include(libeoskeygen) + # Use installpath from GNUInstallDirs as default. include(GNUInstallDirs) @@ -45,15 +47,9 @@ endif() set (PROGRAM_EXE ${CMAKE_PROJECT_NAME}) set (PROGRAM_SOURCE - src/core/file.cpp - src/core/dictionary.cpp - src/core/string.cpp src/core/isatty.cpp - src/crypto/base58.cpp - src/crypto/WIF.cpp src/cli_key_search_result.cpp src/console.cpp - src/key_search.cpp src/benchmark.cpp src/main.cpp ) @@ -65,38 +61,16 @@ else() set (PROGRAM_SOURCE ${PROGRAM_SOURCE} src/console_ansi.cpp) endif() -# Libraries -find_package(OpenSSL 1.1 REQUIRED) -set (PROGRAM_SOURCE ${PROGRAM_SOURCE} - src/crypto/openssl/ec.cpp - src/crypto/openssl/hash.cpp -) - -if (USE_THREADS) - find_package(Threads) - if (Threads_FOUND) - # Add preprocessor flag - add_definitions( "-DHAVE_THREADS=1" ) - set (PROGRAM_SOURCE ${PROGRAM_SOURCE} src/key_search_mt.cpp) - endif (Threads_FOUND) -endif (USE_THREADS) - # Project config file configure_file(src/config.h.in "${PROJECT_BINARY_DIR}/config.h" @ONLY) include_directories(${PROJECT_BINARY_DIR}) # Include OpenSSL headers -include_directories( ${OPENSSL_INCLUDE_DIR} ) - -include_directories( include ) +#include_directories( ${OPENSSL_INCLUDE_DIR} ) add_executable( ${PROGRAM_EXE} ${PROGRAM_SOURCE} ) -target_link_libraries( ${PROGRAM_EXE} - PUBLIC - ${OPENSSL_LIBRARIES} - ${CMAKE_THREAD_LIBS_INIT} -) +target_link_libraries( ${PROGRAM_EXE} PUBLIC eoskeygen ) # -------------------------------- # Install @@ -104,26 +78,6 @@ target_link_libraries( ${PROGRAM_EXE} install(TARGETS ${PROGRAM_EXE} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) -# Win32 specific. -if (WIN32) - if (CMAKE_SIZEOF_VOID_P EQUAL 8) - set (OPENSSL_LIBCRYPTO_NAME libcrypto-1_1-x64) - else() - set (OPENSSL_LIBCRYPTO_NAME libcrypto-1_1) - endif() - set( OPENSSL_LIBCRYPTO_DLL ${OPENSSL_ROOT_DIR}/bin/${OPENSSL_LIBCRYPTO_NAME}.dll ) - - # Need to copy libcrypto dll to binary folder. - add_custom_command(TARGET ${PROGRAM_EXE} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different - ${OPENSSL_LIBCRYPTO_DLL} - ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR} - ) - - # We also need to copy libcrypto dll during install - install(FILES ${OPENSSL_LIBCRYPTO_DLL} DESTINATION ${CMAKE_INSTALL_BINDIR}) -endif (WIN32) - # Readme and license install(FILES README.md LICENSE LICENSE.bitcoin DESTINATION ${CMAKE_INSTALL_SHAREDIR}) diff --git a/README.md b/README.md index 069af15..3b72adf 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ This program generates public and private keypair for [EOS](https://eos.io/) ## Compile -You will need `openssl` development files (version 1.1 or later) to compile and `cmake 3.15` or later to compile this project. +You will need `libeoskeygen` and `cmake 3.15` or later to compile this project. ### Linux/MacOS @@ -18,11 +18,37 @@ You will need `openssl` development files (version 1.1 or later) to compile and #### Linux **Ubuntu:** + +First you need to have a compiler. this can be installed with apt. + ```sh -$ apt-get install gcc g++ libssl-dev +$ apt-get install gcc g++ ``` -**Other**: Consult the manual for you package manager. +You then need `libeoskeygen`. + +This can be installed from [EOS Sweden's APT Repository](https://eosswedenorg.github.io/apt) like this: + +```sh +$ sudo apt-get install software-properties-common +$ curl https://apt.eossweden.org/key 2> /dev/null | sudo apt-key add - +$ sudo apt-add-repository -y 'deb [arch=amd64] https://apt.eossweden.org/main `lsb_release -cs` stable' +$ sudo apt-get install libeoskeygen-dev +``` + +or manually via `.deb` file from [github](https://github.com/eosswedenorg/libeoskeygen/releases) + +```sh +$ wget +$ sudo apt install ./libeoskeygen-dev-.deb +``` + +**Other**: + +Consult the manual for you package manager. +`libeoskeygen` will be downloaded and compiled if it's not installed automatically (however this is slower). + +Consult [libeoskeygen's github](https://github.com/eosswedenorg/libeoskeygen) if you want to compile and install it manually. **CMake** @@ -48,13 +74,15 @@ Other methods is documanted at https://cmake.org/download You must have a compiler installed. This project is known to build with `Xcode 11.0` but other versions should work. -You need to have opessl and cmake installed also, this can be done with this `brew` command: +You need to have cmake installed also, this can be done with this `brew` command: ```sh -$ brew install openssl cmake +$ brew install cmake ``` If you need a newer version of cmake, you can download the official `.dmg` file: [cmake-3.15.7-Darwin-x86_64.dmg](https://github.com/Kitware/CMake/releases/download/v3.15.7/cmake-3.15.7-Darwin-x86_64.dmg). or see https://cmake.org/download for other versions. +`libeoskeygen` needs to be compiled and installed from source. [Go here](https://github.com/eosswedenorg/libeoskeygen) + #### Build Run `./build.sh` to trigger cmake. @@ -73,13 +101,12 @@ $ cmake .. && make #### Dependencies -Download and install `cmake` version `3.15` or newer from [cmake.org](https://cmake.org) and download -[openssl](https://mirror.firedaemon.com/OpenSSL/openssl-1.1.1e-dev.zip) - -unpack `openssl-1.1.1e-dev.zip` somewhere on the filesystem. +Download and install `cmake` version `3.15` or newer from [cmake.org](https://cmake.org) You will also need a compiler. [Build Tools for Visual Studio 2019](https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=BuildTools&rel=16) (Selecting C++ during installation) is recommended. + + #### Build. you need to set `OPENSSL_ROOT_DIR` to the directory where you unpacked @@ -103,7 +130,6 @@ These compile options are available: | Cmake | build.sh | Description | |--------------------------- | ----------------- | ------------------------------------------| | -DCMAKE_BUILD_TYPE=`value` | -t `value` | Type of build | -| -DUSE_THREADS=`OFF` | --disable-threads | Disable thread support | | -DFORCE_ANSI=`ON` | --force-ansi | Force ANSI console colors even on windows | For more details about options run `./build.sh -l` or `mkdir build && cmake build -LA` diff --git a/include/eoskeygen/core/dictionary.h b/include/eoskeygen/core/dictionary.h deleted file mode 100644 index acf7820..0000000 --- a/include/eoskeygen/core/dictionary.h +++ /dev/null @@ -1,72 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2019-2020 EOS Sw/eden - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef EOSIOKEYGEN_CORE_DICTIONARY_H -#define EOSIOKEYGEN_CORE_DICTIONARY_H - -#include -#include -#include - -namespace eoskeygen { - -class Dictionary -{ -public : - // Map that contains position and length for substrings. - // - // key = position in the search string. - // value = length of the word from this position. - typedef std::map< size_t, size_t > search_result_t; - -public : - - // Load words from file. - bool loadFromFile(const std::string& filename); - - // Add a word to the dictionary. - void add(const std::string& word); - - // Add words from another dictionary. - void add(const Dictionary& dictionary); - - // Clear all words from the dictionary. - void clear(); - - // Returns true if word exists in the dictionary. - bool contains(const std::string& word) const; - - // Searches the subject for words defined in the dictionary. - // Returns a search_result_t with the words found in subject. - // See search_result_t for more details. - search_result_t search(const std::string& subject) const; - -protected : - - // Words in the dictionary. - std::set m_words; -}; - -} // namespace eoskeygen - -#endif /* EOSIOKEYGEN_CORE_DICTIONARY_H */ diff --git a/include/eoskeygen/core/file.h b/include/eoskeygen/core/file.h deleted file mode 100644 index dac2790..0000000 --- a/include/eoskeygen/core/file.h +++ /dev/null @@ -1,35 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2019-2020 EOS Sw/eden - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef EOSIOKEYGEN_CORE_FILE_H -#define EOSIOKEYGEN_CORE_FILE_H - -#include - -namespace eoskeygen { - -bool readLines(const std::string& filename, strlist_t& lines); - -} // namespace - -#endif /* EOSIOKEYGEN_CORE_FILE_H */ diff --git a/include/eoskeygen/core/string.h b/include/eoskeygen/core/string.h deleted file mode 100644 index 1662c7b..0000000 --- a/include/eoskeygen/core/string.h +++ /dev/null @@ -1,52 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2019-2020 EOS Sw/eden - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef EOSIOKEYGEN_CORE_STRING_H -#define EOSIOKEYGEN_CORE_STRING_H - -#include -#include - -namespace eoskeygen { - -typedef std::vector strlist_t; - -strlist_t strsplitwords(const std::string& str, const std::string& delim = ","); - -strlist_t strsplit(const std::string& str, const std::string& delim); - -std::string strjoin(const strlist_t& list, const std::string& delim); - -std::string& strtolower(std::string& str); - -std::string& rtrim(std::string& str); -std::string& ltrim(std::string& str); -std::string& trim(std::string& str); - -strlist_t& base58_strip(strlist_t& list); - -strlist_t l33twords(std::string str); - -} // namespace eoskeygen - -#endif /* EOSIOKEYGEN_CORE_STRING_H */ diff --git a/include/eoskeygen/crypto/WIF.h b/include/eoskeygen/crypto/WIF.h deleted file mode 100644 index 244f6ac..0000000 --- a/include/eoskeygen/crypto/WIF.h +++ /dev/null @@ -1,39 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2019-2020 EOS Sw/eden - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef EOSIOKEYGEN_CRYPTO_WIF_H -#define EOSIOKEYGEN_CRYPTO_WIF_H - -#include - -namespace eoskeygen { - -std::string wif_priv_encode(ec_privkey_t priv); - -std::string wif_pub_encode(ec_pubkey_t pub); - -void wif_print_key(const struct ec_keypair *key); - -} // namespace eoskeygen - -#endif /* EOSIOKEYGEN_CRYPTO_WIF_H */ diff --git a/include/eoskeygen/crypto/base58.h b/include/eoskeygen/crypto/base58.h deleted file mode 100644 index 4d52f31..0000000 --- a/include/eoskeygen/crypto/base58.h +++ /dev/null @@ -1,46 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2019-2020 EOS Sw/eden - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef EOSIOKEYGEN_CRYPTO_BASE58_H -#define EOSIOKEYGEN_CRYPTO_BASE58_H - -#include -#include - -namespace eoskeygen { - -std::string base58_encode(const std::string& str); -std::string base58_encode(const std::vector& vch); -std::string base58_encode(const unsigned char* pbegin, const unsigned char* pend); - -bool is_base58(char ch); - -// Returns std::string::npos if the string contains only base58 characters -// Otherwise the position of the first non base58 character is returned. -size_t is_base58(const std::string& str); - -std::string& base58_strip(std::string& str); - -} //namespace eoskeygen - -#endif /* EOSIOKEYGEN_CRYPTO_BASE58_H */ diff --git a/include/eoskeygen/crypto/checksum.h b/include/eoskeygen/crypto/checksum.h deleted file mode 100644 index 953a5d8..0000000 --- a/include/eoskeygen/crypto/checksum.h +++ /dev/null @@ -1,54 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2019-2020 EOS Sw/eden - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef EOSIOKEYGEN_CRYPTO_EOS_CHECKSUM_H -#define EOSIOKEYGEN_CRYPTO_EOS_CHECKSUM_H - -#include -#include -#include -#include - -namespace eoskeygen { - -#define CHECKSUM_SIZE 4 - -typedef std::array checksum_t; - -template -inline checksum_t checksum(const unsigned char* data, std::size_t len) { - checksum_t crc; - T hash; - - F(data, len, &hash); - std::memcpy(crc.data(), &hash, crc.size()); - return crc; -} - -#define checksum_sha256 checksum -#define checksum_sha256d checksum -#define checksum_ripemd160 checksum - -} // namespace eoskeygen - -#endif /* EOSIOKEYGEN_CHECKSUM_H */ diff --git a/include/eoskeygen/crypto/ec.h b/include/eoskeygen/crypto/ec.h deleted file mode 100644 index 7fa9af4..0000000 --- a/include/eoskeygen/crypto/ec.h +++ /dev/null @@ -1,39 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2019-2020 EOS Sw/eden - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef EOSIOKEYGEN_CRYPTO_EC_H -#define EOSIOKEYGEN_CRYPTO_EC_H - -#include - -namespace eoskeygen { - -/** - * Generates a keypair using the secp256k1 curve. - * public key is in compressed format. - */ -int ec_generate_key(struct ec_keypair *pair); - -} // namespace eoskeygen - -#endif /* EOSIOKEYGEN_CRYPTO_EC_H */ diff --git a/include/eoskeygen/crypto/hash.h b/include/eoskeygen/crypto/hash.h deleted file mode 100644 index 4d487c2..0000000 --- a/include/eoskeygen/crypto/hash.h +++ /dev/null @@ -1,41 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2019-2020 EOS Sw/eden - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef EOSIOKEYGEN_CRYPTO_HASH_H -#define EOSIOKEYGEN_CRYPTO_HASH_H - -#include -#include - -namespace eoskeygen { - -sha256_t* sha256(const unsigned char *data, std::size_t len, sha256_t* out); - -// sha256 double. -sha256_t* sha256d(const unsigned char *data, std::size_t len, sha256_t* out); - -ripemd160_t* ripemd160(const unsigned char *data, std::size_t len, ripemd160_t* out); - -} // namespace eoskeygen - -#endif /* EOSIOKEYGEN_CRYPTO_HASH_H */ diff --git a/include/eoskeygen/crypto/types.h b/include/eoskeygen/crypto/types.h deleted file mode 100644 index 23e2585..0000000 --- a/include/eoskeygen/crypto/types.h +++ /dev/null @@ -1,55 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2019-2020 EOS Sw/eden - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef EOSIOKEYGEN_CRYPTO_TYPES_H -#define EOSIOKEYGEN_CRYPTO_TYPES_H - -#include - -namespace eoskeygen { - -#define EC_PRIVKEY_SIZE 32 - -/* - * Compressed format! - * z||x, where byte z specifies which (of the 2) solutions of the quadratic equation y is. - * Each cordinate is 32 bytes. - */ -#define EC_PUBKEY_SIZE (32 + 1) - -typedef std::array ec_privkey_t; -typedef std::array ec_pubkey_t; - -struct ec_keypair { - ec_privkey_t secret; - ec_pubkey_t pub; -}; - -// Hashes. - -typedef struct { unsigned char data[20]; } ripemd160_t; -typedef struct { unsigned char data[32]; } sha256_t; - -} // namespace eoskeygen - -#endif /* EOSIOKEYGEN_CRYPTO_TYPES_H */ diff --git a/include/eoskeygen/key_search.h b/include/eoskeygen/key_search.h deleted file mode 100644 index 5d13716..0000000 --- a/include/eoskeygen/key_search.h +++ /dev/null @@ -1,95 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2019-2020 EOS Sw/eden - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef EOSIOKEYGEN_KEY_SEARCH_H -#define EOSIOKEYGEN_KEY_SEARCH_H - -#include -#include - -namespace eoskeygen { - -class IKeySearchResult; - -class KeySearch -{ -public : - - struct result { - size_t pos; // position where the word was found. - size_t len; // the length of the word. - }; - -public : - // Add a word to search for. - void addWord(const std::string& str); - - // Add a list of words to search for. - void addList(const strlist_t& list); - - // get the list of words to search for. - const strlist_t& getList(); - - // Clears the search list. - void clear(); - - // Set callback for search result. - void setCallback(IKeySearchResult* callback); - -#ifdef HAVE_THREADS - // Set the number of threads to use while searching. - void setThreadCount(size_t num); -#endif /* HAVE_THREADS */ - - // Perform a search. - void find(size_t num_results); - -protected : - - // Check if any word in appears in 's public key. - // returns true if a word was found (stored in ), false otherwise. - bool _contains_word(const struct ec_keypair* key, struct result& result); - -#ifdef HAVE_THREADS - void _thr_proc(); - - void _search_mt(size_t n); -#endif /* HAVE_THREADS */ - - void _search_linear(size_t n); - -protected : - // List of words to search for. - strlist_t m_words; - -#ifdef HAVE_THREADS - // Number of threads to use. - size_t m_threads; -#endif /* HAVE_THREADS */ - - IKeySearchResult* m_callback; -}; - -} // namespace eoskeygen - -#endif /* EOSIOKEYGEN_KEY_SEARCH_H */ diff --git a/include/eoskeygen/key_search_result.h b/include/eoskeygen/key_search_result.h deleted file mode 100644 index 6e48675..0000000 --- a/include/eoskeygen/key_search_result.h +++ /dev/null @@ -1,40 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2019-2020 EOS Sw/eden - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef EOSIOKEYGEN_KEY_SEARCH_RESULT_H -#define EOSIOKEYGEN_KEY_SEARCH_RESULT_H - -#include - -namespace eoskeygen { - -class IKeySearchResult -{ -public : - - virtual void onResult(const struct ec_keypair* key, const struct KeySearch::result& result) = 0; -}; - -} // namespace eoskeygen - -#endif /* EOSIOKEYGEN_KEY_SEARCH_RESULT_H */ diff --git a/src/core/dictionary.cpp b/src/core/dictionary.cpp deleted file mode 100644 index e3431ba..0000000 --- a/src/core/dictionary.cpp +++ /dev/null @@ -1,103 +0,0 @@ - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace eoskeygen { - -struct StringContains { - StringContains(const std::string& str, std::vector& pos) : m_str(str), m_pos(pos) {} - bool operator()(const std::string& w) { - for(size_t p = m_str.find(w); p != std::string::npos; p = m_str.find(w, p+1)) { - m_pos.push_back(p); - } - return !m_pos.empty(); - } - std::string m_str; - std::vector& m_pos; -}; - -bool Dictionary::loadFromFile(const std::string& filename) -{ - strlist_t lines; - - // Clear before adding. - clear(); - - if (readLines(filename, lines)) { - - // Read each line and add to the dictionary. - for(auto it = lines.begin(); it != lines.end(); it++) { - add(*it); - } - return true; - } - return false; -} - -void Dictionary::add(const std::string& word) -{ - // Do not insert a empty string. - if (word.length()) { - m_words.insert(word); - } -} - -void Dictionary::add(const Dictionary& dictionary) -{ - std::set_union( - m_words.begin(), m_words.end(), - dictionary.m_words.begin(), dictionary.m_words.end(), - std::inserter(m_words, m_words.begin()) - ); -} - -void Dictionary::clear() -{ - m_words.clear(); -} - -bool Dictionary::contains(const std::string& word) const -{ - return m_words.find(word) != m_words.cend(); -} - -Dictionary::search_result_t Dictionary::search(const std::string& subject) const -{ - search_result_t res; - - std::vector pos; - StringContains pred(subject, pos); - - // Find all words. - for(auto it = std::find_if(m_words.begin(), m_words.end(), pred); - it != m_words.end(); - it = std::find_if(++it, m_words.end(), pred)) { - - // Go through all found positions. - for (auto it2 = pos.begin(); it2 != pos.end(); it2++) { - - // Insert - auto rit = res.find(*it2); - if (rit == res.end()) { - res.emplace(*it2, it->length()); - } - // Update length if it's longer then the previous we found. - else if (rit->second < it->length()) { - rit->second = it->length(); - } - } - - // Clear positions - pos.clear(); - } - - return res; -} - -} // namespace eoskeygen diff --git a/src/core/file.cpp b/src/core/file.cpp deleted file mode 100644 index 6bdc497..0000000 --- a/src/core/file.cpp +++ /dev/null @@ -1,26 +0,0 @@ - -#include -#include - -namespace eoskeygen { - -bool readLines(const std::string& filename, strlist_t& lines) { - - FILE *fd; - char buf[1024]; - - fd = fopen(filename.c_str(), "r"); - if (!fd) { - return false; - } - - while(fgets(buf, sizeof(buf), fd) != NULL) { - std::string line(buf); - lines.push_back(trim(line)); - } - - fclose(fd); - return true; -} - -} // namespace eoskeygen diff --git a/src/core/string.cpp b/src/core/string.cpp deleted file mode 100644 index aeb2a7d..0000000 --- a/src/core/string.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2019-2020 EOS Sw/eden - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include -#include -#include -#include -#include - -namespace eoskeygen { - -strlist_t strsplitwords(const std::string& str, const std::string& delim) { - - strlist_t words = strsplit(str, delim); - std::for_each(words.begin(), words.end(), trim); - return words; -} - -strlist_t strsplit(const std::string& str, const std::string& delim) { - - strlist_t r; - size_t s = 0, e = 0, dlen = delim.length(); - - while((e = str.find(delim, s)) != std::string::npos) { - r.push_back(str.substr(s, e - s)); - s = e + dlen; - } - - r.push_back(str.substr(s)); - return r; -} - -std::string strjoin(const strlist_t& list, const std::string& delim) { - - std::string out; - - for(const std::string& item : list) { - if (item.length() < 1) { - continue; - } - out += item + delim; - } - - if (out.length() > 0) { - out.erase(out.end() - delim.length()); - } - - return out; -} - -std::string& strtolower(std::string& str) { - std::transform(str.begin(), str.end(), str.begin(), [](unsigned char c){ return std::tolower(c); }); - return str; -} - -std::string& ltrim(std::string& str) { - auto it = std::find_if(str.begin(), str.end(), [](char ch){ return !std::isspace(ch); }); - str.erase(str.begin(), it); - return str; -} - -std::string& rtrim(std::string& str) { - auto it = std::find_if(str.rbegin(), str.rend(), [](char ch){ return !std::isspace(ch); }); - str.erase(it.base(), str.end()); - return str; -} - -std::string& trim(std::string& str) { - return ltrim(rtrim(str)); -} - -strlist_t& base58_strip(strlist_t& list) { - - std::transform(list.begin(), list.end(), list.begin(), [](std::string& str){ return base58_strip(str); }); - return list; -} - -static bool is_l33t(char ch, char& r) { - - // '1', '2', '3', '4', '5', '6', '7', '8', '9' - static char alphabet[9] = { 'l', 'z', 'e', 'a', 's', 'G', 't', 'B', 'g' }; - - for(std::size_t i = 0; i < sizeof(alphabet) / sizeof(char); i++) { - - if (ch == alphabet[i]) { - r = static_cast('1' + i); - return true; - } - } - return false; -} - -static void _l33t(strlist_t& list, const std::string& a, std::size_t pos) { - - // Find the next character to be replaced. - for(std::size_t i = pos; i < a.length(); i++) { - - char ch; - if (is_l33t(a[i], ch)) { - // create a new string and replace the character. - std::string b = a; - b[i] = ch; - - // Store the new string as the result. - list.push_back(b); - - // Perform the same algorithm for both strings - // at the next position. - _l33t(list, a, i + 1); - _l33t(list, b, i + 1); - break; - } - } -} - -strlist_t l33twords(std::string str) { - - strlist_t list; - - // "l" is abit special and are not included in base58 so we set it to 1. - // All other characters in "l33t" are valid. - std::transform(str.begin(), str.end(), str.begin(), [](char c){ return c == 'l' ? '1' : c; }); - - // Store the original string as the first in list. - list.push_back(str); - - _l33t(list, str, 0); - return list; -} - -} // namespace eoskeygen diff --git a/src/crypto/WIF.cpp b/src/crypto/WIF.cpp deleted file mode 100644 index a86a207..0000000 --- a/src/crypto/WIF.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2019-2020 EOS Sw/eden - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include -#include -#include -#include -#include - -namespace eoskeygen { - -#define PRIV_KEY_PREFIX 0x80 /* 0x80 for "Bitcoin mainnet". Always used by EOS. */ - -std::string wif_priv_encode(ec_privkey_t priv) { - - checksum_t check; - // 1 byte extra for prefix. - unsigned char buf[1 + EC_PRIVKEY_SIZE + CHECKSUM_SIZE] = { PRIV_KEY_PREFIX }; - - memcpy(buf + 1, priv.data(), priv.size()); - - // Checksum - check = checksum_sha256d(buf, 1 + EC_PRIVKEY_SIZE); - memcpy(buf + 1 + EC_PRIVKEY_SIZE, check.data(), check.size()); - - return base58_encode(buf, buf + sizeof(buf)); -} - -std::string wif_pub_encode(ec_pubkey_t pub) { - - checksum_t check = checksum_ripemd160(pub.data(), pub.size()); - unsigned char buf[EC_PUBKEY_SIZE + CHECKSUM_SIZE]; - - memcpy(buf, pub.data(), pub.size()); - memcpy(buf + EC_PUBKEY_SIZE, check.data(), check.size()); - - return "EOS" + base58_encode(buf, buf + sizeof(buf)); -} - -void wif_print_key(const struct ec_keypair *key) { - - std::cout << "Public: " << wif_pub_encode(key->pub) << std::endl; - std::cout << "Private: " << wif_priv_encode(key->secret) << std::endl; -} - -} // namespace eoskeygen diff --git a/src/crypto/base58.cpp b/src/crypto/base58.cpp deleted file mode 100644 index 47581f5..0000000 --- a/src/crypto/base58.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/** - * The MIT License (MIT) - * - * Copyright (c) 2009-2019 The Bitcoin Core developers - * Copyright (c) 2009-2019 Bitcoin Developers - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * Based on code from https://github.com/bitcoin/bitcoin/blob/f1e2f2a85962c1664e4e55471061af0eaa798d40/src/base58.cpp - */ -#include -#include -#include -#include - -namespace eoskeygen { - -static const char charmap[59] = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; - -std::string base58_encode(const unsigned char* pbegin, const unsigned char* pend) { - - // Skip & count leading zeroes. - int zeroes = 0; - int length = 0; - while (pbegin != pend && *pbegin == 0) { - pbegin++; - zeroes++; - } - // Allocate enough space in big-endian base58 representation. - std::size_t size = (pend - pbegin) * 138 / 100 + 1; // log(256) / log(58), rounded up. - std::vector b58(size); - // Process the bytes. - while (pbegin != pend) { - int carry = *pbegin; - int i = 0; - // Apply "b58 = b58 * 256 + ch". - for (std::vector::reverse_iterator it = b58.rbegin(); (carry != 0 || i < length) && (it != b58.rend()); it++, i++) { - carry += 256 * (*it); - *it = static_cast(carry % 58); - carry /= 58; - } - - assert(carry == 0); - length = i; - pbegin++; - } - // Skip leading zeroes in base58 result. - std::vector::iterator it = b58.begin() + (size - length); - while (it != b58.end() && *it == 0) - it++; - // Translate the result into a string. - std::string str; - str.reserve(zeroes + (b58.end() - it)); - str.assign(zeroes, '1'); - while (it != b58.end()) - str += charmap[*(it++)]; - return str; -} - -std::string base58_encode(const std::string& str) { - - const unsigned char *ptr = (const unsigned char *) str.c_str(); - return base58_encode(ptr, ptr + str.length()); -} - -std::string base58_encode(const std::vector& vch) { - - return base58_encode(vch.data(), vch.data() + vch.size()); -} - -bool is_base58(char ch) { - for(unsigned int i=0; i < sizeof(charmap); i++) { - if (ch == charmap[i]) { - return true; - } - } - return false; -} - -size_t is_base58(const std::string& str) { - - auto p = std::find_if_not(str.begin(), str.end(), static_cast(is_base58)); - - if (p == str.end()) { - return std::string::npos; - } - return p - str.begin(); -} - -std::string& base58_strip(std::string &str) { - str.erase(std::remove_if(str.begin(), str.end(), [] (std::string::value_type ch) - { return is_base58(ch) == false; } - ), str.end()); - return str; -} - -} // namespace eoskeygen diff --git a/src/crypto/openssl/ec.cpp b/src/crypto/openssl/ec.cpp deleted file mode 100644 index 9fc5431..0000000 --- a/src/crypto/openssl/ec.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2019-2020 EOS Sw/eden - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include -#include -#include -#include - -namespace eoskeygen { - -int ec_generate_key(struct ec_keypair *pair) { - - int ret = -1; - EC_KEY *k; - BN_CTX *ctx; - - // Create BIGNUM context. - ctx = BN_CTX_new(); - if (ctx == NULL) { - return -1; - } - - // Construct curve. - k = EC_KEY_new_by_curve_name(NID_secp256k1); - if (k == NULL) { - goto fail1; - } - - // Generate new key pair. - if (EC_KEY_generate_key(k) != 1) { - goto fail2; - } - - // Copy private key to binary format. - EC_KEY_priv2oct(k, pair->secret.data(), EC_PRIVKEY_SIZE); - - // Copy public key - EC_POINT_point2oct(EC_KEY_get0_group(k), - EC_KEY_get0_public_key(k), POINT_CONVERSION_COMPRESSED, - pair->pub.data(), EC_PUBKEY_SIZE, ctx); - - ret = 0; -fail2: - EC_KEY_free(k); -fail1: - BN_CTX_free(ctx); - return ret; -} - -} // namespace eoskeygen diff --git a/src/crypto/openssl/hash.cpp b/src/crypto/openssl/hash.cpp deleted file mode 100644 index f79abc2..0000000 --- a/src/crypto/openssl/hash.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2019-2020 EOS Sw/eden - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include -#include -#include - -namespace eoskeygen { - -sha256_t* sha256(const unsigned char *data, std::size_t len, sha256_t* out) { - return (sha256_t *) SHA256(data, len, out->data); -} - -sha256_t* sha256d(const unsigned char *data, std::size_t len, sha256_t* out) { - SHA256(data, len, out->data); - return (sha256_t *) SHA256(out->data, 32, out->data); -} - -ripemd160_t* ripemd160(const unsigned char *data, std::size_t len, ripemd160_t* out) { - return (ripemd160_t *) RIPEMD160(data, len, out->data); -} - -} // namespace eoskeygen diff --git a/src/key_search.cpp b/src/key_search.cpp deleted file mode 100644 index 72dd714..0000000 --- a/src/key_search.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2019-2020 EOS Sw/eden - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include -#include -#include -#include -#include - -namespace eoskeygen { - -void KeySearch::addWord(const std::string& str) -{ - std::string tmp = str; - strtolower(tmp); - m_words.push_back(tmp); -} - -void KeySearch::addList(const strlist_t& list) -{ - for(const std::string& item : list) { - addWord(item); - } -} - -const strlist_t& KeySearch::getList() -{ - return m_words; -} - -void KeySearch::clear() -{ - m_words.clear(); -} - -void KeySearch::setCallback(IKeySearchResult* callback) -{ - m_callback = callback; -} - -void KeySearch::_search_linear(size_t n) { - - size_t count = 0; - struct ec_keypair pair; - - while (count < n) { - struct result res; - ec_generate_key(&pair); - if (_contains_word(&pair, res)) { - m_callback->onResult(&pair, res); - count++; - } - } -} - -void KeySearch::find(size_t num_results) { - -#ifdef HAVE_THREADS - // Only do multithread if number of threads makes sense. - if (m_threads >= 2) { - _search_mt(num_results); - return; - } -#endif /* HAVE_THREADS */ - - _search_linear(num_results); -} - -bool KeySearch::_contains_word(const struct ec_keypair* key, struct result& result) { - - // skip first 3 chars, as those are always "EOS" - std::string pubstr = wif_pub_encode(key->pub).substr(3); - strtolower(pubstr); - - for(auto const& w: m_words) { - size_t p = pubstr.find(w); - if (p != std::string::npos) { - result.pos = p + 3; - result.len = w.length(); - return true; - } - } - return false; -} - -} // namespace eoskeygen diff --git a/src/key_search_mt.cpp b/src/key_search_mt.cpp deleted file mode 100644 index d9f02c9..0000000 --- a/src/key_search_mt.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2019-2020 EOS Sw/eden - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include -#include -#include -#include -#include -#include -#include - -namespace eoskeygen { - -// Max keys to search for, -std::size_t g_max; - -// How many keys we have found so far. -std::size_t g_count; - -// Mutex guard for g_count. -std::mutex g_count_mtx; - -// Thread process. -void KeySearch::_thr_proc() { - - struct ec_keypair pair; - - while (g_count < g_max) { - struct result res; - - ec_generate_key(&pair); - if (_contains_word(&pair, res)) { - - // Guard output with mutex, so we don't get - // interrupted mid write and can write to g_count and res safely. - const std::lock_guard lock(g_count_mtx); - - // It is possible g_count was updated by another thread - // after we checked it in the while loop. - // So while we have the lock, we need to check it again. - if (g_count >= g_max) { - return; - } - - // Update count and call result function. - g_count++; - m_callback->onResult(&pair, res); - } - } -} - -void KeySearch::setThreadCount(size_t num) -{ - m_threads = num; -} - -void KeySearch::_search_mt(size_t n) -{ - std::vector t; - - t.resize(m_threads - 1); - - // Setup global variables for the threads. - g_max = n; - g_count = 0; - - // Launch them. - for(std::size_t i = 0; i < t.size(); i++) { - t[i] = std::thread(&KeySearch::_thr_proc, this); - } - - // Use main thread for 1 search - _thr_proc(); - - // Wait for all threads to compelete. - for(std::size_t i = 0; i < t.size(); i++) { - t[i].join(); - } -} - -} // namespace eoskeygen