From 8c95d62c9ed85424b46be277e9feac86b03e0bdf Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Thu, 5 Sep 2013 19:02:10 -0400 Subject: [PATCH] two phase init of aes encoder/decoder --- include/fc/crypto/aes.hpp | 6 ++++-- src/crypto/aes.cpp | 12 +++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/include/fc/crypto/aes.hpp b/include/fc/crypto/aes.hpp index 00e4128..d551667 100644 --- a/include/fc/crypto/aes.hpp +++ b/include/fc/crypto/aes.hpp @@ -11,9 +11,10 @@ namespace fc { class aes_encoder { public: - aes_encoder( const fc::sha256& key, const fc::uint128& init_value ); + aes_encoder(); ~aes_encoder(); + void init( const fc::sha256& key, const fc::uint128& init_value ); uint32_t encode( const char* plaintxt, uint32_t len, const char* ciphertxt ); uint32_t final_encode( const char* ciphertxt ); @@ -24,9 +25,10 @@ namespace fc { class aes_decoder { public: - aes_decoder( const fc::sha256& key, const fc::uint128& init_value ); + aes_decoder(); ~aes_decoder(); + void init( const fc::sha256& key, const fc::uint128& init_value ); uint32_t encode( const char* plaintxt, uint32_t len, const char* ciphertxt ); uint32_t final_encode( const char* ciphertxt ); diff --git a/src/crypto/aes.cpp b/src/crypto/aes.cpp index 4e3e05a..b5a82aa 100644 --- a/src/crypto/aes.cpp +++ b/src/crypto/aes.cpp @@ -15,7 +15,11 @@ struct aes_encoder::impl evp_cipher_ctx ctx; }; -aes_encoder::aes_encoder( const fc::sha256& key, const fc::uint128& init_value ) +aes_encoder::aes_encoder(){} +aes_encoder::~aes_encoder() +{ +} +void aes_encoder::init( const fc::sha256& key, const fc::uint128& init_value ) { my->ctx.obj = EVP_CIPHER_CTX_new(); /* Create and initialise the context */ @@ -36,9 +40,6 @@ aes_encoder::aes_encoder( const fc::sha256& key, const fc::uint128& init_value ) ("s", ERR_error_string( ERR_get_error(), nullptr) ) ); } } -aes_encoder::~aes_encoder() -{ -} uint32_t aes_encoder::encode( const char* plaintxt, uint32_t plaintext_len, const char* ciphertxt ) { @@ -73,7 +74,8 @@ struct aes_decoder::impl evp_cipher_ctx ctx; }; -aes_decoder::aes_decoder( const fc::sha256& key, const fc::uint128& init_value ) +aes_decoder::aes_decoder(){} +void aes_decoder::init( const fc::sha256& key, const fc::uint128& init_value ) { my->ctx.obj = EVP_CIPHER_CTX_new(); /* Create and initialise the context */