1
0
mirror of https://github.com/SoftEtherVPN/SoftEtherVPN.git synced 2025-07-17 05:04:59 +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

@ -2965,13 +2965,7 @@ void IkeHMac(IKE_HASH *h, void *dst, void *key, UINT key_size, void *data, UINT
{
MD *md = NULL;
// Validate arguments
if (h == NULL || dst == NULL || (key == NULL && key_size != 0) || (data == NULL && data_size != 0))
{
return;
}
switch(h->HashId)
switch (h->HashId)
{
case IKE_HASH_MD5_ID:
md = NewMd("MD5");
@ -2992,12 +2986,22 @@ void IkeHMac(IKE_HASH *h, void *dst, void *key, UINT key_size, void *data, UINT
if (md == NULL)
{
Debug("IkeHMac(): The MD object is NULL! Either NewMd() failed or the current algorithm is not handled by the switch-case block.");
Debug("IkeHMac(): The MD object is NULL! Either NewMd() failed or the current algorithm is not handled by the switch-case block.\n");
return;
}
SetMdKey(md, key, key_size);
MdProcess(md, dst, data, data_size);
if (SetMdKey(md, key, key_size) == false)
{
Debug("IkeHMac(): SetMdKey() failed!\n");
goto cleanup;
}
if (MdProcess(md, dst, data, data_size) == 0)
{
Debug("IkeHMac(): MdProcess() returned 0!\n");
}
cleanup:
FreeMd(md);
}