From e5a5323642c5446599fa3444703a3fff48a4f05e Mon Sep 17 00:00:00 2001 From: Eric Frias Date: Tue, 31 Mar 2015 09:47:54 -0400 Subject: [PATCH 1/5] When formatting doubles as strings, use 17 digits of precision to ensure they are read back in without loss (up from 12 digits). Add a mode to the JSON parser to parse all real numbers into strings, so we can later parse them into doubles or another fixed/floating point format to preserve as much precision as needed --- include/fc/io/json.hpp | 3 ++- include/fc/io/json_relaxed.hpp | 18 ++++++------- src/io/json.cpp | 46 ++++++++++++++++++++-------------- src/string.cpp | 10 +++++--- 4 files changed, 44 insertions(+), 33 deletions(-) diff --git a/include/fc/io/json.hpp b/include/fc/io/json.hpp index f423803..4d97ac0 100644 --- a/include/fc/io/json.hpp +++ b/include/fc/io/json.hpp @@ -19,7 +19,8 @@ namespace fc { legacy_parser = 0, strict_parser = 1, - relaxed_parser = 2 + relaxed_parser = 2, + legacy_parser_with_string_doubles = 3 }; static ostream& to_stream( ostream& out, const fc::string& ); diff --git a/include/fc/io/json_relaxed.hpp b/include/fc/io/json_relaxed.hpp index 202fc54..2422db3 100644 --- a/include/fc/io/json_relaxed.hpp +++ b/include/fc/io/json_relaxed.hpp @@ -581,7 +581,7 @@ namespace fc { namespace json_relaxed continue; } if( skip_white_space(in) ) continue; - string key = stringFromStream( in ); + string key = json_relaxed::stringFromStream( in ); skip_white_space(in); if( in.peek() != ':' ) { @@ -589,7 +589,7 @@ namespace fc { namespace json_relaxed ("key", key) ); } in.get(); - auto val = variant_from_stream( in ); + auto val = json_relaxed::variant_from_stream( in ); obj(std::move(key),std::move(val)); skip_white_space(in); @@ -630,7 +630,7 @@ namespace fc { namespace json_relaxed continue; } if( skip_white_space(in) ) continue; - ar.push_back( variant_from_stream(in) ); + ar.push_back( json_relaxed::variant_from_stream(in) ); skip_white_space(in); } if( in.peek() != ']' ) @@ -647,7 +647,7 @@ namespace fc { namespace json_relaxed variant numberFromStream( T& in ) { try { fc::string token = tokenFromStream(in); - variant result = parseNumberOrStr( token ); + variant result = json_relaxed::parseNumberOrStr( token ); if( strict && !(result.is_int64() || result.is_uint64() || result.is_double()) ) FC_THROW_EXCEPTION( parse_error_exception, "expected: number" ); return result; @@ -700,11 +700,11 @@ namespace fc { namespace json_relaxed in.get(); continue; case '"': - return stringFromStream( in ); + return json_relaxed::stringFromStream( in ); case '{': - return objectFromStream( in ); + return json_relaxed::objectFromStream( in ); case '[': - return arrayFromStream( in ); + return json_relaxed::arrayFromStream( in ); case '-': case '+': case '.': @@ -718,7 +718,7 @@ namespace fc { namespace json_relaxed case '7': case '8': case '9': - return numberFromStream( in ); + return json_relaxed::numberFromStream( in ); // null, true, false, or 'warning' / string case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': @@ -729,7 +729,7 @@ namespace fc { namespace json_relaxed case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': case '_': case '/': - return wordFromStream( in ); + return json_relaxed::wordFromStream( in ); case 0x04: // ^D end of transmission case EOF: FC_THROW_EXCEPTION( eof_exception, "unexpected end of file" ); diff --git a/src/io/json.cpp b/src/io/json.cpp index 2890ba3..90fccc5 100644 --- a/src/io/json.cpp +++ b/src/io/json.cpp @@ -15,16 +15,15 @@ namespace fc { // forward declarations of provided functions - template variant variant_from_stream( T& in ); + template variant variant_from_stream( T& in ); template char parseEscape( T& in ); template fc::string stringFromStream( T& in ); template bool skip_white_space( T& in ); template fc::string stringFromToken( T& in ); - template variant_object objectFromStream( T& in ); - template variants arrayFromStream( T& in ); - template variant number_from_stream( T& in ); + template variant_object objectFromStream( T& in ); + template variants arrayFromStream( T& in ); + template variant number_from_stream( T& in ); template variant token_from_stream( T& in ); - template variant variant_from_stream( T& in ); void escape_string( const string& str, ostream& os ); template void to_stream( T& os, const variants& a ); template void to_stream( T& os, const variant_object& o ); @@ -168,7 +167,7 @@ namespace fc ("token", token.str() ) ); } - template + template variant_object objectFromStream( T& in ) { mutable_variant_object obj; @@ -197,7 +196,7 @@ namespace fc ("key", key) ); } in.get(); - auto val = variant_from_stream( in ); + auto val = variant_from_stream( in ); obj(std::move(key),std::move(val)); skip_white_space(in); @@ -219,7 +218,7 @@ namespace fc } FC_RETHROW_EXCEPTIONS( warn, "Error parsing object" ); } - template + template variants arrayFromStream( T& in ) { variants ar; @@ -238,7 +237,7 @@ namespace fc continue; } if( skip_white_space(in) ) continue; - ar.push_back( variant_from_stream(in) ); + ar.push_back( variant_from_stream(in) ); skip_white_space(in); } if( in.peek() != ']' ) @@ -251,7 +250,7 @@ namespace fc return ar; } - template + template variant number_from_stream( T& in ) { fc::stringstream ss; @@ -309,7 +308,7 @@ namespace fc if (str == "-." || str == ".") // check the obviously wrong things we could have encountered FC_THROW_EXCEPTION(parse_error_exception, "Can't parse token \"${token}\" as a JSON numeric constant", ("token", str)); if( dot ) - return to_double(str); + return parser_type == json::legacy_parser_with_string_doubles ? variant(str) : variant(to_double(str)); if( neg ) return to_int64(str); return to_uint64(str); @@ -386,7 +385,7 @@ namespace fc } - template + template variant variant_from_stream( T& in ) { skip_white_space(in); @@ -404,9 +403,9 @@ namespace fc case '"': return stringFromStream( in ); case '{': - return objectFromStream( in ); + return objectFromStream( in ); case '[': - return arrayFromStream( in ); + return arrayFromStream( in ); case '-': case '.': case '0': @@ -419,7 +418,7 @@ namespace fc case '7': case '8': case '9': - return number_from_stream( in ); + return number_from_stream( in ); // null, true, false, or 'warning' / string case 'n': case 't': @@ -466,7 +465,9 @@ namespace fc switch( ptype ) { case legacy_parser: - return variant_from_stream( in ); + return variant_from_stream( in ); + case legacy_parser_with_string_doubles: + return variant_from_stream( in ); case strict_parser: return json_relaxed::variant_from_stream( in ); case relaxed_parser: @@ -760,7 +761,9 @@ namespace fc switch( ptype ) { case legacy_parser: - return variant_from_stream( bi ); + return variant_from_stream( bi ); + case legacy_parser_with_string_doubles: + return variant_from_stream( bi ); case strict_parser: return json_relaxed::variant_from_stream( bi ); case relaxed_parser: @@ -774,7 +777,9 @@ namespace fc switch( ptype ) { case legacy_parser: - return variant_from_stream( in ); + return variant_from_stream( in ); + case legacy_parser_with_string_doubles: + return variant_from_stream( in ); case strict_parser: return json_relaxed::variant_from_stream( in ); case relaxed_parser: @@ -807,7 +812,10 @@ namespace fc switch( ptype ) { case legacy_parser: - variant_from_stream( in ); + variant_from_stream( in ); + break; + case legacy_parser_with_string_doubles: + variant_from_stream( in ); break; case strict_parser: json_relaxed::variant_from_stream( in ); diff --git a/src/string.cpp b/src/string.cpp index 93b6b7a..0b7cb9f 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -9,6 +9,7 @@ #include #include #include +#include /** * Implemented with std::string for now. @@ -127,11 +128,12 @@ namespace fc { FC_RETHROW_EXCEPTIONS( warn, "${i} => double", ("i",i) ) } - fc::string to_string( double d) + fc::string to_string(double d) { - std::stringstream ss; - ss << std::setprecision(12) << std::fixed << d; - return ss.str(); //boost::lexical_cast(d); + // +2 is required to ensure that the double is rounded correctly when read back in. http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html + std::stringstream ss; + ss << std::setprecision(std::numeric_limits::digits10 + 2) << std::fixed << d; + return ss.str(); } fc::string to_string( uint64_t d) From c2451f30f1d8fc4804bb3191d1dbdf4324f9fb52 Mon Sep 17 00:00:00 2001 From: Eric Frias Date: Thu, 11 Jun 2015 19:22:22 -0400 Subject: [PATCH 2/5] Add a new mode to the variant->json generator to restore the normal behavior of writing numbers out as numbers instead of strings --- include/fc/io/json.hpp | 33 ++++++++++++++---------- src/io/json.cpp | 58 +++++++++++++++++++++++------------------- 2 files changed, 51 insertions(+), 40 deletions(-) diff --git a/include/fc/io/json.hpp b/include/fc/io/json.hpp index 4d97ac0..8a46d13 100644 --- a/include/fc/io/json.hpp +++ b/include/fc/io/json.hpp @@ -22,28 +22,33 @@ namespace fc relaxed_parser = 2, legacy_parser_with_string_doubles = 3 }; + enum output_formatting + { + stringify_large_ints_and_doubles = 0, + legacy_generator = 1 + }; - static ostream& to_stream( ostream& out, const fc::string& ); - static ostream& to_stream( ostream& out, const variant& v ); - static ostream& to_stream( ostream& out, const variants& v ); - static ostream& to_stream( ostream& out, const variant_object& v ); + static ostream& to_stream( ostream& out, const fc::string&); + static ostream& to_stream( ostream& out, const variant& v, output_formatting format = stringify_large_ints_and_doubles ); + static ostream& to_stream( ostream& out, const variants& v, output_formatting format = stringify_large_ints_and_doubles ); + static ostream& to_stream( ostream& out, const variant_object& v, output_formatting format = stringify_large_ints_and_doubles ); static variant from_stream( buffered_istream& in, parse_type ptype = legacy_parser ); static variant from_string( const string& utf8_str, parse_type ptype = legacy_parser ); static variants variants_from_string( const string& utf8_str, parse_type ptype = legacy_parser ); - static string to_string( const variant& v ); - static string to_pretty_string( const variant& v ); + static string to_string( const variant& v, output_formatting format = stringify_large_ints_and_doubles ); + static string to_pretty_string( const variant& v, output_formatting format = stringify_large_ints_and_doubles ); static bool is_valid( const std::string& json_str, parse_type ptype = legacy_parser ); template - static void save_to_file( const T& v, const fc::path& fi, bool pretty = true ) + static void save_to_file( const T& v, const fc::path& fi, bool pretty = true, output_formatting format = stringify_large_ints_and_doubles ) { - save_to_file( variant(v), fi, pretty ); + save_to_file( variant(v), fi, pretty, format ); } - static void save_to_file( const variant& v, const fc::path& fi, bool pretty = true ); + static void save_to_file( const variant& v, const fc::path& fi, bool pretty = true, output_formatting format = stringify_large_ints_and_doubles ); static variant from_file( const fc::path& p, parse_type ptype = legacy_parser ); template @@ -53,19 +58,19 @@ namespace fc } template - static string to_string( const T& v ) + static string to_string( const T& v, output_formatting format = stringify_large_ints_and_doubles ) { - return to_string( variant(v) ); + return to_string( variant(v), format ); } template - static string to_pretty_string( const T& v ) + static string to_pretty_string( const T& v, output_formatting format = stringify_large_ints_and_doubles ) { - return to_pretty_string( variant(v) ); + return to_pretty_string( variant(v), format ); } template - static void save_to_file( const T& v, const std::string& p, bool pretty = true ) + static void save_to_file( const T& v, const std::string& p, bool pretty = true, output_formatting format = stringify_large_ints_and_doubles ) { save_to_file( variant(v), fc::path(p), pretty ); } diff --git a/src/io/json.cpp b/src/io/json.cpp index 90fccc5..84446e1 100644 --- a/src/io/json.cpp +++ b/src/io/json.cpp @@ -25,9 +25,9 @@ namespace fc template variant number_from_stream( T& in ); template variant token_from_stream( T& in ); void escape_string( const string& str, ostream& os ); - template void to_stream( T& os, const variants& a ); - template void to_stream( T& os, const variant_object& o ); - template void to_stream( T& os, const variant& v ); + template void to_stream( T& os, const variants& a, json::output_formatting format ); + template void to_stream( T& os, const variant_object& o, json::output_formatting format ); + template void to_stream( T& os, const variant& v, json::output_formatting format ); fc::string pretty_print( const fc::string& v, uint8_t indent ); } @@ -549,14 +549,14 @@ namespace fc } template - void to_stream( T& os, const variants& a ) + void to_stream( T& os, const variants& a, json::output_formatting format ) { os << '['; auto itr = a.begin(); while( itr != a.end() ) { - to_stream( os, *itr ); + to_stream( os, *itr, format ); ++itr; if( itr != a.end() ) os << ','; @@ -564,7 +564,7 @@ namespace fc os << ']'; } template - void to_stream( T& os, const variant_object& o ) + void to_stream( T& os, const variant_object& o, json::output_formatting format ) { os << '{'; auto itr = o.begin(); @@ -573,7 +573,7 @@ namespace fc { escape_string( itr->key(), os ); os << ':'; - to_stream( os, itr->value() ); + to_stream( os, itr->value(), format ); ++itr; if( itr != o.end() ) os << ','; @@ -582,7 +582,7 @@ namespace fc } template - void to_stream( T& os, const variant& v ) + void to_stream( T& os, const variant& v, json::output_formatting format ) { switch( v.get_type() ) { @@ -592,24 +592,30 @@ namespace fc case variant::int64_type: { int64_t i = v.as_int64(); - if( i > 0xffffffff ) + if( format == json::stringify_large_ints_and_doubles && + i > 0xffffffff ) os << '"'< 0xffffffff ) + if( format == json::stringify_large_ints_and_doubles && + i > 0xffffffff ) os << '"'< Date: Sat, 13 Jun 2015 13:11:13 -0400 Subject: [PATCH 3/5] Update websocketpp submodule --- .gitmodules | 4 ++-- vendor/websocketpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitmodules b/.gitmodules index cccd56b..b5f9f0c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "vendor/websocketpp"] - path = vendor/websocketpp - url = https://github.com/zaphoyd/websocketpp + path = vendor/websocketpp + url = https://github.com/zaphoyd/websocketpp diff --git a/vendor/websocketpp b/vendor/websocketpp index 13f6da6..c5510d6 160000 --- a/vendor/websocketpp +++ b/vendor/websocketpp @@ -1 +1 @@ -Subproject commit 13f6da6f81207ae7e67f0e7d25ed0e3cc2ec2f9c +Subproject commit c5510d6de04917812b910a8dd44735c1f17061d9 From f7cf9abe558a05c38091d0fce689aa2a91a993b5 Mon Sep 17 00:00:00 2001 From: Vikram Rajkumar Date: Sat, 13 Jun 2015 13:39:43 -0400 Subject: [PATCH 4/5] Add secp256k1-zkp submodule --- .gitmodules | 5 +++- CMakeLists.txt | 71 +++++++++++++++++++++++++++++++++----------- tests/blind.cpp | 6 ++-- vendor/secp256k1-zkp | 1 + 4 files changed, 60 insertions(+), 23 deletions(-) create mode 160000 vendor/secp256k1-zkp diff --git a/.gitmodules b/.gitmodules index b5f9f0c..3fae9b1 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ +[submodule "vendor/secp256k1-zkp"] + path = vendor/secp256k1-zkp + url = https://github.com/ElementsProject/secp256k1-zkp.git [submodule "vendor/websocketpp"] path = vendor/websocketpp - url = https://github.com/zaphoyd/websocketpp + url = https://github.com/zaphoyd/websocketpp.git diff --git a/CMakeLists.txt b/CMakeLists.txt index d84fc9d..6116e71 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,6 +49,42 @@ SET( ECC_REST src/crypto/elliptic_impl_priv.cpp ) ENDIF( ECC_IMPL STREQUAL mixed ) ENDIF( ECC_IMPL STREQUAL openssl ) +# Configure secp256k1-zkp + +set( SECP256K1_DIR "${CMAKE_CURRENT_SOURCE_DIR}/vendor/secp256k1-zkp" ) + +file( GLOB SECP256K1_SOURCES "${SECP256K1_DIR}/src/secp256k1.c" ) +add_library( secp256k1 ${SECP256K1_SOURCES} ) + +target_include_directories( secp256k1 PRIVATE "${SECP256K1_DIR}" PUBLIC "${SECP256K1_DIR}/include" ) + +# ***Will only work for Clang on 64-bit Mac/Linux*** +set( SECP256K1_BUILD_DEFINES + HAVE_BUILTIN_CLZLL + HAVE_BUILTIN_EXPECT + HAVE_DLFCN_H + HAVE_INTTYPES_H + HAVE_LIBCRYPTO + HAVE_MEMORY_H + HAVE_STDINT_H + HAVE_STDLIB_H + HAVE_STRINGS_H + HAVE_STRING_H + HAVE_SYS_STAT_H + HAVE_SYS_TYPES_H + HAVE_UNISTD_H + HAVE___INT128 + STDC_HEADERS + USE_FIELD_5X52 + USE_FIELD_INV_BUILTIN + USE_NUM_NONE + USE_SCALAR_4X64 + USE_SCALAR_INV_BUILTIN +) +set_target_properties( secp256k1 PROPERTIES COMPILE_DEFINITIONS "${SECP256K1_BUILD_DEFINES}" LINKER_LANGUAGE C ) + +# End configure secp256k1-zkp + IF( WIN32 ) MESSAGE(STATUS "Configuring fc to build on Win32") @@ -77,7 +113,7 @@ ELSE(WIN32) LIST(APPEND BOOST_COMPONENTS coroutine) - FIND_PACKAGE(Boost 1.53 REQUIRED COMPONENTS ${BOOST_COMPONENTS}) + FIND_PACKAGE(Boost 1.53 REQUIRED COMPONENTS ${BOOST_COMPONENTS}) SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a;.so") @@ -115,8 +151,8 @@ set( fc_sources src/thread/thread_specific.cpp src/thread/future.cpp src/thread/task.cpp - src/thread/spin_lock.cpp - src/thread/spin_yield_lock.cpp + src/thread/spin_lock.cpp + src/thread/spin_yield_lock.cpp src/thread/mutex.cpp src/thread/non_preemptable_scope_check.cpp src/asio.cpp @@ -139,7 +175,7 @@ set( fc_sources src/interprocess/mmap_struct.cpp src/rpc/json_connection.cpp src/rpc/cli.cpp - src/log/log_message.cpp + src/log/log_message.cpp src/log/logger.cpp src/log/appender.cpp src/log/console_appender.cpp @@ -190,12 +226,11 @@ set( fc_sources ${SALSA_SRC} ) - SET_PROPERTY( SOURCE + SET_PROPERTY( SOURCE vendor/salsa20/salsa20.s PROPERTY LANGUAGE C) -file(GLOB_RECURSE fc_headers ${CMAKE_CURRENT_SOURCE_DIR} - *.hpp *.h) +file( GLOB_RECURSE fc_headers ${CMAKE_CURRENT_SOURCE_DIR} *.hpp *.h ) set( sources ${fc_sources} @@ -233,12 +268,12 @@ endif(WIN32) IF(WIN32) target_compile_definitions(fc PUBLIC WIN32 NOMINMAX _WIN32_WINNT=0x0501 _CRT_SECURE_NO_WARNINGS - _SCL_SERCURE_NO_WARNINGS + _SCL_SERCURE_NO_WARNINGS # Needed to disable MSVC autolinking feature (#pragma comment) BOOST_ALL_NO_LIB ) # Activate C++ exception handling, assume extern C calls don't throw - # Add /U options to be sure settings specific to dynamic boost link are ineffective + # Add /U options to be sure settings specific to dynamic boost link are ineffective target_compile_options(fc PUBLIC /EHsc /UBOOST_ALL_DYN_LINK /UBOOST_LINKING_PYTHON /UBOOST_DEBUG_PYTHON) ELSE() SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -Wall") @@ -252,7 +287,7 @@ ELSE() SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -fnon-call-exceptions") ENDIF() ENDIF() - + target_include_directories(fc PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include ${Boost_INCLUDE_DIR} @@ -260,13 +295,14 @@ target_include_directories(fc "${readline_includes}" PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} - #${CMAKE_CURRENT_SOURCE_DIR}/vendor/scrypt-jane - ${CMAKE_CURRENT_SOURCE_DIR}/vendor/cyoencode-1.0.2/src ${CMAKE_CURRENT_SOURCE_DIR}/vendor/boost_1.51/include - ${CMAKE_CURRENT_SOURCE_DIR}/vendor/salsa20 + ${CMAKE_CURRENT_SOURCE_DIR}/vendor/cyoencode-1.0.2/src ${CMAKE_CURRENT_SOURCE_DIR}/vendor/easylzma/src + ${CMAKE_CURRENT_SOURCE_DIR}/vendor/salsa20 + #${CMAKE_CURRENT_SOURCE_DIR}/vendor/scrypt-jane ${CMAKE_CURRENT_SOURCE_DIR}/vendor/udt4/src ${CMAKE_CURRENT_SOURCE_DIR}/vendor/websocketpp + ${CMAKE_CURRENT_SOURCE_DIR}/vendor/secp256k1-zkp ) #target_link_libraries( fc PUBLIC easylzma_static scrypt udt ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} ${ZLIB_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS} ${RPCRT4} ${CMAKE_DL_LIBS} ${rt_library} ${ECC_LIB} ) @@ -288,8 +324,8 @@ ENDIF() add_executable( api tests/api.cpp ) target_link_libraries( api fc ) -#add_executable( blind tests/blind.cpp ) -#target_link_libraries( blind fc ) +add_executable( blind tests/blind.cpp ) +target_link_libraries( blind fc ) include_directories( vendor/websocketpp ) @@ -363,7 +399,7 @@ if(WIN32) endif() endforeach() - + set(INTERFACE_LINK_PDB_DEBUG) set(SHARED_LIBRARIES_DEBUG) foreach(boost_import_lib ${Boost_LIBRARIES_DEBUG}) @@ -430,9 +466,8 @@ SET(POST_BUILD_STEP_COMMANDS ${POST_BUILD_STEP_COMMANDS} COMMAND ${CMAKE_COMMAND} -E copy_if_different "${OPENSSL_ROOT_DIR}/ssl/openssl.cnf" "${OPENSSL_CONF_TARGET}/openssl.cnf") ENDIF(WIN32) -ADD_CUSTOM_COMMAND(TARGET fc POST_BUILD ${POST_BUILD_STEP_COMMANDS} +ADD_CUSTOM_COMMAND(TARGET fc POST_BUILD ${POST_BUILD_STEP_COMMANDS} COMMENT "Copying OpenSSL/ssl/openssl.cnf into target directory." ) MESSAGE(STATUS "Finished fc module configuration...") - diff --git a/tests/blind.cpp b/tests/blind.cpp index bd74519..f1713b2 100644 --- a/tests/blind.cpp +++ b/tests/blind.cpp @@ -5,8 +5,6 @@ #include extern "C" { -#include -#include #include } //struct secp256k1_scalar_t { uint64_t v[4]; }; @@ -65,7 +63,7 @@ int main( int argc, char** argv ) auto B1 = fc::sha256::hash("B1"); auto B2 = fc::sha256::hash("B2"); auto B3 = fc::sha256::hash("B3"); - + //secp256k1_scalar_get_b32((unsigned char*)&B1, (const secp256k1_scalar_t*)&B2); //B1 = fc::variant("b2e5da56ef9f2a34d3e22fd12634bc99261e95c87b9960bf94ed3d27b30").as(); @@ -84,7 +82,7 @@ int main( int argc, char** argv ) } - } + } catch ( const fc::exception& e ) { edump((e.to_detail_string())); diff --git a/vendor/secp256k1-zkp b/vendor/secp256k1-zkp new file mode 160000 index 0000000..bd06794 --- /dev/null +++ b/vendor/secp256k1-zkp @@ -0,0 +1 @@ +Subproject commit bd067945ead3b514fba884abd0de95fc4b5db9ae From 10e747409c5d656e794cb2e10cc51d5e31978cf1 Mon Sep 17 00:00:00 2001 From: Eric Frias Date: Mon, 15 Jun 2015 14:38:33 -0400 Subject: [PATCH 5/5] Fix FC win32 compiling (secp256k1 related errors) --- CMakeLists.txt | 83 +++++++++++++++++------------- src/crypto/_elliptic_impl_priv.hpp | 6 +-- src/crypto/elliptic_impl_priv.cpp | 6 +-- src/crypto/elliptic_secp256k1.cpp | 4 +- tests/blind.cpp | 6 +-- 5 files changed, 58 insertions(+), 47 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6116e71..1d847c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,50 +39,59 @@ SET( Boost_USE_STATIC_LIBS ON CACHE STRING "ON or OFF" ) IF( ECC_IMPL STREQUAL openssl ) -SET( ECC_REST src/crypto/elliptic_impl_pub.cpp ) + SET( ECC_REST src/crypto/elliptic_impl_pub.cpp ) ELSE( ECC_IMPL STREQUAL openssl ) -SET( ECC_LIB secp256k1 ) -IF( ECC_IMPL STREQUAL mixed ) -SET( ECC_REST src/crypto/elliptic_impl_priv.cpp src/crypto/elliptic_impl_pub.cpp ) -ELSE( ECC_IMPL STREQUAL mixed ) -SET( ECC_REST src/crypto/elliptic_impl_priv.cpp ) -ENDIF( ECC_IMPL STREQUAL mixed ) + SET( ECC_LIB secp256k1 ) + IF( ECC_IMPL STREQUAL mixed ) + SET( ECC_REST src/crypto/elliptic_impl_priv.cpp src/crypto/elliptic_impl_pub.cpp ) + ELSE( ECC_IMPL STREQUAL mixed ) + SET( ECC_REST src/crypto/elliptic_impl_priv.cpp ) + ENDIF( ECC_IMPL STREQUAL mixed ) ENDIF( ECC_IMPL STREQUAL openssl ) # Configure secp256k1-zkp - + set( SECP256K1_DIR "${CMAKE_CURRENT_SOURCE_DIR}/vendor/secp256k1-zkp" ) - + file( GLOB SECP256K1_SOURCES "${SECP256K1_DIR}/src/secp256k1.c" ) add_library( secp256k1 ${SECP256K1_SOURCES} ) - + target_include_directories( secp256k1 PRIVATE "${SECP256K1_DIR}" PUBLIC "${SECP256K1_DIR}/include" ) + -# ***Will only work for Clang on 64-bit Mac/Linux*** -set( SECP256K1_BUILD_DEFINES - HAVE_BUILTIN_CLZLL - HAVE_BUILTIN_EXPECT - HAVE_DLFCN_H - HAVE_INTTYPES_H - HAVE_LIBCRYPTO - HAVE_MEMORY_H - HAVE_STDINT_H - HAVE_STDLIB_H - HAVE_STRINGS_H - HAVE_STRING_H - HAVE_SYS_STAT_H - HAVE_SYS_TYPES_H - HAVE_UNISTD_H - HAVE___INT128 - STDC_HEADERS - USE_FIELD_5X52 - USE_FIELD_INV_BUILTIN - USE_NUM_NONE - USE_SCALAR_4X64 - USE_SCALAR_INV_BUILTIN -) +if( WIN32 ) + set( SECP256K1_BUILD_DEFINES + USE_FIELD_10X26 + USE_FIELD_INV_BUILTIN + USE_NUM_NONE + USE_SCALAR_8X32 + USE_SCALAR_INV_BUILTIN ) +else() + # ***Will only work for Clang on 64-bit Mac/Linux*** + set( SECP256K1_BUILD_DEFINES + HAVE_BUILTIN_CLZLL + HAVE_BUILTIN_EXPECT + HAVE_DLFCN_H + HAVE_INTTYPES_H + HAVE_LIBCRYPTO + HAVE_MEMORY_H + HAVE_STDINT_H + HAVE_STDLIB_H + HAVE_STRINGS_H + HAVE_STRING_H + HAVE_SYS_STAT_H + HAVE_SYS_TYPES_H + HAVE_UNISTD_H + HAVE___INT128 + STDC_HEADERS + USE_FIELD_5X52 + USE_FIELD_INV_BUILTIN + USE_NUM_NONE + USE_SCALAR_4X64 + USE_SCALAR_INV_BUILTIN + ) +endif() set_target_properties( secp256k1 PROPERTIES COMPILE_DEFINITIONS "${SECP256K1_BUILD_DEFINES}" LINKER_LANGUAGE C ) - # End configure secp256k1-zkp IF( WIN32 ) @@ -324,8 +333,10 @@ ENDIF() add_executable( api tests/api.cpp ) target_link_libraries( api fc ) -add_executable( blind tests/blind.cpp ) -target_link_libraries( blind fc ) +if( ECC_IMPL STREQUAL secp256k1 ) + add_executable( blind tests/blind.cpp ) + target_link_libraries( blind fc ) +endif() include_directories( vendor/websocketpp ) diff --git a/src/crypto/_elliptic_impl_priv.hpp b/src/crypto/_elliptic_impl_priv.hpp index 4da6a62..8c2a1ab 100644 --- a/src/crypto/_elliptic_impl_priv.hpp +++ b/src/crypto/_elliptic_impl_priv.hpp @@ -14,10 +14,10 @@ void _init_lib(); class private_key_impl { public: - private_key_impl() noexcept; - private_key_impl( const private_key_impl& cpy ) noexcept; + private_key_impl() BOOST_NOEXCEPT; + private_key_impl( const private_key_impl& cpy ) BOOST_NOEXCEPT; - private_key_impl& operator=( const private_key_impl& pk ) noexcept; + private_key_impl& operator=( const private_key_impl& pk ) BOOST_NOEXCEPT; private_key_secret _key; }; diff --git a/src/crypto/elliptic_impl_priv.cpp b/src/crypto/elliptic_impl_priv.cpp index 39e4ceb..ad79ebe 100644 --- a/src/crypto/elliptic_impl_priv.cpp +++ b/src/crypto/elliptic_impl_priv.cpp @@ -9,18 +9,18 @@ namespace fc { namespace ecc { namespace detail { - private_key_impl::private_key_impl() noexcept + private_key_impl::private_key_impl() BOOST_NOEXCEPT { _init_lib(); } - private_key_impl::private_key_impl( const private_key_impl& cpy ) noexcept + private_key_impl::private_key_impl( const private_key_impl& cpy ) BOOST_NOEXCEPT { _init_lib(); this->_key = cpy._key; } - private_key_impl& private_key_impl::operator=( const private_key_impl& pk ) noexcept + private_key_impl& private_key_impl::operator=( const private_key_impl& pk ) BOOST_NOEXCEPT { _key = pk._key; return *this; diff --git a/src/crypto/elliptic_secp256k1.cpp b/src/crypto/elliptic_secp256k1.cpp index 1a7826c..37cf8cd 100644 --- a/src/crypto/elliptic_secp256k1.cpp +++ b/src/crypto/elliptic_secp256k1.cpp @@ -29,12 +29,12 @@ namespace fc { namespace ecc { class public_key_impl { public: - public_key_impl() noexcept + public_key_impl() BOOST_NOEXCEPT { _init_lib(); } - public_key_impl( const public_key_impl& cpy ) noexcept + public_key_impl( const public_key_impl& cpy ) BOOST_NOEXCEPT : _key( cpy._key ) { _init_lib(); diff --git a/tests/blind.cpp b/tests/blind.cpp index f1713b2..31fffdd 100644 --- a/tests/blind.cpp +++ b/tests/blind.cpp @@ -4,9 +4,9 @@ #include #include -extern "C" { -#include -} +//extern "C" { +//#include +//} //struct secp256k1_scalar_t { uint64_t v[4]; }; //extern "C" { void secp256k1_scalar_get_b32(unsigned char *bin, const struct secp256k1_scalar_t* a); }