Cleanups.

This commit is contained in:
JoelKatz
2012-04-12 23:22:44 -07:00
parent 498aba272f
commit d8a284f129

View File

@@ -122,6 +122,7 @@ std::vector<unsigned char> CKey::encryptECIES(CKey& otherKey, const std::vector<
ECIES_ENC_KEY_TYPE secret;
ECIES_HMAC_KEY_TYPE hmacKey;
getECIESSecret(otherKey, secret, hmacKey);
ECIES_HMAC_TYPE hmac = makeHMAC(hmacKey, plaintext);
hmacKey.zero();
@@ -169,7 +170,7 @@ std::vector<unsigned char> CKey::encryptECIES(CKey& otherKey, const std::vector<
if (EVP_EncryptFinal_ex(&ctx, &(out.front()) + len, &bytesWritten) < 0)
{
EVP_CIPHER_CTX_cleanup(&ctx);
throw std::runtime_error("");
throw std::runtime_error("encryption error");
}
len += bytesWritten;
@@ -183,7 +184,6 @@ std::vector<unsigned char> CKey::encryptECIES(CKey& otherKey, const std::vector<
std::vector<unsigned char> CKey::decryptECIES(CKey& otherKey, const std::vector<unsigned char>& ciphertext)
{
// minimum ciphertext = IV + HMAC + 1 block
if (ciphertext.size() < ((2 * ECIES_ENC_BLK_SIZE) + ECIES_HMAC_SIZE) )
throw std::runtime_error("ciphertext too short");
@@ -195,6 +195,7 @@ std::vector<unsigned char> CKey::decryptECIES(CKey& otherKey, const std::vector<
// begin decrypting
EVP_CIPHER_CTX ctx;
EVP_CIPHER_CTX_init(&ctx);
ECIES_ENC_KEY_TYPE secret;
ECIES_HMAC_KEY_TYPE hmacKey;
getECIESSecret(otherKey, secret, hmacKey);
@@ -262,7 +263,7 @@ bool checkECIES(void)
{
CKey senderPriv, recipientPriv, senderPub, recipientPub;
for(int i=0; i<30000; i++)
for(int i = 0; i < 30000; ++i)
{
if ((i % 100) == 0)
{ // generate new keys every 100 times