From 606bc30522a19a1c4e68eccdbc43ae4393903957 Mon Sep 17 00:00:00 2001 From: "Kirill A. Korinskiy" Date: Sun, 7 Sep 2014 18:14:19 +0200 Subject: [PATCH] Compability with OpenSSL < 0.9.9 HMAC_* don't return error code before 0.9.9. See details here: https://github.com/openssl/openssl/commit/87d52468aa600e02326e13f01331e1f3b8602ed0 --- src/key.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/key.cpp b/src/key.cpp index a6e8bbf3..1f132f78 100644 --- a/src/key.cpp +++ b/src/key.cpp @@ -454,6 +454,11 @@ public: 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. +#if (OPENSSL_VERSION_NUMBER < 0x000909000) + HMAC_Init_ex(&hmac, envelope_key + key_length, key_length, ECIES_HASHER, NULL); + HMAC_Update(&hmac, reinterpret_cast(cryptex.body.data()), cryptex.body.size()); + HMAC_Final(&hmac, reinterpret_cast(&cryptex.mac[0]), &mac_length); +#else if (HMAC_Init_ex(&hmac, envelope_key + key_length, key_length, ECIES_HASHER, NULL) != 1 || HMAC_Update(&hmac, reinterpret_cast(cryptex.body.data()), cryptex.body.size()) != 1 || HMAC_Final(&hmac, reinterpret_cast(&cryptex.mac[0]), &mac_length) != 1) { @@ -463,9 +468,11 @@ public: HMAC_CTX_cleanup(&hmac); return false; } +#endif HMAC_CTX_cleanup(&hmac); return true; + } bool Decrypt(ecies_secure_t const &cryptex, std::string &vchText ) @@ -563,6 +570,11 @@ public: 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. +#if (OPENSSL_VERSION_NUMBER < 0x000909000) + HMAC_Init_ex(&hmac, envelope_key + key_length, key_length, ECIES_HASHER, NULL); + HMAC_Update(&hmac, reinterpret_cast(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 || HMAC_Update(&hmac, reinterpret_cast(cryptex.body.data()), cryptex.body.size()) != 1 || HMAC_Final(&hmac, md, &mac_length) != 1) { @@ -572,6 +584,7 @@ public: HMAC_CTX_cleanup(&hmac); return false; } +#endif HMAC_CTX_cleanup(&hmac);