diff --git a/CMakeLists.txt b/CMakeLists.txt index 2396237..d0195d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,7 +19,6 @@ set (PROGRAM_EXE ${CMAKE_PROJECT_NAME}) set (PROGRAM_SOURCE src/string.cpp src/base58.cpp - src/checksum.cpp src/WIF.cpp src/key_search.cpp src/key_search_helpers.cpp diff --git a/src/checksum.cpp b/src/checksum.cpp deleted file mode 100644 index 9f46b0e..0000000 --- a/src/checksum.cpp +++ /dev/null @@ -1,51 +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 "crypto/hash.h" -#include "checksum.h" - -namespace eoskeygen { - -inline void sha256d(const unsigned char *data, std::size_t len, sha256_t *out) { - sha256(data, len, out); - sha256(out->data, 32, out); -} - -#define checksum_impl(func, type) \ - checksum_t checksum_##func(const unsigned char *data, std::size_t len) { \ - \ - checksum_t crc; \ - type hash; \ - \ - func(data, len, &hash); \ - \ - std::memcpy(crc.data(), &hash, crc.size()); \ - return crc; \ - } - - -checksum_impl(sha256d, sha256_t) -checksum_impl(ripemd160, ripemd160_t) - -} // namespace eosio-keygen diff --git a/src/checksum.h b/src/checksum.h index b48f783..a67a42b 100644 --- a/src/checksum.h +++ b/src/checksum.h @@ -25,7 +25,9 @@ #define EOSIOKEYGEN_CHECKSUM_H #include +#include #include +#include "crypto/hash.h" namespace eoskeygen { @@ -33,9 +35,19 @@ namespace eoskeygen { typedef std::array checksum_t; -checksum_t checksum_sha256d(const unsigned char *data, std::size_t len); +template +inline checksum_t checksum(const unsigned char* data, std::size_t len) { + checksum_t crc; + T hash; -checksum_t checksum_ripemd160(const unsigned char *data, std::size_t len); + 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