From ff6b8261d89a2ac071bba0ebe0e16b40dd7122a1 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 23 Dec 2018 20:11:05 +0300 Subject: in fact, we don't need mir_hmac_sha1 either --- include/m_core.h | 2 -- libs/win32/mir_core.lib | Bin 322740 -> 322524 bytes libs/win64/mir_core.lib | Bin 323850 -> 323658 bytes protocols/Gadu-Gadu/src/gg.h | 4 ++++ protocols/Gadu-Gadu/src/oauth.cpp | 3 ++- protocols/JabberG/src/jabber_omemo.cpp | 5 +---- protocols/JabberG/src/jabber_secur.cpp | 12 +++++++----- protocols/JabberG/src/stdafx.h | 6 ++++++ protocols/MSN/src/msn_auth.cpp | 12 +++++++----- protocols/MSN/src/stdafx.h | 4 ++++ protocols/Twitter/src/oauth.cpp | 3 ++- protocols/Twitter/src/stdafx.h | 4 ++++ src/mir_core/src/mir_core.def | 1 - src/mir_core/src/mir_core64.def | 1 - src/mir_core/src/sha1.cpp | 31 ------------------------------- 15 files changed, 37 insertions(+), 51 deletions(-) diff --git a/include/m_core.h b/include/m_core.h index 64cb936986..11878f8b60 100644 --- a/include/m_core.h +++ b/include/m_core.h @@ -361,8 +361,6 @@ MIR_CORE_DLL(void) mir_sha1_append(mir_sha1_ctx *ctx, const BYTE *dataIn, size_t MIR_CORE_DLL(void) mir_sha1_finish(mir_sha1_ctx *ctx, BYTE hashout[MIR_SHA1_HASH_SIZE]); MIR_CORE_DLL(void) mir_sha1_hash(BYTE *dataIn, size_t len, BYTE hashout[MIR_SHA1_HASH_SIZE]); -MIR_CORE_DLL(void) mir_hmac_sha1(BYTE hashout[MIR_SHA1_HASH_SIZE], const BYTE *key, size_t keylen, const BYTE *text, size_t textlen); - /////////////////////////////////////////////////////////////////////////////// // sha256 functions diff --git a/libs/win32/mir_core.lib b/libs/win32/mir_core.lib index bf09e5def3..9cef4dc7ff 100644 Binary files a/libs/win32/mir_core.lib and b/libs/win32/mir_core.lib differ diff --git a/libs/win64/mir_core.lib b/libs/win64/mir_core.lib index 3e0ebc2eb5..b7233c5ab4 100644 Binary files a/libs/win64/mir_core.lib and b/libs/win64/mir_core.lib differ diff --git a/protocols/Gadu-Gadu/src/gg.h b/protocols/Gadu-Gadu/src/gg.h index 67cc001e43..5ffd8c2d0a 100644 --- a/protocols/Gadu-Gadu/src/gg.h +++ b/protocols/Gadu-Gadu/src/gg.h @@ -70,6 +70,10 @@ #include #include +#include +#include +#pragma comment(lib, "libeay32.lib") + // libgadu headers #include "libgadu.h" #include "dynstuff.h" diff --git a/protocols/Gadu-Gadu/src/oauth.cpp b/protocols/Gadu-Gadu/src/oauth.cpp index 400e7a5ed8..c43b111dba 100644 --- a/protocols/Gadu-Gadu/src/oauth.cpp +++ b/protocols/Gadu-Gadu/src/oauth.cpp @@ -186,7 +186,8 @@ int oauth_sign_request(LIST ¶ms, const char *httpmethod, con mir_strcat(key, tsenc); BYTE digest[MIR_SHA1_HASH_SIZE]; - mir_hmac_sha1(digest, (BYTE*)(char*)key, mir_strlen(key), (BYTE*)(char*)text, mir_strlen(text)); + unsigned len = sizeof(digest); + HMAC(EVP_sha1(), key, (int)mir_strlen(key), (BYTE*)(char*)text, (int)mir_strlen(text), digest, &len); sign = mir_base64_encode(digest, MIR_SHA1_HASH_SIZE); } else { // PLAINTEXT diff --git a/protocols/JabberG/src/jabber_omemo.cpp b/protocols/JabberG/src/jabber_omemo.cpp index 186cd5c2e9..772560af2f 100755 --- a/protocols/JabberG/src/jabber_omemo.cpp +++ b/protocols/JabberG/src/jabber_omemo.cpp @@ -28,10 +28,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" #include "jabber_omemo.h" -#include -#include -#include -#include + #include #include #include diff --git a/protocols/JabberG/src/jabber_secur.cpp b/protocols/JabberG/src/jabber_secur.cpp index bb0a51e778..28166d3348 100644 --- a/protocols/JabberG/src/jabber_secur.cpp +++ b/protocols/JabberG/src/jabber_secur.cpp @@ -230,7 +230,8 @@ void TScramAuth::Hi(BYTE* res, char* passw, size_t passwLen, char* salt, size_t memset(res, 0, MIR_SHA1_HASH_SIZE); for (int i = 0; i < ind; i++) { - mir_hmac_sha1(u, (BYTE*)passw, passwLen, u, bufLen); + unsigned int len = MIR_SHA1_HASH_SIZE; + HMAC(EVP_sha1(), (BYTE*)passw, passwLen, u, bufLen, u, &len); bufLen = MIR_SHA1_HASH_SIZE; for (unsigned j = 0; j < MIR_SHA1_HASH_SIZE; j++) @@ -268,7 +269,8 @@ char* TScramAuth::getChallenge(const wchar_t *challenge) Hi(saltedPassw, passw, passwLen, salt, saltLen, ind); BYTE clientKey[MIR_SHA1_HASH_SIZE]; - mir_hmac_sha1(clientKey, saltedPassw, sizeof(saltedPassw), (BYTE*)"Client Key", 10); + unsigned int len = sizeof(clientKey); + HMAC(EVP_sha1(), saltedPassw, sizeof(saltedPassw), (BYTE*)"Client Key", 10, clientKey, &len); BYTE storedKey[MIR_SHA1_HASH_SIZE]; @@ -281,7 +283,7 @@ char* TScramAuth::getChallenge(const wchar_t *challenge) int authmsgLen = mir_snprintf(authmsg, "%s,%s,c=biws,r=%s", msg1, chl, snonce); BYTE clientSig[MIR_SHA1_HASH_SIZE]; - mir_hmac_sha1(clientSig, storedKey, sizeof(storedKey), (BYTE*)authmsg, authmsgLen); + HMAC(EVP_sha1(), storedKey, sizeof(storedKey), (BYTE*)authmsg, authmsgLen, clientSig, &len); BYTE clientProof[MIR_SHA1_HASH_SIZE]; for (unsigned j = 0; j < sizeof(clientKey); j++) @@ -289,10 +291,10 @@ char* TScramAuth::getChallenge(const wchar_t *challenge) /* Calculate the server signature */ BYTE serverKey[MIR_SHA1_HASH_SIZE]; - mir_hmac_sha1(serverKey, saltedPassw, sizeof(saltedPassw), (BYTE*)"Server Key", 10); + HMAC(EVP_sha1(), saltedPassw, sizeof(saltedPassw), (BYTE*)"Server Key", 10, serverKey, &len); BYTE srvSig[MIR_SHA1_HASH_SIZE]; - mir_hmac_sha1(srvSig, serverKey, sizeof(serverKey), (BYTE*)authmsg, authmsgLen); + HMAC(EVP_sha1(), serverKey, sizeof(serverKey), (BYTE*)authmsg, authmsgLen, srvSig, &len); serverSignature = mir_base64_encode(srvSig, sizeof(srvSig)); char buf[4096]; diff --git a/protocols/JabberG/src/stdafx.h b/protocols/JabberG/src/stdafx.h index bd420ce718..f4431b2b28 100755 --- a/protocols/JabberG/src/stdafx.h +++ b/protocols/JabberG/src/stdafx.h @@ -97,6 +97,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include +#include +#include +#include +#include +#pragma comment(lib, "libeay32.lib") + #include "../../libs/zlib/src/zlib.h" #include "resource.h" diff --git a/protocols/MSN/src/msn_auth.cpp b/protocols/MSN/src/msn_auth.cpp index e8c1fa4602..e478dc6e72 100644 --- a/protocols/MSN/src/msn_auth.cpp +++ b/protocols/MSN/src/msn_auth.cpp @@ -524,16 +524,17 @@ static void derive_key(BYTE* der, unsigned char* key, size_t keylen, unsigned ch const size_t buflen = MIR_SHA1_HASH_SIZE + datalen; BYTE* buf = (BYTE*)alloca(buflen); - mir_hmac_sha1(hash1, key, keylen, data, datalen); - mir_hmac_sha1(hash3, key, keylen, hash1, MIR_SHA1_HASH_SIZE); + unsigned int len = sizeof(hash1); + HMAC(EVP_sha1(), key, keylen, data, datalen, hash1, &len); + HMAC(EVP_sha1(), key, keylen, hash1, MIR_SHA1_HASH_SIZE, hash3, &len); memcpy(buf, hash1, MIR_SHA1_HASH_SIZE); memcpy(buf + MIR_SHA1_HASH_SIZE, data, datalen); - mir_hmac_sha1(hash2, key, keylen, buf, buflen); + HMAC(EVP_sha1(), key, keylen, buf, buflen, hash2, &len); memcpy(buf, hash3, MIR_SHA1_HASH_SIZE); memcpy(buf + MIR_SHA1_HASH_SIZE, data, datalen); - mir_hmac_sha1(hash4, key, keylen, buf, buflen); + HMAC(EVP_sha1(), key, keylen, buf, buflen, hash4, &len); memcpy(der, hash2, MIR_SHA1_HASH_SIZE); memcpy(der + MIR_SHA1_HASH_SIZE, hash4, 4); @@ -564,7 +565,8 @@ CMStringA CMsnProto::HotmailLogin(const char* url) result.Append(ptrA(mir_urlEncode(noncenc))); BYTE hash[MIR_SHA1_HASH_SIZE]; - mir_hmac_sha1(hash, key2, sizeof(key2), (BYTE*)result.GetString(), result.GetLength()); + unsigned int len = sizeof(hash); + HMAC(EVP_sha1(), key2, sizeof(key2), (BYTE*)result.GetString(), result.GetLength(), hash, &len); ptrA szHash(mir_base64_encode(hash, sizeof(hash))); result.AppendFormat("&hash=%s", ptrA(mir_urlEncode(szHash))); return result; diff --git a/protocols/MSN/src/stdafx.h b/protocols/MSN/src/stdafx.h index a96e8a8efa..ef2024f7e2 100644 --- a/protocols/MSN/src/stdafx.h +++ b/protocols/MSN/src/stdafx.h @@ -70,6 +70,10 @@ along with this program. If not, see . #include "ezxml.h" +#include +#include +#pragma comment(lib, "libeay32.lib") + #include "resource.h" ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/protocols/Twitter/src/oauth.cpp b/protocols/Twitter/src/oauth.cpp index 1105b6e650..b4b00cb8fa 100644 --- a/protocols/Twitter/src/oauth.cpp +++ b/protocols/Twitter/src/oauth.cpp @@ -337,8 +337,9 @@ wstring mir_twitter::OAuthCreateSignature(const wstring& signatureBase, const ws string keyBytes = WideToUTF8(key); BYTE digest[MIR_SHA1_HASH_SIZE]; + unsigned int len = sizeof(digest); string data = WideToUTF8(signatureBase); - mir_hmac_sha1(digest, (PBYTE)keyBytes.c_str(), keyBytes.size(), (PBYTE)data.c_str(), data.size()); + HMAC(EVP_sha1(), keyBytes.c_str(), keyBytes.size(), (PBYTE)data.c_str(), data.size(), digest, &len); ptrA encoded(mir_base64_encode(digest, sizeof(digest))); return UrlEncode((wchar_t*)_A2T(encoded)); } diff --git a/protocols/Twitter/src/stdafx.h b/protocols/Twitter/src/stdafx.h index 8373154179..456c816a0f 100644 --- a/protocols/Twitter/src/stdafx.h +++ b/protocols/Twitter/src/stdafx.h @@ -64,6 +64,10 @@ typedef std::basic_string wstring; #include #pragma warning(pop) +#include +#include +#pragma comment(lib, "libeay32.lib") + #include "StringUtil.h" #define TWITTER_KEY_NICK "Nick" // we need one called Nick for the chat thingo to work diff --git a/src/mir_core/src/mir_core.def b/src/mir_core/src/mir_core.def index f2cd22e6d2..4a744c5b5f 100644 --- a/src/mir_core/src/mir_core.def +++ b/src/mir_core/src/mir_core.def @@ -164,7 +164,6 @@ mir_writeLogVA @226 mir_writeLogVW @227 bin2hex @228 bin2hexW @229 -mir_hmac_sha1 @230 mir_base64_encodebuf @231 mirstr_allocate @232 mirstr_free @233 diff --git a/src/mir_core/src/mir_core64.def b/src/mir_core/src/mir_core64.def index 4b454ab756..3f25e54f77 100644 --- a/src/mir_core/src/mir_core64.def +++ b/src/mir_core/src/mir_core64.def @@ -164,7 +164,6 @@ mir_writeLogVA @226 mir_writeLogVW @227 bin2hex @228 bin2hexW @229 -mir_hmac_sha1 @230 mir_base64_encodebuf @231 mirstr_allocate @232 mirstr_free @233 diff --git a/src/mir_core/src/sha1.cpp b/src/mir_core/src/sha1.cpp index 10f47d7867..435f6f440b 100644 --- a/src/mir_core/src/sha1.cpp +++ b/src/mir_core/src/sha1.cpp @@ -153,34 +153,3 @@ MIR_CORE_DLL(void) mir_sha1_hash(BYTE *dataIn, size_t len, BYTE hashout[20]) mir_sha1_append(&ctx, dataIn, len); mir_sha1_finish(&ctx, hashout); } - -///////////////////////////////////////////////////////////////////////////////////////// - -MIR_CORE_DLL(void) mir_hmac_sha1(BYTE hashout[MIR_SHA1_HASH_SIZE], const BYTE *key, size_t keylen, const BYTE *text, size_t textlen) -{ - mir_sha1_ctx ctx; - BYTE usedKey[MIR_SHA_BLOCKSIZE] = { 0 }; - - if (keylen > MIR_SHA_BLOCKSIZE) { - mir_sha1_init(&ctx); - mir_sha1_append(&ctx, key, (int)keylen); - mir_sha1_finish(&ctx, usedKey); - } - else memcpy(usedKey, key, keylen); - - for (size_t i = 0; i < MIR_SHA_BLOCKSIZE; i++) - usedKey[i] ^= 0x36; - - mir_sha1_init(&ctx); - mir_sha1_append(&ctx, usedKey, MIR_SHA_BLOCKSIZE); - mir_sha1_append(&ctx, text, (int)textlen); - mir_sha1_finish(&ctx, hashout); - - for (size_t i = 0; i < MIR_SHA_BLOCKSIZE; i++) - usedKey[i] ^= 0x5C ^ 0x36; - - mir_sha1_init(&ctx); - mir_sha1_append(&ctx, usedKey, MIR_SHA_BLOCKSIZE); - mir_sha1_append(&ctx, hashout, MIR_SHA1_HASH_SIZE); - mir_sha1_finish(&ctx, hashout); -} -- cgit v1.2.3