diff --git a/include/fc/crypto/aes.hpp b/include/fc/crypto/aes.hpp index 70fdc7c..f0c7616 100644 --- a/include/fc/crypto/aes.hpp +++ b/include/fc/crypto/aes.hpp @@ -37,12 +37,12 @@ namespace fc { fc::fwd my; }; - int aes_encrypt(unsigned char *plaintext, int plaintext_len, unsigned char *key, - unsigned char *iv, unsigned char *ciphertext); - int aes_decrypt(unsigned char *ciphertext, int ciphertext_len, unsigned char *key, - unsigned char *iv, unsigned char *plaintext); - int aes_cfb_decrypt(unsigned char *ciphertext, int ciphertext_len, unsigned char *key, - unsigned char *iv, unsigned char *plaintext); + unsigned aes_encrypt(unsigned char *plaintext, int plaintext_len, unsigned char *key, + unsigned char *iv, unsigned char *ciphertext); + unsigned aes_decrypt(unsigned char *ciphertext, int ciphertext_len, unsigned char *key, + unsigned char *iv, unsigned char *plaintext); + unsigned aes_cfb_decrypt(unsigned char *ciphertext, int ciphertext_len, unsigned char *key, + unsigned char *iv, unsigned char *plaintext); std::vector aes_encrypt( const fc::sha512& key, const std::vector& plain_text ); std::vector aes_decrypt( const fc::sha512& key, const std::vector& cipher_text ); diff --git a/include/fc/io/varint.hpp b/include/fc/io/varint.hpp index 3536d4e..e289f87 100644 --- a/include/fc/io/varint.hpp +++ b/include/fc/io/varint.hpp @@ -19,12 +19,21 @@ struct unsigned_int { uint32_t value; - friend bool operator==( const unsigned_int& i, const uint32_t& v ) { return v == i.value; } - friend bool operator!=( const unsigned_int& i, const uint32_t& v ) { return v != i.value; } - friend bool operator<( const unsigned_int& i, const uint32_t& v ) { return v < i.value; } - friend bool operator>=( const unsigned_int& i, const uint32_t& v ) { return v >= i.value; } - friend bool operator<( const unsigned_int& i, const unsigned_int& v ) { return v < i.value; } - friend bool operator>=( const unsigned_int& i, const unsigned_int& v ) { return v >= i.value; } + friend bool operator==( const unsigned_int& i, const uint32_t& v ) { return i.value == v; } + friend bool operator==( const uint32_t& i, const unsigned_int& v ) { return i == v.value; } + friend bool operator==( const unsigned_int& i, const unsigned_int& v ) { return i.value == v.value; } + + friend bool operator!=( const unsigned_int& i, const uint32_t& v ) { return i.value != v; } + friend bool operator!=( const uint32_t& i, const unsigned_int& v ) { return i != v.value; } + friend bool operator!=( const unsigned_int& i, const unsigned_int& v ) { return i.value != v.value; } + + friend bool operator<( const unsigned_int& i, const uint32_t& v ) { return i.value < v; } + friend bool operator<( const uint32_t& i, const unsigned_int& v ) { return i < v.value; } + friend bool operator<( const unsigned_int& i, const unsigned_int& v ) { return i.value < v.value; } + + friend bool operator>=( const unsigned_int& i, const uint32_t& v ) { return i.value >= v; } + friend bool operator>=( const uint32_t& i, const unsigned_int& v ) { return i >= v.value; } + friend bool operator>=( const unsigned_int& i, const unsigned_int& v ) { return i.value >= v.value; } }; /** @@ -41,6 +50,22 @@ struct signed_int { signed_int& operator++(){ ++value; return *this; } int32_t value; + + friend bool operator==( const signed_int& i, const int32_t& v ) { return i.value == v; } + friend bool operator==( const int32_t& i, const signed_int& v ) { return i == v.value; } + friend bool operator==( const signed_int& i, const signed_int& v ) { return i.value == v.value; } + + friend bool operator!=( const signed_int& i, const int32_t& v ) { return i.value != v; } + friend bool operator!=( const int32_t& i, const signed_int& v ) { return i != v.value; } + friend bool operator!=( const signed_int& i, const signed_int& v ) { return i.value != v.value; } + + friend bool operator<( const signed_int& i, const int32_t& v ) { return i.value < v; } + friend bool operator<( const int32_t& i, const signed_int& v ) { return i < v.value; } + friend bool operator<( const signed_int& i, const signed_int& v ) { return i.value < v.value; } + + friend bool operator>=( const signed_int& i, const int32_t& v ) { return i.value >= v; } + friend bool operator>=( const int32_t& i, const signed_int& v ) { return i >= v.value; } + friend bool operator>=( const signed_int& i, const signed_int& v ) { return i.value >= v.value; } }; class variant; @@ -64,4 +89,13 @@ namespace std return std::hash()(a.value); } }; + template<> + struct hash + { + public: + size_t operator()(const fc::signed_int &a) const + { + return std::hash()(a.value); + } + }; } diff --git a/include/fc/signals.hpp b/include/fc/signals.hpp index 35f9a60..632f4f4 100644 --- a/include/fc/signals.hpp +++ b/include/fc/signals.hpp @@ -8,6 +8,8 @@ namespace fc { #if !defined(BOOST_NO_TEMPLATE_ALIASES) template using signal = boost::signals2::signal; + + using scoped_connection = boost::signals2::scoped_connection; #else /** Workaround for missing Template Aliases feature in the VS 2012. \warning Class defined below cannot have defined constructor (even base class has it) diff --git a/src/crypto/aes.cpp b/src/crypto/aes.cpp index 8e51519..1c2a036 100644 --- a/src/crypto/aes.cpp +++ b/src/crypto/aes.cpp @@ -157,13 +157,13 @@ uint32_t aes_decoder::final_decode( char* plaintext ) /** example method from wiki.opensslfoundation.com */ -int aes_encrypt(unsigned char *plaintext, int plaintext_len, unsigned char *key, - unsigned char *iv, unsigned char *ciphertext) +unsigned aes_encrypt(unsigned char *plaintext, int plaintext_len, unsigned char *key, + unsigned char *iv, unsigned char *ciphertext) { evp_cipher_ctx ctx( EVP_CIPHER_CTX_new() ); int len = 0; - int ciphertext_len = 0; + unsigned ciphertext_len = 0; /* Create and initialise the context */ if(!ctx) @@ -206,12 +206,12 @@ int aes_encrypt(unsigned char *plaintext, int plaintext_len, unsigned char *key, return ciphertext_len; } -int aes_decrypt(unsigned char *ciphertext, int ciphertext_len, unsigned char *key, - unsigned char *iv, unsigned char *plaintext) +unsigned aes_decrypt(unsigned char *ciphertext, int ciphertext_len, unsigned char *key, + unsigned char *iv, unsigned char *plaintext) { evp_cipher_ctx ctx( EVP_CIPHER_CTX_new() ); int len = 0; - int plaintext_len = 0; + unsigned plaintext_len = 0; /* Create and initialise the context */ if(!ctx) @@ -255,12 +255,12 @@ int aes_decrypt(unsigned char *ciphertext, int ciphertext_len, unsigned char *ke return plaintext_len; } -int aes_cfb_decrypt(unsigned char *ciphertext, int ciphertext_len, unsigned char *key, - unsigned char *iv, unsigned char *plaintext) +unsigned aes_cfb_decrypt(unsigned char *ciphertext, int ciphertext_len, unsigned char *key, + unsigned char *iv, unsigned char *plaintext) { evp_cipher_ctx ctx( EVP_CIPHER_CTX_new() ); int len = 0; - int plaintext_len = 0; + unsigned plaintext_len = 0; /* Create and initialise the context */ if(!ctx) @@ -308,8 +308,8 @@ std::vector aes_encrypt( const fc::sha512& key, const std::vector& p { std::vector cipher_text(plain_text.size()+16); auto cipher_len = aes_encrypt( (unsigned char*)plain_text.data(), plain_text.size(), - (unsigned char*)&key, ((unsigned char*)&key)+32, - (unsigned char*)cipher_text.data() ); + (unsigned char*)&key, ((unsigned char*)&key)+32, + (unsigned char*)cipher_text.data() ); FC_ASSERT( cipher_len <= cipher_text.size() ); cipher_text.resize(cipher_len); return cipher_text; diff --git a/src/crypto/elliptic.cpp b/src/crypto/elliptic.cpp index dd3c4cb..ed38ad2 100644 --- a/src/crypto/elliptic.cpp +++ b/src/crypto/elliptic.cpp @@ -265,7 +265,7 @@ namespace fc { namespace ecc { std::string public_key::to_base58() const { public_key_data key = serialize(); - uint32_t check = sha256::hash(key.data, sizeof(key))._hash[0]; + uint32_t check = (uint32_t)sha256::hash(key.data, sizeof(key))._hash[0]; assert(key.size() + sizeof(check) == 37); array data; memcpy(data.data, key.begin(), key.size()); @@ -280,7 +280,7 @@ namespace fc { namespace ecc { FC_ASSERT( s == sizeof(data) ); public_key_data key; - uint32_t check = sha256::hash(data.data, sizeof(key))._hash[0]; + uint32_t check = (uint32_t)sha256::hash(data.data, sizeof(key))._hash[0]; FC_ASSERT( memcmp( (char*)&check, data.data + sizeof(key), sizeof(check) ) == 0 ); memcpy( (char*)key.data, data.data, sizeof(key) ); return public_key(key);