From: CryptoManiac Date: Sat, 12 Mar 2016 22:43:37 +0000 (+0300) Subject: Merge pull request #288 from svost/patch X-Git-Tag: nvc-v0.5.6~10 X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=commitdiff_plain;h=fd7b67828ddfb69d1c42dd969b807b74790b7260;hp=ac3971a70f7f73b2c30f266f97a9abf91a412fa5 Merge pull request #288 from svost/patch Patch --- diff --git a/src/ecies.cpp b/src/ecies.cpp index 39fe2d7..3f8eaf7 100644 --- a/src/ecies.cpp +++ b/src/ecies.cpp @@ -556,12 +556,18 @@ unsigned char * ecies_decrypt(const ies_ctx_t *ctx, const cryptogram_t *cryptogr ies_ctx_t *create_context(EC_KEY *user_key) { - ies_ctx_t* ctx = (ies_ctx_t*) malloc(sizeof(ies_ctx_t)); - ctx->cipher = EVP_aes_128_cbc(); - ctx->md = EVP_sha1(); - ctx->kdf_md = EVP_sha1(); - ctx->stored_key_length = 33; - ctx->user_key = user_key; - - return ctx; -} + try { + ies_ctx_t* ctx = new ies_ctx_t; + ctx->cipher = EVP_aes_128_cbc(); + ctx->md = EVP_sha1(); + ctx->kdf_md = EVP_sha1(); + ctx->stored_key_length = 33; + ctx->user_key = user_key; + return ctx; + } + catch (const std::bad_alloc& e) { + printf("Error: %s in %s:%d\n", e.what(), __FILE__, __LINE__); +// TODO: add checking to NULL where necessary + return NULL; + } +} \ No newline at end of file diff --git a/src/key.cpp b/src/key.cpp index 49868b8..2232324 100644 --- a/src/key.cpp +++ b/src/key.cpp @@ -1202,7 +1202,7 @@ void CKey::EncryptData(const std::vector& data, std::vector& data, std::vector& encrypted, std::vector& data) @@ -1234,7 +1234,7 @@ void CKey::DecryptData(const std::vector& encrypted, std::vector< decrypted = ecies_decrypt(ctx, cryptogram, &length, error); cryptogram_free(cryptogram); - free(ctx); + delete ctx; if (decrypted == NULL) { throw key_error(std::string("Error in decryption: %s") + error); @@ -1243,4 +1243,4 @@ void CKey::DecryptData(const std::vector& encrypted, std::vector< data.resize(length); memcpy(&data[0], decrypted, length); free(decrypted); -} +} \ No newline at end of file diff --git a/src/serialize.h b/src/serialize.h index 0e2fa9d..8305dd0 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -56,9 +56,9 @@ enum SER_DISK = (1 << 1), SER_GETHASH = (1 << 2), - // modifiers - SER_SKIPSIG = (1 << 16), - SER_BLOCKHEADERONLY = (1 << 17) + // modifiers + SER_SKIPSIG = (1 << 16), + SER_BLOCKHEADERONLY = (1 << 17) };