1
0
mirror of https://github.com/SoftEtherVPN/SoftEtherVPN.git synced 2025-09-23 03:39:22 +03:00

Revamp digest functions

- Hash() has been removed because it was ambiguous, Md5() and Sha0() are proper replacements.
- HMacMd5() and HMacSha1() now share a common implementation handled by the new Internal_HMac() function.
- NewMd() and MdProcess() now support plain hashing (without the key).
- NewMd(), SetMdKey() and MdProcess() now check the OpenSSL functions' return value and in case of failure a debug message is printed along with the error string, if available.
- SetMdKey()'s return value has been changed from void to bool, so that it's possible to know whether the function succeeded or not.
- MdProcess()' return value has been changed from void to UINT (unsigned int) and the function now returns the number of bytes written by HMAC_Final() or EVP_DigestFinal_ex().
This commit is contained in:
Davide Beatrici
2018-09-22 06:35:30 +02:00
parent 69b35f875a
commit 3f5f716357
41 changed files with 329 additions and 371 deletions

View File

@ -1205,7 +1205,7 @@ void GenerateUnicodeCacheFileName(wchar_t *name, UINT size, wchar_t *strfilename
UniStrCat(hashtemp, sizeof(hashtemp), exe);
UniStrLower(hashtemp);
Hash(hash, hashtemp, UniStrLen(hashtemp) * sizeof(wchar_t), true);
Sha0(hash, hashtemp, UniStrLen(hashtemp) * sizeof(wchar_t));
BinToStrW(hashstr, sizeof(hashstr), hash, 4);
UniFormat(tmp, sizeof(tmp), UNICODE_CACHE_FILE, hashstr);
UniStrLower(tmp);
@ -1266,7 +1266,7 @@ void SaveUnicodeCache(wchar_t *strfilename, UINT strfilesize, UCHAR *hash)
WriteBuf(b, t->unistr, UniStrLen(t->unistr) * sizeof(wchar_t));
}
Hash(binhash, b->Buf, b->Size, false);
Md5(binhash, b->Buf, b->Size);
WriteBuf(b, binhash, MD5_SIZE);
GenerateUnicodeCacheFileName(name, sizeof(name), strfilename, strfilesize, hash);
@ -1316,7 +1316,7 @@ bool LoadUnicodeCache(wchar_t *strfilename, UINT strfilesize, UCHAR *hash)
SeekBuf(b, 0, 0);
FileClose(io);
Hash(binhash, b->Buf, b->Size >= MD5_SIZE ? (b->Size - MD5_SIZE) : 0, false);
Md5(binhash, b->Buf, b->Size >= MD5_SIZE ? (b->Size - MD5_SIZE) : 0);
Copy(binhash_2, ((UCHAR *)b->Buf) + (b->Size >= MD5_SIZE ? (b->Size - MD5_SIZE) : 0), MD5_SIZE);
if (Cmp(binhash, binhash_2, MD5_SIZE) != 0)
{
@ -1419,7 +1419,7 @@ bool LoadTableMain(wchar_t *filename)
return false;
}
Hash(hash, b->Buf, b->Size, false);
Md5(hash, b->Buf, b->Size);
if (LoadUnicodeCache(filename, b->Size, hash) == false)
{