From f55d41e6bc1aecf8c06af60ab6b009de7dfbd58c Mon Sep 17 00:00:00 2001 From: clemahieu Date: Tue, 6 Jan 2015 07:19:10 -0600 Subject: [PATCH] Compiling ed25519 separately as a c library. --- CMakeLists.txt | 28 ++++++++++-------- ed25519-donna/ed25519-hash-custom.h | 33 +++++----------------- ed25519-donna/ed25519-randombytes-custom.h | 12 +------- ed25519-donna/{ed25519.cpp => ed25519.c} | 0 rai/secure.cpp | 32 +++++++++++++++++++++ 5 files changed, 56 insertions(+), 49 deletions(-) rename ed25519-donna/{ed25519.cpp => ed25519.c} (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 78ce6fa2..376a0e77 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,13 +37,16 @@ add_library (secure rai/secure.cpp ) -add_library (node - rai/node.hpp - rai/node.cpp +add_library (ed25519 ed25519-donna/ed25519-hash-custom.h ed25519-donna/ed25519-randombytes-custom.h ed25519-donna/ed25519.h - ed25519-donna/ed25519.cpp + ed25519-donna/ed25519.c + ) + +add_library (node + rai/node.hpp + rai/node.cpp ) add_executable (core_test @@ -98,7 +101,8 @@ set (CPACK_PACKAGE_VERSION_PATCH "0") SET (ACTIVE_NETWORK rai_active_network CACHE STRING "Selects which network parameters are used") set_property (CACHE ACTIVE_NETWORK PROPERTY STRINGS rai_test_network rai_beta_network rai_live_network) -set_target_properties (secure node core_test slow_test qt_test cli qt qt_wallet qt_system landing PROPERTIES COMPILE_FLAGS "-std=c++11 -Werror=switch ${PLATFORM_COMPILE_FLAGS} -DQT_NO_KEYWORDS -DACTIVE_NETWORK=${ACTIVE_NETWORK} -DED25519_CUSTOMHASH -DED25519_CUSTOMRNG -DRAIBLOCKS_VERSION_MAJOR=${CPACK_PACKAGE_VERSION_MAJOR} -DRAIBLOCKS_VERSION_MINOR=${CPACK_PACKAGE_VERSION_MINOR} -DRAIBLOCKS_VERSION_PATCH=${CPACK_PACKAGE_VERSION_PATCH}") +set_target_properties (ed25519 PROPERTIES COMPILE_FLAGS "-DED25519_CUSTOMHASH -DED25519_CUSTOMRNG ") +set_target_properties (secure node core_test slow_test qt_test cli qt qt_wallet qt_system landing PROPERTIES COMPILE_FLAGS "-std=c++11 -Werror=switch ${PLATFORM_COMPILE_FLAGS} -DQT_NO_KEYWORDS -DACTIVE_NETWORK=${ACTIVE_NETWORK} -DRAIBLOCKS_VERSION_MAJOR=${CPACK_PACKAGE_VERSION_MAJOR} -DRAIBLOCKS_VERSION_MINOR=${CPACK_PACKAGE_VERSION_MINOR} -DRAIBLOCKS_VERSION_PATCH=${CPACK_PACKAGE_VERSION_PATCH}") set_target_properties (qt_wallet qt_test PROPERTIES LINK_FLAGS "${PLATFORM_GUI_EXE_LINK_FLAGS}") if (WIN32) @@ -107,19 +111,19 @@ else (WIN32) set (PLATFORM_LIBS) endif (WIN32) -target_link_libraries (core_test node secure ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_LOG_LIBRARY} ${Boost_LOG_SETUP_LIBRARY} ${Boost_THREAD_LIBRARY} ${GTEST_MAIN_LIBRARY} ${GTEST_LIBRARY} ${CRYPTOPP_LIBRARY} ${CPPNETLIB_LIBRARIES} pthread ${PLATFORM_LIBS} ${LevelDB_LIBRARY}) +target_link_libraries (core_test ed25519 node secure ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_LOG_LIBRARY} ${Boost_LOG_SETUP_LIBRARY} ${Boost_THREAD_LIBRARY} ${GTEST_MAIN_LIBRARY} ${GTEST_LIBRARY} ${CRYPTOPP_LIBRARY} ${CPPNETLIB_LIBRARIES} pthread ${PLATFORM_LIBS} ${LevelDB_LIBRARY}) -target_link_libraries (slow_test node secure ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_LOG_LIBRARY} ${Boost_LOG_SETUP_LIBRARY} ${Boost_THREAD_LIBRARY} ${GTEST_MAIN_LIBRARY} ${GTEST_LIBRARY} ${CRYPTOPP_LIBRARY} ${CPPNETLIB_LIBRARIES} pthread ${PLATFORM_LIBS} ${LevelDB_LIBRARY}) +target_link_libraries (slow_test ed25519 node secure ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_LOG_LIBRARY} ${Boost_LOG_SETUP_LIBRARY} ${Boost_THREAD_LIBRARY} ${GTEST_MAIN_LIBRARY} ${GTEST_LIBRARY} ${CRYPTOPP_LIBRARY} ${CPPNETLIB_LIBRARIES} pthread ${PLATFORM_LIBS} ${LevelDB_LIBRARY}) -target_link_libraries (cli node secure ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_LOG_LIBRARY} ${Boost_LOG_SETUP_LIBRARY} ${Boost_THREAD_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY} ${GTEST_MAIN_LIBRARY} ${GTEST_LIBRARY} ${CRYPTOPP_LIBRARY} ${CPPNETLIB_LIBRARIES} pthread ${PLATFORM_LIBS} ${LevelDB_LIBRARY}) +target_link_libraries (cli ed25519 node secure ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_LOG_LIBRARY} ${Boost_LOG_SETUP_LIBRARY} ${Boost_THREAD_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY} ${GTEST_MAIN_LIBRARY} ${GTEST_LIBRARY} ${CRYPTOPP_LIBRARY} ${CPPNETLIB_LIBRARIES} pthread ${PLATFORM_LIBS} ${LevelDB_LIBRARY}) -target_link_libraries (landing node secure ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_LOG_LIBRARY} ${Boost_LOG_SETUP_LIBRARY} ${Boost_THREAD_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY} ${GTEST_MAIN_LIBRARY} ${GTEST_LIBRARY} ${CRYPTOPP_LIBRARY} ${CPPNETLIB_LIBRARIES} pthread ${PLATFORM_LIBS} ${LevelDB_LIBRARY}) +target_link_libraries (landing ed25519 node secure ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_LOG_LIBRARY} ${Boost_LOG_SETUP_LIBRARY} ${Boost_THREAD_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY} ${GTEST_MAIN_LIBRARY} ${GTEST_LIBRARY} ${CRYPTOPP_LIBRARY} ${CPPNETLIB_LIBRARIES} pthread ${PLATFORM_LIBS} ${LevelDB_LIBRARY}) -target_link_libraries (qt_test node secure qt ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_LOG_LIBRARY} ${Boost_LOG_SETUP_LIBRARY} ${Boost_THREAD_LIBRARY} ${GTEST_MAIN_LIBRARY} ${GTEST_LIBRARY} ${CRYPTOPP_LIBRARY} ${CPPNETLIB_LIBRARIES} Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Test ${QT_QTGUI_LIBRARY} pthread ${PLATFORM_LIBS} ${LevelDB_LIBRARY}) +target_link_libraries (qt_test ed25519 node secure qt ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_LOG_LIBRARY} ${Boost_LOG_SETUP_LIBRARY} ${Boost_THREAD_LIBRARY} ${GTEST_MAIN_LIBRARY} ${GTEST_LIBRARY} ${CRYPTOPP_LIBRARY} ${CPPNETLIB_LIBRARIES} Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Test ${QT_QTGUI_LIBRARY} pthread ${PLATFORM_LIBS} ${LevelDB_LIBRARY}) -target_link_libraries (qt_wallet node secure qt ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_LOG_LIBRARY} ${Boost_LOG_SETUP_LIBRARY} ${Boost_THREAD_LIBRARY} ${GTEST_MAIN_LIBRARY} ${GTEST_LIBRARY} ${CRYPTOPP_LIBRARY} ${CPPNETLIB_LIBRARIES} Qt5::Core Qt5::Gui Qt5::Widgets ${QT_QTGUI_LIBRARY} pthread ${PLATFORM_LIBS} ${LevelDB_LIBRARY}) +target_link_libraries (qt_wallet ed25519 node secure qt ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_LOG_LIBRARY} ${Boost_LOG_SETUP_LIBRARY} ${Boost_THREAD_LIBRARY} ${GTEST_MAIN_LIBRARY} ${GTEST_LIBRARY} ${CRYPTOPP_LIBRARY} ${CPPNETLIB_LIBRARIES} Qt5::Core Qt5::Gui Qt5::Widgets ${QT_QTGUI_LIBRARY} pthread ${PLATFORM_LIBS} ${LevelDB_LIBRARY}) -target_link_libraries (qt_system node secure qt ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_LOG_LIBRARY} ${Boost_LOG_SETUP_LIBRARY} ${Boost_THREAD_LIBRARY} ${GTEST_MAIN_LIBRARY} ${GTEST_LIBRARY} ${CRYPTOPP_LIBRARY} ${CPPNETLIB_LIBRARIES} Qt5::Core Qt5::Gui Qt5::Widgets ${QT_QTGUI_LIBRARY} pthread ${PLATFORM_LIBS} ${LevelDB_LIBRARY}) +target_link_libraries (qt_system ed25519 node secure qt ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_LOG_LIBRARY} ${Boost_LOG_SETUP_LIBRARY} ${Boost_THREAD_LIBRARY} ${GTEST_MAIN_LIBRARY} ${GTEST_LIBRARY} ${CRYPTOPP_LIBRARY} ${CPPNETLIB_LIBRARIES} Qt5::Core Qt5::Gui Qt5::Widgets ${QT_QTGUI_LIBRARY} pthread ${PLATFORM_LIBS} ${LevelDB_LIBRARY}) if (APPLE) get_filename_component (Qt5Core_framework_DIR ${Qt5_DIR}/../../QtCore.framework ABSOLUTE) diff --git a/ed25519-donna/ed25519-hash-custom.h b/ed25519-donna/ed25519-hash-custom.h index a34f3a9d..343a6d9f 100644 --- a/ed25519-donna/ed25519-hash-custom.h +++ b/ed25519-donna/ed25519-hash-custom.h @@ -9,34 +9,15 @@ void ed25519_hash(uint8_t *hash, const uint8_t *in, size_t inlen); */ -#include - -struct ed25519_hash_context +typedef struct ed25519_hash_context_t { - ed25519_hash_context () : - sha (64) - { - } - CryptoPP::SHA3 sha; -}; + void * sha; +} ed25519_hash_context; -void ed25519_hash_init (ed25519_hash_context * ctx) -{ -} +void ed25519_hash_init (ed25519_hash_context * ctx); -void ed25519_hash_update (ed25519_hash_context * ctx, uint8_t const * in, size_t inlen) -{ - ctx->sha.Update (in, inlen); -} +void ed25519_hash_update (ed25519_hash_context * ctx, uint8_t const * in, size_t inlen); -void ed25519_hash_final (ed25519_hash_context * ctx, uint8_t * out) -{ - ctx->sha.Final (out); -} +void ed25519_hash_final (ed25519_hash_context * ctx, uint8_t * out); -void ed25519_hash (uint8_t * out, uint8_t const * in, size_t inlen) -{ - ed25519_hash_context ctx; - ctx.sha.Update (in, inlen); - ctx.sha.Final (out); -} \ No newline at end of file +void ed25519_hash (uint8_t * out, uint8_t const * in, size_t inlen); \ No newline at end of file diff --git a/ed25519-donna/ed25519-randombytes-custom.h b/ed25519-donna/ed25519-randombytes-custom.h index 2133ba97..9818555f 100644 --- a/ed25519-donna/ed25519-randombytes-custom.h +++ b/ed25519-donna/ed25519-randombytes-custom.h @@ -7,14 +7,4 @@ to create random scalars */ -#include - -namespace rai -{ -extern CryptoPP::AutoSeededRandomPool random_pool; -} - -void ed25519_randombytes_unsafe (void * out, size_t outlen) -{ - rai::random_pool.GenerateBlock (reinterpret_cast (out), outlen); -} \ No newline at end of file +void ed25519_randombytes_unsafe (void * out, size_t outlen); \ No newline at end of file diff --git a/ed25519-donna/ed25519.cpp b/ed25519-donna/ed25519.c similarity index 100% rename from ed25519-donna/ed25519.cpp rename to ed25519-donna/ed25519.c diff --git a/rai/secure.cpp b/rai/secure.cpp index 171559b2..735a34e4 100644 --- a/rai/secure.cpp +++ b/rai/secure.cpp @@ -5,6 +5,38 @@ #include #include +extern "C" +{ +#include +void ed25519_randombytes_unsafe (void * out, size_t outlen) +{ + rai::random_pool.GenerateBlock (reinterpret_cast (out), outlen); +} +void ed25519_hash_init (ed25519_hash_context * ctx) +{ + ctx->sha = new CryptoPP::SHA3 (64); +} + +void ed25519_hash_update (ed25519_hash_context * ctx, uint8_t const * in, size_t inlen) +{ + reinterpret_cast (ctx->sha)->Update (in, inlen); +} + +void ed25519_hash_final (ed25519_hash_context * ctx, uint8_t * out) +{ + reinterpret_cast (ctx->sha)->Final (out); + delete reinterpret_cast (ctx->sha); +} + +void ed25519_hash (uint8_t * out, uint8_t const * in, size_t inlen) +{ + ed25519_hash_context ctx; + ed25519_hash_init (&ctx); + ed25519_hash_update (&ctx, in, inlen); + ed25519_hash_final (&ctx, out); +} +} + namespace { std::string rai_test_private_key = "34F0A37AAD20F4A260F0A5B3CB3D7FB50673212263E58A380BC10474BB039CE4";