mirror of
https://github.com/SoftEtherVPN/SoftEtherVPN.git
synced 2025-07-06 07:44:57 +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:
@ -466,7 +466,7 @@ bool CfgSaveExW3(CFG_RW *rw, FOLDER *f, wchar_t *name, UINT *written_size, bool
|
||||
return false;
|
||||
}
|
||||
// Hash the contents
|
||||
Hash(hash, b->Buf, b->Size, true);
|
||||
Sha0(hash, b->Buf, b->Size);
|
||||
|
||||
// Compare the contents to be written with the content which was written last
|
||||
if (rw != NULL)
|
||||
@ -661,7 +661,7 @@ FOLDER *CfgReadW(wchar_t *name)
|
||||
// Check the hash
|
||||
ReadBuf(b, hash1, sizeof(hash1));
|
||||
|
||||
Hash(hash2, ((UCHAR *)b->Buf) + 8 + SHA1_SIZE, b->Size - 8 - SHA1_SIZE, true);
|
||||
Sha0(hash2, ((UCHAR *)b->Buf) + 8 + SHA1_SIZE, b->Size - 8 - SHA1_SIZE);
|
||||
|
||||
if (Cmp(hash1, hash2, SHA1_SIZE) != 0)
|
||||
{
|
||||
@ -1105,7 +1105,7 @@ BUF *CfgFolderToBufBin(FOLDER *f)
|
||||
CfgOutputFolderBin(b, f);
|
||||
|
||||
// Hash
|
||||
Hash(((UCHAR *)b->Buf) + 8, ((UCHAR *)b->Buf) + 8 + SHA1_SIZE, b->Size - 8 - SHA1_SIZE, true);
|
||||
Sha0(((UCHAR *)b->Buf) + 8, ((UCHAR *)b->Buf) + 8 + SHA1_SIZE, b->Size - 8 - SHA1_SIZE);
|
||||
|
||||
return b;
|
||||
}
|
||||
|
@ -170,7 +170,8 @@ LOCK **ssl_lock_obj = NULL;
|
||||
UINT ssl_lock_num;
|
||||
static bool openssl_inited = false;
|
||||
|
||||
static unsigned char *Internal_SHA0(const unsigned char *d, size_t n, unsigned char *md);
|
||||
static UINT Internal_HMac(const EVP_MD *md, void *dest, void *key, UINT key_size, const void *src, const UINT src_size);
|
||||
static void Internal_Sha0(unsigned char *dest, const unsigned char *src, const UINT size);
|
||||
|
||||
// For the callback function
|
||||
typedef struct CB_PARAM
|
||||
@ -268,185 +269,86 @@ void Enc_tls1_PRF(unsigned char *label, int label_len, const unsigned char *sec,
|
||||
}
|
||||
|
||||
// Calculation of HMAC (MD5)
|
||||
void HMacMd5(void *dst, void *key, UINT key_size, void *data, UINT data_size)
|
||||
UINT HMacMd5(void *dst, void *key, UINT key_size, void *src, UINT src_size)
|
||||
{
|
||||
UCHAR k[HMAC_BLOCK_SIZE];
|
||||
UCHAR hash1[MD5_SIZE];
|
||||
UCHAR data2[HMAC_BLOCK_SIZE];
|
||||
MD5_CTX md5_ctx1;
|
||||
UCHAR pad1[HMAC_BLOCK_SIZE];
|
||||
UINT i;
|
||||
// Validate arguments
|
||||
if (dst == NULL || (key == NULL && key_size != 0) || (data == NULL && data_size != 0))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Creating a K
|
||||
if (key_size <= HMAC_BLOCK_SIZE)
|
||||
{
|
||||
for (i = 0;i < key_size;i++)
|
||||
{
|
||||
pad1[i] = ((UCHAR *)key)[i] ^ 0x36;
|
||||
}
|
||||
for (i = key_size;i < HMAC_BLOCK_SIZE;i++)
|
||||
{
|
||||
pad1[i] = 0 ^ 0x36;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Zero(k, sizeof(k));
|
||||
Hash(k, key, key_size, false);
|
||||
|
||||
for (i = 0;i < HMAC_BLOCK_SIZE;i++)
|
||||
{
|
||||
pad1[i] = k[i] ^ 0x36;
|
||||
}
|
||||
}
|
||||
|
||||
MD5_Init(&md5_ctx1);
|
||||
MD5_Update(&md5_ctx1, pad1, sizeof(pad1));
|
||||
MD5_Update(&md5_ctx1, data, data_size);
|
||||
MD5_Final(hash1, &md5_ctx1);
|
||||
|
||||
// Generation of data 2
|
||||
if (key_size <= HMAC_BLOCK_SIZE)
|
||||
{
|
||||
for (i = 0;i < key_size;i++)
|
||||
{
|
||||
data2[i] = ((UCHAR *)key)[i] ^ 0x5c;
|
||||
}
|
||||
for (i = key_size;i < HMAC_BLOCK_SIZE;i++)
|
||||
{
|
||||
data2[i] = 0 ^ 0x5c;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0;i < HMAC_BLOCK_SIZE;i++)
|
||||
{
|
||||
data2[i] = k[i] ^ 0x5c;
|
||||
}
|
||||
}
|
||||
|
||||
MD5_Init(&md5_ctx1);
|
||||
MD5_Update(&md5_ctx1, data2, HMAC_BLOCK_SIZE);
|
||||
MD5_Update(&md5_ctx1, hash1, MD5_SIZE);
|
||||
MD5_Final(dst, &md5_ctx1);
|
||||
return Internal_HMac(EVP_md5(), dst, key, key_size, src, src_size);
|
||||
}
|
||||
|
||||
// Calculation of HMAC (SHA-1)
|
||||
void HMacSha1(void *dst, void *key, UINT key_size, void *data, UINT data_size)
|
||||
UINT HMacSha1(void *dst, void *key, UINT key_size, void *src, UINT src_size)
|
||||
{
|
||||
UCHAR k[HMAC_BLOCK_SIZE];
|
||||
UCHAR hash1[SHA1_SIZE];
|
||||
UCHAR data2[HMAC_BLOCK_SIZE];
|
||||
SHA_CTX sha_ctx1;
|
||||
UCHAR pad1[HMAC_BLOCK_SIZE];
|
||||
UINT i;
|
||||
// Validate arguments
|
||||
if (dst == NULL || (key == NULL && key_size != 0) || (data == NULL && data_size != 0))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Creating a K
|
||||
if (key_size <= HMAC_BLOCK_SIZE)
|
||||
{
|
||||
for (i = 0;i < key_size;i++)
|
||||
{
|
||||
pad1[i] = ((UCHAR *)key)[i] ^ 0x36;
|
||||
}
|
||||
for (i = key_size;i < HMAC_BLOCK_SIZE;i++)
|
||||
{
|
||||
pad1[i] = 0 ^ 0x36;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Zero(k, sizeof(k));
|
||||
HashSha1(k, key, key_size);
|
||||
|
||||
for (i = 0;i < HMAC_BLOCK_SIZE;i++)
|
||||
{
|
||||
pad1[i] = k[i] ^ 0x36;
|
||||
}
|
||||
}
|
||||
|
||||
SHA1_Init(&sha_ctx1);
|
||||
SHA1_Update(&sha_ctx1, pad1, sizeof(pad1));
|
||||
SHA1_Update(&sha_ctx1, data, data_size);
|
||||
SHA1_Final(hash1, &sha_ctx1);
|
||||
|
||||
// Generation of data 2
|
||||
if (key_size <= HMAC_BLOCK_SIZE)
|
||||
{
|
||||
for (i = 0;i < key_size;i++)
|
||||
{
|
||||
data2[i] = ((UCHAR *)key)[i] ^ 0x5c;
|
||||
}
|
||||
for (i = key_size;i < HMAC_BLOCK_SIZE;i++)
|
||||
{
|
||||
data2[i] = 0 ^ 0x5c;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0;i < HMAC_BLOCK_SIZE;i++)
|
||||
{
|
||||
data2[i] = k[i] ^ 0x5c;
|
||||
}
|
||||
}
|
||||
|
||||
SHA1_Init(&sha_ctx1);
|
||||
SHA1_Update(&sha_ctx1, data2, HMAC_BLOCK_SIZE);
|
||||
SHA1_Update(&sha_ctx1, hash1, SHA1_SIZE);
|
||||
SHA1_Final(dst, &sha_ctx1);
|
||||
return Internal_HMac(EVP_sha1(), dst, key, key_size, src, src_size);
|
||||
}
|
||||
|
||||
// Calculate the HMAC
|
||||
void MdProcess(MD *md, void *dest, void *src, UINT size)
|
||||
// Calculate the hash/HMAC
|
||||
UINT MdProcess(MD *md, void *dest, void *src, UINT size)
|
||||
{
|
||||
int r = 0;
|
||||
|
||||
if (md != NULL && md->isNullMd)
|
||||
{
|
||||
if (dest != src)
|
||||
{
|
||||
Copy(dest, src, size);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
UINT len = 0;
|
||||
|
||||
// Validate arguments
|
||||
if (md == NULL || dest == NULL || (src != NULL && size == 0))
|
||||
if (md == NULL || md->IsNullMd || dest == NULL || (src == NULL && size != 0))
|
||||
{
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
HMAC_Init_ex(md->Ctx, NULL, 0, NULL, NULL);
|
||||
HMAC_Update(md->Ctx, src, size);
|
||||
HMAC_Final(md->Ctx, dest, &r);
|
||||
if (md->IsHMac)
|
||||
{
|
||||
if (HMAC_Update(md->Ctx, src, size) == false)
|
||||
{
|
||||
Debug("MdProcess(): HMAC_Update() failed with error: %s\n", OpenSSL_Error());
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (HMAC_Final(md->Ctx, dest, &len) == false)
|
||||
{
|
||||
Debug("MdProcess(): HMAC_Final() failed with error: %s\n", OpenSSL_Error());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (EVP_DigestUpdate(md->Ctx, src, size) == false)
|
||||
{
|
||||
Debug("MdProcess(): EVP_DigestUpdate() failed with error: %s\n", OpenSSL_Error());
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (EVP_DigestFinal_ex(md->Ctx, dest, &len) == false)
|
||||
{
|
||||
Debug("MdProcess(): EVP_DigestFinal_ex() failed with error: %s\n", OpenSSL_Error());
|
||||
}
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
// Set the key to the message digest object
|
||||
void SetMdKey(MD *md, void *key, UINT key_size)
|
||||
bool SetMdKey(MD *md, void *key, UINT key_size)
|
||||
{
|
||||
// Validate arguments
|
||||
if (md == NULL || (key != NULL && key_size == 0))
|
||||
if (md == NULL || md->IsHMac == false || key == NULL || key_size == 0)
|
||||
{
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
HMAC_Init_ex(md->Ctx, key, key_size, (const EVP_MD *)md->Md, NULL);
|
||||
if (HMAC_Init_ex(md->Ctx, key, key_size, (const EVP_MD *)md->Md, NULL) == false)
|
||||
{
|
||||
Debug("SetMdKey(): HMAC_Init_ex() failed with error: %s\n", OpenSSL_Error());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Creating a message digest object
|
||||
MD *NewMd(char *name)
|
||||
{
|
||||
return NewMdEx(name, true);
|
||||
}
|
||||
|
||||
MD *NewMdEx(char *name, bool hmac)
|
||||
{
|
||||
MD *m;
|
||||
|
||||
// Validate arguments
|
||||
if (name == NULL)
|
||||
{
|
||||
@ -461,25 +363,43 @@ MD *NewMd(char *name)
|
||||
StrCmpi(name, "NULL") == 0 ||
|
||||
IsEmptyStr(name))
|
||||
{
|
||||
m->isNullMd = true;
|
||||
m->IsNullMd = true;
|
||||
return m;
|
||||
}
|
||||
|
||||
m->Md = (const struct evp_md_st *)EVP_get_digestbyname(name);
|
||||
if (m->Md == NULL)
|
||||
{
|
||||
Debug("NewMdEx(): Algorithm %s not found by EVP_get_digestbyname().\n", m->Name);
|
||||
FreeMd(m);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
||||
m->Ctx = HMAC_CTX_new();
|
||||
#else
|
||||
m->Ctx = ZeroMalloc(sizeof(struct hmac_ctx_st));
|
||||
HMAC_CTX_init(m->Ctx);
|
||||
#endif
|
||||
|
||||
m->Size = EVP_MD_size((const EVP_MD *)m->Md);
|
||||
m->IsHMac = hmac;
|
||||
|
||||
if (hmac)
|
||||
{
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
||||
m->Ctx = HMAC_CTX_new();
|
||||
#else
|
||||
m->Ctx = ZeroMalloc(sizeof(struct hmac_ctx_st));
|
||||
HMAC_CTX_init(m->Ctx);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
||||
m->Ctx = EVP_MD_CTX_new();
|
||||
#else
|
||||
m->Ctx = EVP_MD_CTX_create();
|
||||
#endif
|
||||
if (EVP_DigestInit_ex(m->Ctx, m->Md, NULL) == false)
|
||||
{
|
||||
Debug("NewMdEx(): EVP_DigestInit_ex() failed with error: %s\n", OpenSSL_Error());
|
||||
FreeMd(m);
|
||||
}
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
@ -495,12 +415,23 @@ void FreeMd(MD *md)
|
||||
|
||||
if (md->Ctx != NULL)
|
||||
{
|
||||
if (md->IsHMac)
|
||||
{
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
||||
HMAC_CTX_free(md->Ctx);
|
||||
HMAC_CTX_free(md->Ctx);
|
||||
#else
|
||||
HMAC_CTX_cleanup(md->Ctx);
|
||||
Free(md->Ctx);
|
||||
HMAC_CTX_cleanup(md->Ctx);
|
||||
Free(md->Ctx);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
||||
EVP_MD_CTX_free(md->Ctx);
|
||||
#else
|
||||
EVP_MD_CTX_destroy(md->Ctx);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
Free(md);
|
||||
@ -704,7 +635,7 @@ UINT HashPtrToUINT(void *p)
|
||||
return 0;
|
||||
}
|
||||
|
||||
Hash(hash_data, &p, sizeof(p), false);
|
||||
Md5(hash_data, &p, sizeof(p));
|
||||
|
||||
Copy(&ret, hash_data, sizeof(ret));
|
||||
|
||||
@ -822,6 +753,11 @@ unsigned long OpenSSL_Id(void)
|
||||
return (unsigned long)ThreadId();
|
||||
}
|
||||
|
||||
char *OpenSSL_Error()
|
||||
{
|
||||
return ERR_error_string(ERR_get_error(), NULL);
|
||||
}
|
||||
|
||||
// Get the display name of the certificate
|
||||
void GetPrintNameFromX(wchar_t *str, UINT size, X *x)
|
||||
{
|
||||
@ -2287,7 +2223,7 @@ bool HashForSign(void *dst, UINT dst_size, void *src, UINT src_size)
|
||||
Copy(buf, sign_data, sizeof(sign_data));
|
||||
|
||||
// Hash
|
||||
HashSha1(HASHED_DATA(buf), src, src_size);
|
||||
Sha1(HASHED_DATA(buf), src, src_size);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -3781,8 +3717,8 @@ void InitCryptLibrary()
|
||||
openssl_inited = true;
|
||||
}
|
||||
|
||||
// Hash function
|
||||
void Hash(void *dst, void *src, UINT size, bool sha)
|
||||
// MD4 specific hash function
|
||||
void HashMd4(void *dst, void *src, UINT size)
|
||||
{
|
||||
// Validate arguments
|
||||
if (dst == NULL || (src == NULL && size != 0))
|
||||
@ -3790,26 +3726,6 @@ void Hash(void *dst, void *src, UINT size, bool sha)
|
||||
return;
|
||||
}
|
||||
|
||||
if (sha == false)
|
||||
{
|
||||
// MD5 hash
|
||||
MD5(src, size, dst);
|
||||
}
|
||||
else
|
||||
{
|
||||
// SHA hash
|
||||
Internal_SHA0(src, size, dst);
|
||||
}
|
||||
}
|
||||
|
||||
// MD4 specific hash function
|
||||
void HashMd4(void *dst, void *src, UINT size)
|
||||
{
|
||||
// Validate arguments
|
||||
if (dst == NULL || (size != 0 && src == NULL))
|
||||
{
|
||||
return;
|
||||
}
|
||||
MD4(src, size, dst);
|
||||
}
|
||||
|
||||
@ -3824,7 +3740,7 @@ UINT HashToUINT(void *data, UINT size)
|
||||
return 0;
|
||||
}
|
||||
|
||||
HashSha1(hash, data, size);
|
||||
Sha1(hash, data, size);
|
||||
|
||||
Copy(&u, hash, sizeof(UINT));
|
||||
|
||||
@ -3836,12 +3752,7 @@ UINT HashToUINT(void *data, UINT size)
|
||||
// SHA-1 specific hash function
|
||||
void HashSha1(void *dst, void *src, UINT size)
|
||||
{
|
||||
// Validate arguments
|
||||
if (dst == NULL || (size != 0 && src == NULL))
|
||||
{
|
||||
return;
|
||||
}
|
||||
SHA1(src, size, dst);
|
||||
Sha1(dst, src, size);
|
||||
}
|
||||
|
||||
// Creating a new CRYPT object
|
||||
@ -3876,11 +3787,11 @@ void Encrypt(CRYPT *c, void *dst, void *src, UINT size)
|
||||
RC4(c->Rc4Key, size, src, dst);
|
||||
}
|
||||
|
||||
// SHA-1 hash
|
||||
// SHA hash
|
||||
void Sha(UINT sha_type, void *dst, void *src, UINT size)
|
||||
{
|
||||
// Validate arguments
|
||||
if (dst == NULL || src == NULL)
|
||||
if (dst == NULL || (src == NULL && size != 0))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -3899,29 +3810,36 @@ void Sha(UINT sha_type, void *dst, void *src, UINT size)
|
||||
SHA512(src, size, dst);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// SHA-1 hash
|
||||
void Sha1(void *dst, void *src, UINT size)
|
||||
void Sha0(void *dst, void *src, UINT size)
|
||||
{
|
||||
// Validate arguments
|
||||
if (dst == NULL || src == NULL)
|
||||
if (dst == NULL || (src == NULL && size != 0))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SHA1(src, size, dst);
|
||||
Internal_Sha0(dst, src, size);
|
||||
}
|
||||
|
||||
void Sha2_256(void *dst, void *src, UINT size) {
|
||||
void Sha1(void *dst, void *src, UINT size)
|
||||
{
|
||||
Sha(SHA1_160, dst, src, size);
|
||||
}
|
||||
|
||||
void Sha2_256(void *dst, void *src, UINT size)
|
||||
{
|
||||
Sha(SHA2_256, dst, src, size);
|
||||
}
|
||||
void Sha2_384(void *dst, void *src, UINT size) {
|
||||
|
||||
void Sha2_384(void *dst, void *src, UINT size)
|
||||
{
|
||||
Sha(SHA2_384, dst, src, size);
|
||||
}
|
||||
void Sha2_512(void *dst, void *src, UINT size) {
|
||||
|
||||
void Sha2_512(void *dst, void *src, UINT size)
|
||||
{
|
||||
Sha(SHA2_512, dst, src, size);
|
||||
}
|
||||
|
||||
@ -3929,7 +3847,7 @@ void Sha2_512(void *dst, void *src, UINT size) {
|
||||
void Md5(void *dst, void *src, UINT size)
|
||||
{
|
||||
// Validate arguments
|
||||
if (dst == NULL || src == NULL)
|
||||
if (dst == NULL || (src == NULL && size != 0))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -4468,6 +4386,50 @@ void DhFree(DH_CTX *dh)
|
||||
Free(dh);
|
||||
}
|
||||
|
||||
int GetSslClientCertIndex()
|
||||
{
|
||||
return ssl_clientcert_index;
|
||||
}
|
||||
|
||||
// Internal functions
|
||||
static UINT Internal_HMac(const EVP_MD *md, void *dest, void *key, UINT key_size, const void *src, const UINT src_size)
|
||||
{
|
||||
MD *m;
|
||||
UINT len = 0;
|
||||
|
||||
// Validate arguments
|
||||
if (md == NULL || dest == NULL || key == NULL || key_size == 0 || (src == NULL && src_size != 0))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
m = ZeroMalloc(sizeof(MD));
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
||||
m->Ctx = HMAC_CTX_new();
|
||||
#else
|
||||
m->Ctx = ZeroMalloc(sizeof(HMAC_CTX));
|
||||
HMAC_CTX_init(m->Ctx);
|
||||
#endif
|
||||
m->Md = md;
|
||||
m->IsHMac = true;
|
||||
|
||||
if (SetMdKey(m, key, key_size) == false)
|
||||
{
|
||||
Debug("Internal_HMac(): SetMdKey() failed!\n");
|
||||
goto final;
|
||||
}
|
||||
|
||||
len = MdProcess(m, dest, src, src_size);
|
||||
if (len == 0)
|
||||
{
|
||||
Debug("Internal_HMac(): MdProcess() returned 0!\n");
|
||||
}
|
||||
|
||||
final:
|
||||
FreeMd(m);
|
||||
return len;
|
||||
}
|
||||
|
||||
/////////////////////////
|
||||
// SHA0 implementation //
|
||||
/////////////////////////
|
||||
@ -4767,24 +4729,12 @@ static void ampheck_sha0_finish(const struct ampheck_sha0 *ctx, UCHAR *digest)
|
||||
UNPACK_32_BE(tmp.h[3], &digest[12]);
|
||||
UNPACK_32_BE(tmp.h[4], &digest[16]);
|
||||
}
|
||||
static unsigned char *Internal_SHA0(const unsigned char *d, size_t n, unsigned char *md)
|
||||
|
||||
static void Internal_Sha0(unsigned char *dest, const unsigned char *src, const UINT size)
|
||||
{
|
||||
struct ampheck_sha0 c;
|
||||
static unsigned char m[SHA_DIGEST_LENGTH];
|
||||
|
||||
if (md == NULL) md=m;
|
||||
|
||||
ampheck_sha0_init(&c);
|
||||
ampheck_sha0_update(&c, d, (UINT)n);
|
||||
ampheck_sha0_finish(&c, md);
|
||||
|
||||
return md;
|
||||
ampheck_sha0_update(&c, src, size);
|
||||
ampheck_sha0_finish(&c, dest);
|
||||
}
|
||||
|
||||
|
||||
int GetSslClientCertIndex()
|
||||
{
|
||||
return ssl_clientcert_index;
|
||||
}
|
||||
|
||||
|
||||
|
@ -359,9 +359,10 @@ struct CIPHER
|
||||
struct MD
|
||||
{
|
||||
char Name[MAX_PATH];
|
||||
bool isNullMd;
|
||||
bool IsNullMd;
|
||||
bool IsHMac;
|
||||
const struct evp_md_st *Md;
|
||||
struct hmac_ctx_st *Ctx;
|
||||
void *Ctx;
|
||||
UINT Size;
|
||||
};
|
||||
|
||||
@ -490,6 +491,7 @@ void DesFreeKeyValue(DES_KEY_VALUE *v);
|
||||
void Des3Encrypt2(void *dest, void *src, UINT size, DES_KEY_VALUE *k1, DES_KEY_VALUE *k2, DES_KEY_VALUE *k3, void *ivec);
|
||||
void Des3Decrypt2(void *dest, void *src, UINT size, DES_KEY_VALUE *k1, DES_KEY_VALUE *k2, DES_KEY_VALUE *k3, void *ivec);
|
||||
void Sha(UINT sha_type, void *dst, void *src, UINT size);
|
||||
void Sha0(void *dst, void *src, UINT size);
|
||||
void Sha1(void *dst, void *src, UINT size);
|
||||
void Sha2_256(void *dst, void *src, UINT size);
|
||||
void Sha2_384(void *dst, void *src, UINT size);
|
||||
@ -524,6 +526,7 @@ void OpenSSL_FreeLock();
|
||||
void OpenSSL_Lock(int mode, int n, const char *file, int line);
|
||||
unsigned long OpenSSL_Id(void);
|
||||
void FreeOpenSSLThreadState();
|
||||
char *OpenSSL_Error();
|
||||
|
||||
CIPHER *NewCipher(char *name);
|
||||
void FreeCipher(CIPHER *c);
|
||||
@ -531,14 +534,15 @@ void SetCipherKey(CIPHER *c, void *key, bool enc);
|
||||
UINT CipherProcess(CIPHER *c, void *iv, void *dest, void *src, UINT size);
|
||||
|
||||
MD *NewMd(char *name);
|
||||
MD *NewMdEx(char *name, bool hmac);
|
||||
void FreeMd(MD *md);
|
||||
void SetMdKey(MD *md, void *key, UINT key_size);
|
||||
void MdProcess(MD *md, void *dest, void *src, UINT size);
|
||||
bool SetMdKey(MD *md, void *key, UINT key_size);
|
||||
UINT MdProcess(MD *md, void *dest, void *src, UINT size);
|
||||
void Enc_tls1_PRF(unsigned char *label, int label_len, const unsigned char *sec,
|
||||
int slen, unsigned char *out1, int olen);
|
||||
|
||||
void HMacSha1(void *dst, void *key, UINT key_size, void *data, UINT data_size);
|
||||
void HMacMd5(void *dst, void *key, UINT key_size, void *data, UINT data_size);
|
||||
UINT HMacSha1(void *dst, void *key, UINT key_size, void *data, UINT data_size);
|
||||
UINT HMacMd5(void *dst, void *key, UINT key_size, void *data, UINT data_size);
|
||||
|
||||
int GetSslClientCertIndex();
|
||||
|
||||
|
@ -714,7 +714,7 @@ void HashInstanceName(char *name, UINT size, char *instance_name)
|
||||
Trim(tmp);
|
||||
StrUpper(tmp);
|
||||
|
||||
Hash(hash, tmp, StrLen(tmp), SHA1_SIZE);
|
||||
Sha0(hash, tmp, StrLen(tmp));
|
||||
BinToStr(key, sizeof(key), hash, 5);
|
||||
key[10] = 0;
|
||||
|
||||
@ -745,7 +745,7 @@ void HashInstanceNameLocal(char *name, UINT size, char *instance_name)
|
||||
Trim(tmp);
|
||||
StrUpper(tmp);
|
||||
|
||||
Hash(hash, tmp, StrLen(tmp), SHA1_SIZE);
|
||||
Sha0(hash, tmp, StrLen(tmp));
|
||||
BinToStr(key, sizeof(key), hash, 5);
|
||||
key[10] = 0;
|
||||
|
||||
|
@ -147,7 +147,7 @@ PRAND *NewPRand(void *key, UINT key_size)
|
||||
|
||||
r = ZeroMalloc(sizeof(PRAND));
|
||||
|
||||
HashSha1(r->Key, key, key_size);
|
||||
Sha1(r->Key, key, key_size);
|
||||
|
||||
r->Rc4 = NewCrypt(key, key_size);
|
||||
|
||||
@ -2459,7 +2459,7 @@ BUF *FileToBuf(IO *o)
|
||||
}
|
||||
|
||||
// Take a hash
|
||||
Hash(hash2, buf, size, false);
|
||||
Md5(hash2, buf, size);
|
||||
|
||||
// Compare the hashes
|
||||
if (Cmp(hash1, hash2, sizeof(hash1)) != 0)
|
||||
@ -2664,7 +2664,7 @@ bool BufToFile(IO *o, BUF *b)
|
||||
}
|
||||
|
||||
// Hash the data
|
||||
Hash(hash, b->Buf, b->Size, false);
|
||||
Md5(hash, b->Buf, b->Size);
|
||||
|
||||
size = Endian32(b->Size);
|
||||
|
||||
|
@ -988,7 +988,7 @@ void *MsOpenOrCreateGlobalPulse(char *name)
|
||||
Trim(tmp);
|
||||
StrUpper(tmp);
|
||||
|
||||
HashSha1(hash, name, StrLen(name));
|
||||
Sha1(hash, name, StrLen(name));
|
||||
|
||||
BinToStr(tmp, sizeof(tmp), hash, sizeof(hash));
|
||||
|
||||
@ -2110,13 +2110,13 @@ void MsRegistWindowsFirewallEx(char *title, char *exe)
|
||||
tmp_size = StrLen(data) * 4;
|
||||
tmp = ZeroMalloc(tmp_size);
|
||||
|
||||
HashSha1(hashbin, exe, StrLen(exe));
|
||||
Sha1(hashbin, exe, StrLen(exe));
|
||||
BinToStr(hash, sizeof(hash), hashbin, 6);
|
||||
|
||||
ReplaceStrEx(tmp, tmp_size, data, "$TITLE$", title, false);
|
||||
ReplaceStrEx(tmp, tmp_size, tmp, "$PATH$", exe, false);
|
||||
|
||||
HashSha1(file_hash_bin, tmp, StrLen(tmp));
|
||||
Sha1(file_hash_bin, tmp, StrLen(tmp));
|
||||
BinToStr(file_hash_str, sizeof(file_hash_str), file_hash_bin, sizeof(file_hash_bin));
|
||||
|
||||
if (MsIsVista() == false || MsRegReadIntEx2(REG_LOCAL_MACHINE, SOFTETHER_FW_SCRIPT_HASH, file_hash_str, false, true) == 0)
|
||||
@ -2357,7 +2357,7 @@ void *MsLoadLibraryAsDataFileW(wchar_t *name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Hash(hash, name, UniStrLen(name), true);
|
||||
Sha0(hash, name, UniStrLen(name));
|
||||
|
||||
BinToStr(hash_str, sizeof(hash_str), hash, 4);
|
||||
|
||||
@ -2404,7 +2404,7 @@ void *MsLoadLibraryW(wchar_t *name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Hash(hash, name, UniStrSize(name), true);
|
||||
Sha0(hash, name, UniStrSize(name));
|
||||
|
||||
BinToStr(hash_str, sizeof(hash_str), hash, 4);
|
||||
|
||||
@ -4075,7 +4075,7 @@ void MsGenerateUserModeSvcGlobalPulseName(char *name, UINT size, char *svc_name)
|
||||
UniTrim(tmp);
|
||||
UniStrUpper(tmp);
|
||||
|
||||
HashSha1(hash, tmp, UniStrLen(tmp) * sizeof(wchar_t));
|
||||
Sha1(hash, tmp, UniStrLen(tmp) * sizeof(wchar_t));
|
||||
|
||||
BinToStr(name, size, hash, sizeof(hash));
|
||||
}
|
||||
@ -8365,7 +8365,7 @@ void MsGenMacAddress(UCHAR *mac)
|
||||
now = SystemTime64();
|
||||
Copy(hash_src, &now, sizeof(now));
|
||||
|
||||
Hash(hash, hash_src, sizeof(hash_src), true);
|
||||
Sha0(hash, hash_src, sizeof(hash_src));
|
||||
|
||||
mac[0] = 0x5E;
|
||||
mac[1] = hash[0];
|
||||
@ -12017,7 +12017,7 @@ bool MsCheckIsAdmin()
|
||||
DWORD size;
|
||||
char name[MAX_SIZE];
|
||||
|
||||
HashSha1(exe_hash, MsGetExeFileNameW(), UniStrLen(MsGetExeFileNameW()));
|
||||
Sha1(exe_hash, MsGetExeFileNameW(), UniStrLen(MsGetExeFileNameW()));
|
||||
|
||||
Format(name, sizeof(name), name_tag, *((UINT *)exe_hash));
|
||||
|
||||
|
@ -559,7 +559,7 @@ UINT GetCurrentDDnsFqdnHash()
|
||||
Trim(name);
|
||||
StrUpper(name);
|
||||
|
||||
HashSha1(hash, name, StrLen(name));
|
||||
Sha1(hash, name, StrLen(name));
|
||||
|
||||
Copy(&ret, hash, sizeof(UINT));
|
||||
|
||||
@ -2555,7 +2555,7 @@ void RUDPBulkSend(RUDP_STACK *r, RUDP_SESSION *se, void *data, UINT data_size)
|
||||
Copy(iv, se->BulkNextIv, SHA1_SIZE);
|
||||
Copy(crypt_key_src + 0, se->BulkSendKey->Data, SHA1_SIZE);
|
||||
Copy(crypt_key_src + SHA1_SIZE, iv, SHA1_SIZE);
|
||||
HashSha1(crypt_key, crypt_key_src, SHA1_SIZE * 2);
|
||||
Sha1(crypt_key, crypt_key_src, SHA1_SIZE * 2);
|
||||
c = NewCrypt(crypt_key, sizeof(crypt_key));
|
||||
Encrypt(c, buf + SHA1_SIZE + SHA1_SIZE, buf + SHA1_SIZE + SHA1_SIZE, sizeof(UINT64) + data_size + padding_size);
|
||||
FreeCrypt(c);
|
||||
@ -2567,7 +2567,7 @@ void RUDPBulkSend(RUDP_STACK *r, RUDP_SESSION *se, void *data, UINT data_size)
|
||||
if (se->UseHMac == false)
|
||||
{
|
||||
Copy(buf + 0, se->BulkSendKey->Data, SHA1_SIZE);
|
||||
HashSha1(sign, buf, SHA1_SIZE + SHA1_SIZE + sizeof(UINT64) + data_size + padding_size);
|
||||
Sha1(sign, buf, SHA1_SIZE + SHA1_SIZE + sizeof(UINT64) + data_size + padding_size);
|
||||
Copy(buf + 0, sign, SHA1_SIZE);
|
||||
}
|
||||
else
|
||||
@ -2690,7 +2690,7 @@ bool RUDPCheckSignOfRecvPacket(RUDP_STACK *r, RUDP_SESSION *se, void *recv_data,
|
||||
// Verification the signature (segment packet)
|
||||
Copy(sign, p, SHA1_SIZE);
|
||||
Copy(p, se->Key_Recv, SHA1_SIZE);
|
||||
HashSha1(sign2, p, recv_size);
|
||||
Sha1(sign2, p, recv_size);
|
||||
|
||||
if (r->Protocol == RUDP_PROTOCOL_DNS || r->Protocol == RUDP_PROTOCOL_ICMP)
|
||||
{
|
||||
@ -2713,7 +2713,7 @@ bool RUDPCheckSignOfRecvPacket(RUDP_STACK *r, RUDP_SESSION *se, void *recv_data,
|
||||
{
|
||||
Copy(sign, p, SHA1_SIZE);
|
||||
Copy(p, se->BulkRecvKey->Data, SHA1_SIZE);
|
||||
HashSha1(sign2, p, recv_size);
|
||||
Sha1(sign2, p, recv_size);
|
||||
Copy(p, sign, SHA1_SIZE);
|
||||
|
||||
if (Cmp(sign, sign2, SHA1_SIZE) == 0)
|
||||
@ -2765,7 +2765,7 @@ bool RUDPProcessBulkRecvPacket(RUDP_STACK *r, RUDP_SESSION *se, void *recv_data,
|
||||
{
|
||||
Copy(sign, p, SHA1_SIZE);
|
||||
Copy(p, se->BulkRecvKey->Data, SHA1_SIZE);
|
||||
HashSha1(sign2, p, recv_size);
|
||||
Sha1(sign2, p, recv_size);
|
||||
Copy(p, sign, SHA1_SIZE);
|
||||
|
||||
if (Cmp(sign, sign2, SHA1_SIZE) != 0)
|
||||
@ -2814,7 +2814,7 @@ bool RUDPProcessBulkRecvPacket(RUDP_STACK *r, RUDP_SESSION *se, void *recv_data,
|
||||
}
|
||||
Copy(keygen + 0, se->BulkRecvKey->Data, SHA1_SIZE);
|
||||
Copy(keygen + SHA1_SIZE, iv, SHA1_SIZE);
|
||||
HashSha1(key, keygen, sizeof(keygen));
|
||||
Sha1(key, keygen, sizeof(keygen));
|
||||
|
||||
c = NewCrypt(key, sizeof(key));
|
||||
Encrypt(c, p, p, size);
|
||||
@ -2910,7 +2910,7 @@ bool RUDPProcessRecvPacket(RUDP_STACK *r, RUDP_SESSION *se, void *recv_data, UIN
|
||||
// Validate the signature
|
||||
Copy(sign, p, SHA1_SIZE);
|
||||
Copy(p, se->Key_Recv, SHA1_SIZE);
|
||||
HashSha1(sign2, p, recv_size);
|
||||
Sha1(sign2, p, recv_size);
|
||||
Copy(p, sign, SHA1_SIZE);
|
||||
|
||||
if (r->Protocol == RUDP_PROTOCOL_DNS || r->Protocol == RUDP_PROTOCOL_ICMP)
|
||||
@ -2942,7 +2942,7 @@ bool RUDPProcessRecvPacket(RUDP_STACK *r, RUDP_SESSION *se, void *recv_data, UIN
|
||||
}
|
||||
Copy(keygen + 0, iv, SHA1_SIZE);
|
||||
Copy(keygen + SHA1_SIZE, se->Key_Recv, SHA1_SIZE);
|
||||
HashSha1(key, keygen, sizeof(keygen));
|
||||
Sha1(key, keygen, sizeof(keygen));
|
||||
|
||||
c = NewCrypt(key, sizeof(key));
|
||||
Encrypt(c, p, p, size);
|
||||
@ -3505,13 +3505,13 @@ void RUDPSendSegmentNow(RUDP_STACK *r, RUDP_SESSION *se, UINT64 seq_no, void *da
|
||||
// Encrypt
|
||||
Copy(keygen + 0, iv, SHA1_SIZE);
|
||||
Copy(keygen + SHA1_SIZE, se->Key_Send, SHA1_SIZE);
|
||||
HashSha1(key, keygen, sizeof(keygen));
|
||||
Sha1(key, keygen, sizeof(keygen));
|
||||
c = NewCrypt(key, sizeof(key));
|
||||
Encrypt(c, dst + SHA1_SIZE * 2, dst + SHA1_SIZE * 2, current_size - (SHA1_SIZE * 2));
|
||||
FreeCrypt(c);
|
||||
|
||||
// Sign
|
||||
HashSha1(sign, dst, current_size);
|
||||
Sha1(sign, dst, current_size);
|
||||
if (r->Protocol == RUDP_PROTOCOL_DNS || r->Protocol == RUDP_PROTOCOL_ICMP)
|
||||
{
|
||||
XorData(sign, sign, r->SvcNameHash, SHA1_SIZE);
|
||||
@ -3671,26 +3671,26 @@ RUDP_SESSION *RUDPNewSession(bool server_mode, IP *my_ip, UINT my_port, IP *your
|
||||
b = NewBuf();
|
||||
WriteBuf(b, init_key, SHA1_SIZE);
|
||||
WriteBufStr(b, "zurukko");
|
||||
HashSha1(key1, b->Buf, b->Size);
|
||||
Sha1(key1, b->Buf, b->Size);
|
||||
FreeBuf(b);
|
||||
|
||||
b = NewBuf();
|
||||
WriteBuf(b, init_key, SHA1_SIZE);
|
||||
WriteBuf(b, key1, SHA1_SIZE);
|
||||
WriteBufStr(b, "yasushineko");
|
||||
HashSha1(key2, b->Buf, b->Size);
|
||||
Sha1(key2, b->Buf, b->Size);
|
||||
FreeBuf(b);
|
||||
|
||||
// Generate the magic number for the KeepAlive
|
||||
b = NewBuf();
|
||||
WriteBuf(b, init_key, SHA1_SIZE);
|
||||
WriteBufStr(b, "Magic_KeepAliveRequest");
|
||||
HashSha1(se->Magic_KeepAliveRequest, b->Buf, b->Size);
|
||||
Sha1(se->Magic_KeepAliveRequest, b->Buf, b->Size);
|
||||
FreeBuf(b);
|
||||
b = NewBuf();
|
||||
WriteBuf(b, init_key, SHA1_SIZE);
|
||||
WriteBufStr(b, "Magic_KeepAliveResponse");
|
||||
HashSha1(se->Magic_KeepAliveResponse, b->Buf, b->Size);
|
||||
Sha1(se->Magic_KeepAliveResponse, b->Buf, b->Size);
|
||||
FreeBuf(b);
|
||||
|
||||
if (server_mode == false)
|
||||
@ -3852,7 +3852,7 @@ void RUDPMainThread(THREAD *thread, void *param)
|
||||
{
|
||||
UCHAR hash[SHA1_SIZE];
|
||||
|
||||
HashSha1(hash, ((UCHAR *)p->Data) + ip_header_size + sizeof(ICMP_HEADER) + sizeof(ICMP_ECHO) + SHA1_SIZE,
|
||||
Sha1(hash, ((UCHAR *)p->Data) + ip_header_size + sizeof(ICMP_HEADER) + sizeof(ICMP_ECHO) + SHA1_SIZE,
|
||||
p->Size - (ip_header_size + sizeof(ICMP_HEADER) + sizeof(ICMP_ECHO) + SHA1_SIZE));
|
||||
|
||||
if (Cmp(hash, ((UCHAR *)p->Data) + ip_header_size + sizeof(ICMP_HEADER) + sizeof(ICMP_ECHO), SHA1_SIZE) == 0)
|
||||
@ -3990,7 +3990,7 @@ void RUDPMainThread(THREAD *thread, void *param)
|
||||
Copy(icmp_data, p->Data, p->Size);
|
||||
|
||||
// Hash
|
||||
HashSha1(hash, icmp_data, p->Size);
|
||||
Sha1(hash, icmp_data, p->Size);
|
||||
|
||||
// Checksum calculation
|
||||
icmp_header->Checksum = IpChecksum(dst_data, dst_size);
|
||||
@ -4166,7 +4166,7 @@ void RUDPGetRegisterHostNameByIP(char *dst, UINT size, IP *ip)
|
||||
{
|
||||
UCHAR hash[SHA1_SIZE];
|
||||
|
||||
HashSha1(hash, ip->addr, 4);
|
||||
Sha1(hash, ip->addr, 4);
|
||||
BinToStr(tmp, sizeof(tmp), hash, 2);
|
||||
}
|
||||
else
|
||||
@ -4661,7 +4661,7 @@ UINT GetHostIPAddressHash32()
|
||||
|
||||
WriteBuf(b, rand_port_numbers, sizeof(rand_port_numbers));
|
||||
|
||||
HashSha1(hash, b->Buf, b->Size);
|
||||
Sha1(hash, b->Buf, b->Size);
|
||||
|
||||
FreeBuf(b);
|
||||
|
||||
@ -5291,7 +5291,7 @@ RUDP_STACK *NewRUDP(bool server_mode, char *svc_name, RUDP_STACK_INTERRUPTS_PROC
|
||||
Trim(tmp);
|
||||
StrLower(tmp);
|
||||
|
||||
HashSha1(r->SvcNameHash, tmp, StrLen(tmp));
|
||||
Sha1(r->SvcNameHash, tmp, StrLen(tmp));
|
||||
|
||||
r->Client_IcmpId = (USHORT)(Rand32() % 65534 + 1);
|
||||
r->Client_IcmpSeqNo = (USHORT)(Rand32() % 65534 + 1);
|
||||
@ -5310,7 +5310,7 @@ RUDP_STACK *NewRUDP(bool server_mode, char *svc_name, RUDP_STACK_INTERRUPTS_PROC
|
||||
#endif // OS_WIN32
|
||||
|
||||
pid = Endian32(pid);
|
||||
HashSha1(pid_hash, &pid, sizeof(UINT));
|
||||
Sha1(pid_hash, &pid, sizeof(UINT));
|
||||
|
||||
pid_us = READ_USHORT(pid_hash);
|
||||
if (pid_us == 0 || pid_us == 0xFFFF)
|
||||
@ -5564,7 +5564,7 @@ void GetCurrentMachineIpProcessHashInternal(void *hash)
|
||||
}
|
||||
FreeHostIPAddressList(ip_list);
|
||||
|
||||
HashSha1(hash, b->Buf, b->Size);
|
||||
Sha1(hash, b->Buf, b->Size);
|
||||
|
||||
FreeBuf(b);
|
||||
|
||||
@ -10677,7 +10677,7 @@ ROUTE_TABLE *GetRouteTable()
|
||||
WriteBuf(buf, e, sizeof(ROUTE_ENTRY));
|
||||
}
|
||||
|
||||
Hash(hash, buf->Buf, buf->Size, false);
|
||||
Md5(hash, buf->Buf, buf->Size);
|
||||
|
||||
FreeBuf(buf);
|
||||
|
||||
@ -11108,7 +11108,7 @@ SOCK *NewUDPEx2Rand(bool ipv6, IP *ip, void *rand_seed, UINT rand_seed_size, UIN
|
||||
WriteBuf(buf, rand_seed, rand_seed_size);
|
||||
WriteBufInt(buf, i);
|
||||
|
||||
HashSha1(hash, buf->Buf, buf->Size);
|
||||
Sha1(hash, buf->Buf, buf->Size);
|
||||
|
||||
FreeBuf(buf);
|
||||
|
||||
@ -11160,7 +11160,7 @@ SOCK *NewUDPEx2RandMachineAndExePath(bool ipv6, IP *ip, UINT num_retry, UCHAR ra
|
||||
WriteBufChar(b, rand_port_id);
|
||||
//WriteBufInt(b, GetHostIPAddressHash32());
|
||||
|
||||
HashSha1(hash, b->Buf, b->Size);
|
||||
Sha1(hash, b->Buf, b->Size);
|
||||
|
||||
FreeBuf(b);
|
||||
|
||||
@ -18092,7 +18092,7 @@ UINT64 GetHostIPAddressListHash()
|
||||
|
||||
WriteBufStr(buf, "test");
|
||||
|
||||
HashSha1(hash, buf->Buf, buf->Size);
|
||||
Sha1(hash, buf->Buf, buf->Size);
|
||||
|
||||
FreeBuf(buf);
|
||||
|
||||
@ -20926,7 +20926,7 @@ PACK *RecvPackWithHash(SOCK *s)
|
||||
return false;
|
||||
}
|
||||
|
||||
HashSha1(hash1, data, sz);
|
||||
Sha1(hash1, data, sz);
|
||||
if (RecvAll(s, hash2, sizeof(hash2), s->SecureMode) == false)
|
||||
{
|
||||
Free(data);
|
||||
@ -20987,7 +20987,7 @@ bool SendPackWithHash(SOCK *s, PACK *p)
|
||||
|
||||
SendAdd(s, &sz, sizeof(UINT));
|
||||
SendAdd(s, b->Buf, b->Size);
|
||||
HashSha1(hash, b->Buf, b->Size);
|
||||
Sha1(hash, b->Buf, b->Size);
|
||||
SendAdd(s, hash, sizeof(hash));
|
||||
|
||||
FreeBuf(b);
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -2288,7 +2288,7 @@ void UnixGenPidFileName(char *name, UINT size)
|
||||
StrCat(exe_name, sizeof(exe_name), ":pid_hash");
|
||||
StrUpper(exe_name);
|
||||
|
||||
Hash(hash, exe_name, StrLen(exe_name), false);
|
||||
Md5(hash, exe_name, StrLen(exe_name));
|
||||
BinToStr(tmp1, sizeof(tmp1), hash, sizeof(hash));
|
||||
|
||||
Format(name, size, "%s/.pid_%s", dir, tmp1);
|
||||
@ -2333,7 +2333,7 @@ void UnixGenCtlFileName(char *name, UINT size)
|
||||
StrCat(exe_name, sizeof(exe_name), ":pid_hash");
|
||||
StrUpper(exe_name);
|
||||
|
||||
Hash(hash, exe_name, StrLen(exe_name), false);
|
||||
Md5(hash, exe_name, StrLen(exe_name));
|
||||
BinToStr(tmp1, sizeof(tmp1), hash, sizeof(hash));
|
||||
|
||||
Format(name, size, "%s/.ctl_%s", dir, tmp1);
|
||||
|
Reference in New Issue
Block a user