This commit is contained in:
Daniel Larimer 2014-06-26 20:10:37 -04:00
commit 8670a4722f
5 changed files with 61 additions and 25 deletions

View file

@ -37,12 +37,12 @@ namespace fc {
fc::fwd<impl,96> 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<char> aes_encrypt( const fc::sha512& key, const std::vector<char>& plain_text );
std::vector<char> aes_decrypt( const fc::sha512& key, const std::vector<char>& cipher_text );

View file

@ -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<int32_t>()(a.value);
}
};
template<>
struct hash<fc::unsigned_int>
{
public:
size_t operator()(const fc::signed_int &a) const
{
return std::hash<uint32_t>()(a.value);
}
};
}

View file

@ -8,6 +8,8 @@ namespace fc {
#if !defined(BOOST_NO_TEMPLATE_ALIASES)
template<typename T>
using signal = boost::signals2::signal<T>;
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)

View file

@ -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<char> aes_encrypt( const fc::sha512& key, const std::vector<char>& p
{
std::vector<char> 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;

View file

@ -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<char, 37> 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);