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
cryptogram = ecies_encrypt(ctx, (unsigned char*)&data[0], data.size(), error);
if (cryptogram == NULL) {
- free(ctx);
+ delete ctx;
ctx = NULL;
throw key_error(std::string("Error in encryption: %s") + error);
}
unsigned char *key_data = cryptogram_key_data(cryptogram);
memcpy(&encrypted[0], key_data, encrypted.size());
cryptogram_free(cryptogram);
- free(ctx);
+ delete ctx;
}
void CKey::DecryptData(const std::vector<unsigned char>& encrypted, std::vector<unsigned char>& data)
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);
data.resize(length);
memcpy(&data[0], decrypted, length);
free(decrypted);
-}
+}
\ No newline at end of file
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)
};