X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fecies.cpp;h=dec773f9cecf2d62f65d647d9e0c76b5b2a5fd2c;hb=cecf7a56ed5a5efd939b21c760c69da616306005;hp=f2a86ddd5f5e2bf4d8ecc07391bb8233c8aeea84;hpb=6db849791e675fa14d1222f86011ec6c08c84183;p=novacoin.git diff --git a/src/ecies.cpp b/src/ecies.cpp index f2a86dd..dec773f 100644 --- a/src/ecies.cpp +++ b/src/ecies.cpp @@ -272,16 +272,16 @@ static int store_mac_tag(const ies_ctx_t *ctx, const unsigned char *envelope_key cryptogram_t * ecies_encrypt(const ies_ctx_t *ctx, const unsigned char *data, size_t length, char *error) { - const size_t block_length = EVP_CIPHER_block_size(ctx->cipher); - const size_t mac_length = EVP_MD_size(ctx->md); - cryptogram_t *cryptogram = NULL; - unsigned char *envelope_key = NULL; - if (!ctx || !data || !length) { SET_ERROR("Invalid arguments"); return NULL; } + const size_t block_length = EVP_CIPHER_block_size(ctx->cipher); + const size_t mac_length = EVP_MD_size(ctx->md); + cryptogram_t *cryptogram = NULL; + unsigned char *envelope_key = NULL; + if (block_length == 0 || block_length > EVP_MAX_BLOCK_LENGTH) { SET_ERROR("Derived block size is incorrect"); return NULL; @@ -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_ripemd160(); + ctx->kdf_md = EVP_ripemd160(); + 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; + } }