Browse Source

Compability with OpenSSL < 0.9.9

HMAC_* don't return error code before 0.9.9. See details here:
87d52468aa
miguelfreitas
Kirill A. Korinskiy 10 years ago
parent
commit
606bc30522
  1. 13
      src/key.cpp

13
src/key.cpp

@ -454,6 +454,11 @@ public:
unsigned int mac_length = cryptex.mac.size(); unsigned int mac_length = cryptex.mac.size();
// At the moment we are generating the hash using encrypted data. At some point we may want to validate the original text instead. // At the moment we are generating the hash using encrypted data. At some point we may want to validate the original text instead.
#if (OPENSSL_VERSION_NUMBER < 0x000909000)
HMAC_Init_ex(&hmac, envelope_key + key_length, key_length, ECIES_HASHER, NULL);
HMAC_Update(&hmac, reinterpret_cast<const unsigned char *>(cryptex.body.data()), cryptex.body.size());
HMAC_Final(&hmac, reinterpret_cast<unsigned char *>(&cryptex.mac[0]), &mac_length);
#else
if (HMAC_Init_ex(&hmac, envelope_key + key_length, key_length, ECIES_HASHER, NULL) != 1 || if (HMAC_Init_ex(&hmac, envelope_key + key_length, key_length, ECIES_HASHER, NULL) != 1 ||
HMAC_Update(&hmac, reinterpret_cast<const unsigned char *>(cryptex.body.data()), cryptex.body.size()) != 1 || HMAC_Update(&hmac, reinterpret_cast<const unsigned char *>(cryptex.body.data()), cryptex.body.size()) != 1 ||
HMAC_Final(&hmac, reinterpret_cast<unsigned char *>(&cryptex.mac[0]), &mac_length) != 1) { HMAC_Final(&hmac, reinterpret_cast<unsigned char *>(&cryptex.mac[0]), &mac_length) != 1) {
@ -463,9 +468,11 @@ public:
HMAC_CTX_cleanup(&hmac); HMAC_CTX_cleanup(&hmac);
return false; return false;
} }
#endif
HMAC_CTX_cleanup(&hmac); HMAC_CTX_cleanup(&hmac);
return true; return true;
} }
bool Decrypt(ecies_secure_t const &cryptex, std::string &vchText ) bool Decrypt(ecies_secure_t const &cryptex, std::string &vchText )
@ -563,6 +570,11 @@ public:
unsigned char md[EVP_MAX_MD_SIZE]; unsigned char md[EVP_MAX_MD_SIZE];
// At the moment we are generating the hash using encrypted data. At some point we may want to validate the original text instead. // At the moment we are generating the hash using encrypted data. At some point we may want to validate the original text instead.
#if (OPENSSL_VERSION_NUMBER < 0x000909000)
HMAC_Init_ex(&hmac, envelope_key + key_length, key_length, ECIES_HASHER, NULL);
HMAC_Update(&hmac, reinterpret_cast<const unsigned char *>(cryptex.body.data()), cryptex.body.size());
HMAC_Final(&hmac, md, &mac_length);
#else
if (HMAC_Init_ex(&hmac, envelope_key + key_length, key_length, ECIES_HASHER, NULL) != 1 || if (HMAC_Init_ex(&hmac, envelope_key + key_length, key_length, ECIES_HASHER, NULL) != 1 ||
HMAC_Update(&hmac, reinterpret_cast<const unsigned char *>(cryptex.body.data()), cryptex.body.size()) != 1 || HMAC_Update(&hmac, reinterpret_cast<const unsigned char *>(cryptex.body.data()), cryptex.body.size()) != 1 ||
HMAC_Final(&hmac, md, &mac_length) != 1) { HMAC_Final(&hmac, md, &mac_length) != 1) {
@ -572,6 +584,7 @@ public:
HMAC_CTX_cleanup(&hmac); HMAC_CTX_cleanup(&hmac);
return false; return false;
} }
#endif
HMAC_CTX_cleanup(&hmac); HMAC_CTX_cleanup(&hmac);

Loading…
Cancel
Save