diff --git a/CMakeLists.txt b/CMakeLists.txt index 6daae5863..bad24074e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,11 +7,11 @@ PROJECT( fc ) set( CMAKE_CXX_STANDARD 14 ) SET( CMAKE_CXX_STANDARD_REQUIRED ON ) -if( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" ) +if( "${CMAKE_CXX_COMPILER_ID}" MATCHES "^(Apple)?Clang|GNU$" ) set( CMAKE_CXX_EXTENSIONS ON ) # for __int128 support -else( GNU ) +else( "${CMAKE_CXX_COMPILER_ID}" MATCHES "^(Apple)?Clang|GNU$" ) set( CMAKE_CXX_EXTENSIONS OFF ) -endif( GNU ) +endif( "${CMAKE_CXX_COMPILER_ID}" MATCHES "^(Apple)?Clang|GNU$" ) MESSAGE(STATUS "Configuring project fc located in: ${CMAKE_CURRENT_SOURCE_DIR}") SET( CMAKE_AUTOMOC OFF ) diff --git a/include/fc/asio.hpp b/include/fc/asio.hpp index 4c330c423..bc9377dd3 100644 --- a/include/fc/asio.hpp +++ b/include/fc/asio.hpp @@ -102,7 +102,7 @@ namespace asio { */ template size_t read( AsyncReadStream& s, const MutableBufferSequence& buf ) { - promise::ptr p(new promise("fc::asio::read")); + promise::ptr p = promise::create("fc::asio::read"); boost::asio::async_read( s, buf, detail::read_write_handler(p) ); return p->wait(); } @@ -249,7 +249,6 @@ namespace asio { */ template void accept( AcceptorType& acc, SocketType& sock ) { - //promise::ptr p( new promise("fc::asio::tcp::accept") ); promise::ptr p = promise::create("fc::asio::tcp::accept"); acc.async_accept( sock, boost::bind( fc::asio::detail::error_handler, p, _1 ) ); p->wait(); diff --git a/include/fc/network/tcp_socket.hpp b/include/fc/network/tcp_socket.hpp index fe6b83737..9bb6ea523 100644 --- a/include/fc/network/tcp_socket.hpp +++ b/include/fc/network/tcp_socket.hpp @@ -51,7 +51,7 @@ namespace fc { friend class tcp_server; class impl; #ifdef _WIN64 - fc::fwd my; + fc::fwd my; #else fc::fwd my; #endif diff --git a/include/fc/reflect/reflect.hpp b/include/fc/reflect/reflect.hpp index 3bf0ef7e2..75783601f 100644 --- a/include/fc/reflect/reflect.hpp +++ b/include/fc/reflect/reflect.hpp @@ -175,7 +175,7 @@ template<> struct reflector { \ { \ i = boost::lexical_cast(s); \ } \ - catch( const boost::bad_lexical_cast& e ) \ + catch( const boost::bad_lexical_cast& ) \ { \ fc::throw_bad_enum_cast( s, BOOST_PP_STRINGIZE(ENUM) ); \ } \ diff --git a/include/fc/static_variant.hpp b/include/fc/static_variant.hpp index 7ed4d9041..6f1841cd6 100644 --- a/include/fc/static_variant.hpp +++ b/include/fc/static_variant.hpp @@ -222,7 +222,7 @@ static const std::array init_wrappers( Visitor& v, Data d, typename Visitor::result_type(**funcs)(Visitor&,Data) = 0 ) { std::array result{}; - if( !funcs ) funcs = result.begin(); + if( !funcs ) funcs = result.data(); *funcs++ = [] ( Visitor& v, Data d ) { return v( *reinterpret_cast( d ) ); }; init_wrappers( v, d, funcs ); return result; @@ -240,7 +240,7 @@ static const std::array init_const_wrappers( Visitor& v, Data d, typename Visitor::result_type(**funcs)(Visitor&,Data) = 0 ) { std::array result{}; - if( !funcs ) funcs = result.begin(); + if( !funcs ) funcs = result.data(); *funcs++ = [] ( Visitor& v, Data d ) { return v( *reinterpret_cast( d ) ); }; init_const_wrappers( v, d, funcs ); return result; diff --git a/src/crypto/elliptic_common.cpp b/src/crypto/elliptic_common.cpp index 56eeebcbd..dd89c3a5b 100644 --- a/src/crypto/elliptic_common.cpp +++ b/src/crypto/elliptic_common.cpp @@ -55,7 +55,7 @@ namespace fc { namespace ecc { static chr37 _derive_message( unsigned char first, const unsigned char* key32, int i ) { chr37 result; - unsigned char* dest = result.begin(); + unsigned char* dest = result.data(); *dest++ = first; memcpy( dest, key32, 32 ); dest += 32; _put( &dest, i ); @@ -64,7 +64,7 @@ namespace fc { namespace ecc { chr37 _derive_message( const public_key_data& key, int i ) { - return _derive_message( *key.begin(), key.begin() + 1, i ); + return _derive_message( *key.data(), key.data() + 1, i ); } static chr37 _derive_message( const private_key_secret& key, int i ) @@ -142,9 +142,9 @@ namespace fc { namespace ecc { sha256 check = sha256::hash((char*) key.data(), sizeof(key)); static_assert(sizeof(key) + 4 == 37, "Elliptic public key size (or its hash) is incorrect"); detail::chr37 data; - memcpy(data.data(), key.begin(), key.size()); - memcpy(data.begin() + key.size(), (const char*)check._hash, 4); - return fc::to_base58((char*) data.begin(), data.size()); + memcpy(data.data(), key.data(), key.size()); + memcpy(data.data() + key.size(), (const char*)check._hash, 4); + return fc::to_base58((char*) data.data(), data.size()); } public_key public_key::from_base58( const std::string& b58 ) @@ -163,7 +163,7 @@ namespace fc { namespace ecc { unsigned int public_key::fingerprint() const { public_key_data key = serialize(); - ripemd160 hash = ripemd160::hash( sha256::hash( (char*) key.begin(), key.size() ) ); + ripemd160 hash = ripemd160::hash( sha256::hash( (char*) key.data(), key.size() ) ); unsigned char* fp = (unsigned char*) hash._hash; return (fp[0] << 24) | (fp[1] << 16) | (fp[2] << 8) | fp[3]; } @@ -233,8 +233,8 @@ namespace fc { namespace ecc { { size_t buf_len = key.size() + 4; char *buffer = (char*)alloca(buf_len); - memcpy( buffer, key.begin(), key.size() ); - fc::sha256 double_hash = fc::sha256::hash( fc::sha256::hash( (char*) key.begin(), key.size() )); + memcpy( buffer, key.data(), key.size() ); + fc::sha256 double_hash = fc::sha256::hash( fc::sha256::hash( (char*) key.data(), key.size() )); memcpy( buffer + key.size(), double_hash.data(), 4 ); return fc::to_base58( buffer, buf_len ); } @@ -260,14 +260,14 @@ namespace fc { namespace ecc { extended_key_data extended_public_key::serialize_extended() const { extended_key_data result; - unsigned char* dest = (unsigned char*) result.begin(); + unsigned char* dest = (unsigned char*) result.data(); detail::_put( &dest, BTC_EXT_PUB_MAGIC ); *dest++ = depth; detail::_put( &dest, parent_fp ); detail::_put( &dest, child_num ); memcpy( dest, c.data(), c.data_size() ); dest += 32; public_key_data key = serialize(); - memcpy( dest, key.begin(), key.size() ); + memcpy( dest, key.data(), key.size() ); return result; } @@ -293,7 +293,7 @@ namespace fc { namespace ecc { fc::sha256 chain; memcpy( chain.data(), ptr, chain.data_size() ); ptr += chain.data_size(); public_key_data key; - memcpy( key.begin(), ptr, key.size() ); + memcpy( key.data(), ptr, key.size() ); return extended_public_key( key, chain, cn, fp, d ); } @@ -311,7 +311,7 @@ namespace fc { namespace ecc { { const detail::chr37 data = detail::_derive_message( get_public_key().serialize(), i ); hmac_sha512 mac; - fc::sha512 l = mac.digest( c.data(), c.data_size(), (char*) data.begin(), data.size() ); + fc::sha512 l = mac.digest( c.data(), c.data_size(), (char*) data.data(), data.size() ); return private_derive_rest( l, i ); } @@ -320,14 +320,14 @@ namespace fc { namespace ecc { hmac_sha512 mac; private_key_secret key = get_secret(); const detail::chr37 data = detail::_derive_message( key, i ); - fc::sha512 l = mac.digest( c.data(), c.data_size(), (char*) data.begin(), data.size() ); + fc::sha512 l = mac.digest( c.data(), c.data_size(), (char*) data.data(), data.size() ); return private_derive_rest( l, i ); } extended_key_data extended_private_key::serialize_extended() const { extended_key_data result; - unsigned char* dest = (unsigned char*) result.begin(); + unsigned char* dest = (unsigned char*) result.data(); detail::_put( &dest, BTC_EXT_PRIV_MAGIC ); *dest++ = depth; detail::_put( &dest, parent_fp ); diff --git a/src/crypto/elliptic_impl_priv.cpp b/src/crypto/elliptic_impl_priv.cpp index 585ffdef1..326392753 100644 --- a/src/crypto/elliptic_impl_priv.cpp +++ b/src/crypto/elliptic_impl_priv.cpp @@ -72,7 +72,8 @@ namespace fc { namespace ecc { FC_ASSERT( my->_key != empty_priv ); public_key_data pub; unsigned int pk_len; - FC_ASSERT( secp256k1_ec_pubkey_create( detail::_get_context(), (unsigned char*) pub.begin(), (int*) &pk_len, (unsigned char*) my->_key.data(), 1 ) ); + FC_ASSERT( secp256k1_ec_pubkey_create( detail::_get_context(), pub.data(), (int*) &pk_len, + (unsigned char*) my->_key.data(), 1 ) ); FC_ASSERT( pk_len == pub.size() ); return public_key(pub); } @@ -93,9 +94,11 @@ namespace fc { namespace ecc { unsigned int counter = 0; do { - FC_ASSERT( secp256k1_ecdsa_sign_compact( detail::_get_context(), (unsigned char*) digest.data(), (unsigned char*) result.begin() + 1, (unsigned char*) my->_key.data(), extended_nonce_function, &counter, &recid )); + FC_ASSERT( secp256k1_ecdsa_sign_compact( detail::_get_context(), (unsigned char*) digest.data(), + result.data() + 1, (unsigned char*) my->_key.data(), + extended_nonce_function, &counter, &recid )); } while( require_canonical && !public_key::is_canonical( result ) ); - result.begin()[0] = 27 + 4 + recid; + result.data()[0] = 27 + 4 + recid; return result; } diff --git a/src/crypto/elliptic_secp256k1.cpp b/src/crypto/elliptic_secp256k1.cpp index 7f8d84157..b180d44a3 100644 --- a/src/crypto/elliptic_secp256k1.cpp +++ b/src/crypto/elliptic_secp256k1.cpp @@ -53,7 +53,7 @@ namespace fc { namespace ecc { public_key_data _key; }; - typedef std::array chr37; + typedef std::array chr37; chr37 _derive_message( const public_key_data& key, int i ); fc::sha256 _left( const fc::sha512& v ); fc::sha256 _right( const fc::sha512& v ); @@ -70,8 +70,9 @@ namespace fc { namespace ecc { FC_ASSERT( my->_key != empty_priv ); FC_ASSERT( other.my->_key != empty_pub ); public_key_data pub(other.my->_key); - FC_ASSERT( secp256k1_ec_pubkey_tweak_mul( detail::_get_context(), pub.begin(), pub.size(), (unsigned char*) my->_key.data() ) ); - return fc::sha512::hash( (char*) pub.begin() + 1, pub.size() - 1 ); + FC_ASSERT( secp256k1_ec_pubkey_tweak_mul( detail::_get_context(), pub.data(), pub.size(), + (unsigned char*) my->_key.data() ) ); + return fc::sha512::hash( (char*) pub.data() + 1, pub.size() - 1 ); } @@ -104,8 +105,9 @@ namespace fc { namespace ecc { { FC_ASSERT( my->_key != empty_pub ); public_key_data new_key; - memcpy( new_key.begin(), my->_key.begin(), new_key.size() ); - FC_ASSERT( secp256k1_ec_pubkey_tweak_add( detail::_get_context(), new_key.begin(), new_key.size(), (unsigned char*) digest.data() ) ); + memcpy( new_key.data(), my->_key.data(), new_key.size() ); + FC_ASSERT( secp256k1_ec_pubkey_tweak_add( detail::_get_context(), new_key.data(), new_key.size(), + (unsigned char*) digest.data() ) ); return public_key( new_key ); } @@ -126,8 +128,8 @@ namespace fc { namespace ecc { FC_ASSERT( my->_key != empty_pub ); public_key_point_data dat; unsigned int pk_len = my->_key.size(); - memcpy( dat.begin(), my->_key.begin(), pk_len ); - FC_ASSERT( secp256k1_ec_pubkey_decompress( detail::_get_context(), dat.begin(), (int*) &pk_len ) ); + memcpy( dat.data(), my->_key.data(), pk_len ); + FC_ASSERT( secp256k1_ec_pubkey_decompress( detail::_get_context(), dat.data(), (int*) &pk_len ) ); FC_ASSERT( pk_len == dat.size() ); return dat; } @@ -142,7 +144,7 @@ namespace fc { namespace ecc { key = o2i_ECPublicKey( &key, &front, sizeof(dat) ); FC_ASSERT( key ); EC_KEY_set_conv_form( key, POINT_CONVERSION_COMPRESSED ); - unsigned char* buffer = my->_key.begin(); + unsigned char* buffer = my->_key.data(); i2o_ECPublicKey( key, &buffer ); // FIXME: questionable memory handling EC_KEY_free( key ); } @@ -165,7 +167,9 @@ namespace fc { namespace ecc { } unsigned int pk_len; - FC_ASSERT( secp256k1_ecdsa_recover_compact( detail::_get_context(), (unsigned char*) digest.data(), c.begin() + 1, my->_key.begin(), (int*) &pk_len, 1, (*c.begin() - 27) & 3 ) ); + FC_ASSERT( secp256k1_ecdsa_recover_compact( detail::_get_context(), (unsigned char*) digest.data(), + c.data() + 1, my->_key.data(), (int*) &pk_len, 1, + (*c.data() - 27) & 3 ) ); FC_ASSERT( pk_len == my->_key.size() ); } @@ -178,10 +182,11 @@ namespace fc { namespace ecc { hmac_sha512 mac; public_key_data key = serialize(); const detail::chr37 data = detail::_derive_message( key, i ); - fc::sha512 l = mac.digest( c.data(), c.data_size(), data.begin(), data.size() ); + fc::sha512 l = mac.digest( c.data(), c.data_size(), (const char*) data.data(), data.size() ); fc::sha256 left = detail::_left(l); FC_ASSERT( left < detail::get_curve_order() ); - FC_ASSERT( secp256k1_ec_pubkey_tweak_add( detail::_get_context(), key.begin(), key.size(), (unsigned char*) left.data() ) > 0 ); + FC_ASSERT( secp256k1_ec_pubkey_tweak_add( detail::_get_context(), key.data(), key.size(), + (unsigned char*) left.data() ) > 0 ); // FIXME: check validity - if left + key == infinity then invalid extended_public_key result( key, detail::_right(l), i, fingerprint(), depth + 1 ); return result; diff --git a/src/variant.cpp b/src/variant.cpp index 9eb625176..7a527e934 100644 --- a/src/variant.cpp +++ b/src/variant.cpp @@ -11,6 +11,10 @@ #include #include +#ifdef __APPLE__ +#include +#endif + namespace fc { @@ -675,12 +679,26 @@ void from_variant( const variant& var, std::vector& vo, uint32_t max_depth void to_variant( const uint128_t& var, variant& vo, uint32_t max_depth ) { +#ifdef __APPLE__ + boost::multiprecision::uint128_t helper = uint128_hi64( var ); + helper <<= 64; + helper += uint128_lo64( var ); + vo = boost::lexical_cast( helper ); +#else vo = boost::lexical_cast( var ); +#endif } void from_variant( const variant& var, uint128_t& vo, uint32_t max_depth ) { +#ifdef __APPLE__ + boost::multiprecision::uint128_t helper = boost::lexical_cast( var.as_string() ); + vo = static_cast( helper >> 64 ); + vo <<= 64; + vo += static_cast( helper & 0xffffffffffffffffULL ); +#else vo = boost::lexical_cast( var.as_string() ); +#endif } #ifdef __APPLE__ diff --git a/tests/crypto/ecc_test.cpp b/tests/crypto/ecc_test.cpp index 94028ae70..79ac1e13f 100644 --- a/tests/crypto/ecc_test.cpp +++ b/tests/crypto/ecc_test.cpp @@ -23,7 +23,7 @@ static void interop_do(const char * const data, size_t len) { } static void interop_do(const fc::ecc::public_key_data &data) { - interop_do((char*) data.begin(), data.size()); + interop_do((char*) data.data(), data.size()); } static void interop_do(const fc::ecc::private_key_secret &data) { @@ -31,7 +31,7 @@ static void interop_do(const fc::ecc::private_key_secret &data) { } static void interop_do(const fc::ecc::public_key_point_data &data) { - interop_do((char*) data.begin(), data.size()); + interop_do((char*) data.data(), data.size()); } static void interop_do(const std::string &data) { @@ -44,11 +44,11 @@ static void interop_do(const fc::sha512 &data) { static void interop_do(fc::ecc::compact_signature &data) { if (write_mode) { - interop_data.write((char*) data.begin(), data.size()); + interop_data.write((char*) data.data(), data.size()); return; } - interop_data.read((char*) data.begin(), data.size()); + interop_data.read((char*) data.data(), data.size()); } static void interop_file(const char * const name) { diff --git a/tests/hmac_test.cpp b/tests/hmac_test.cpp index 82079bebd..fdd1e4cf2 100644 --- a/tests/hmac_test.cpp +++ b/tests/hmac_test.cpp @@ -79,13 +79,13 @@ static void run_test( const std::string& key, const std::string& data, const std { std::array key_arr; - BOOST_CHECK_EQUAL( fc::from_hex( key, key_arr.begin(), key_arr.size() ), N ); + BOOST_CHECK_EQUAL( fc::from_hex( key, key_arr.data(), key_arr.size() ), N ); std::array data_arr; - BOOST_CHECK_EQUAL( fc::from_hex( data, data_arr.begin(), data_arr.size() ), M ); + BOOST_CHECK_EQUAL( fc::from_hex( data, data_arr.data(), data_arr.size() ), M ); - BOOST_CHECK_EQUAL( mac_224.digest( key_arr.begin(), N, data_arr.begin(), M ).str(), expect_224 ); - BOOST_CHECK_EQUAL( mac_256.digest( key_arr.begin(), N, data_arr.begin(), M ).str(), expect_256 ); - BOOST_CHECK_EQUAL( mac_512.digest( key_arr.begin(), N, data_arr.begin(), M ).str(), expect_512 ); + BOOST_CHECK_EQUAL( mac_224.digest( key_arr.data(), N, data_arr.data(), M ).str(), expect_224 ); + BOOST_CHECK_EQUAL( mac_256.digest( key_arr.data(), N, data_arr.data(), M ).str(), expect_256 ); + BOOST_CHECK_EQUAL( mac_512.digest( key_arr.data(), N, data_arr.data(), M ).str(), expect_512 ); } BOOST_AUTO_TEST_CASE(hmac_test_1)