1
0
mirror of https://github.com/unrealircd/unrealircd.git synced 2026-06-30 19:46:38 +02:00

Added MD5 and SHA1 encryption to the win32 version

This commit is contained in:
codemastr
2002-07-01 21:09:01 +00:00
parent e81ca7b87c
commit fdfdbd993e
4 changed files with 110 additions and 5 deletions
+97 -2
View File
@@ -182,7 +182,7 @@ int Auth_Check(aClient *cptr, anAuthStruct *as, char *para)
case AUTHTYPE_MD5:
if (!para)
return -1;
#ifndef _WIN32
if ((i = b64_encode(MD5(para, strlen(para), NULL),
MD5_DIGEST_LENGTH, buf, sizeof(buf))))
{
@@ -194,11 +194,37 @@ int Auth_Check(aClient *cptr, anAuthStruct *as, char *para)
else
return -1;
break;
#else
{
HCRYPTPROV hProv;
HCRYPTHASH hHash;
char buf2[512];
DWORD size = 512;
if (!CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, 0))
return -1;
if (!CryptCreateHash(hProv, CALG_MD5, 0, 0, &hHash))
return -1;
if (!CryptHashData(hHash, para, strlen(para), 0))
return -1;
if (!CryptGetHashParam(hHash, HP_HASHVAL, buf, &size, 0))
return -1;
CryptDestroyHash(hHash);
CryptReleaseContext(hProv, 0);
b64_encode(buf, 16, buf2, sizeof(buf2));
if (!strcmp(buf2, as->data))
return 2;
else
return -1;
}
break;
#endif
#endif
#ifdef AUTHENABLE_SHA1
case AUTHTYPE_SHA1:
if (!para)
return -1;
#ifndef _WIN32
if ((i = b64_encode(SHA1(para, strlen(para), NULL),
SHA_DIGEST_LENGTH, buf, sizeof(buf))))
@@ -211,6 +237,30 @@ int Auth_Check(aClient *cptr, anAuthStruct *as, char *para)
else
return -1;
break;
#else
{
HCRYPTPROV hProv;
HCRYPTHASH hHash;
char buf2[512];
DWORD size = 512;
if (!CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, 0))
return -1;
if (!CryptCreateHash(hProv, CALG_SHA1, 0, 0, &hHash))
return -1;
if (!CryptHashData(hHash, para, strlen(para), 0))
return -1;
if (!CryptGetHashParam(hHash, HP_HASHVAL, buf, &size, 0))
return -1;
CryptDestroyHash(hHash);
CryptReleaseContext(hProv, 0);
b64_encode(buf, 20, buf2, sizeof(buf2));
if (!strcmp(buf2, as->data))
return 2;
else
return -1;
}
break;
#endif
#endif
#ifdef AUTHENABLE_RIPEMD160
case AUTHTYPE_RIPEMD160:
@@ -282,6 +332,9 @@ char *Auth_Make(short type, char *para)
static char buf[512];
int i;
#endif
#ifdef _WIN32
static char buf2[512];
#endif
switch (type)
{
@@ -303,6 +356,7 @@ char *Auth_Make(short type, char *para)
case AUTHTYPE_MD5:
if (!para)
return NULL;
#ifndef _WIN32
if ((i = b64_encode(MD5(para, strlen(para), NULL),
MD5_DIGEST_LENGTH, buf, sizeof(buf))))
@@ -312,12 +366,32 @@ char *Auth_Make(short type, char *para)
else
return NULL;
break;
#else
{
HCRYPTPROV hProv;
HCRYPTHASH hHash;
DWORD size = 512;
if (!CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, 0))
return NULL;
if (!CryptCreateHash(hProv, CALG_MD5, 0, 0, &hHash))
return NULL;
if (!CryptHashData(hHash, para, strlen(para), 0))
return NULL;
if (!CryptGetHashParam(hHash, HP_HASHVAL, buf, &size, 0))
return NULL;
CryptDestroyHash(hHash);
CryptReleaseContext(hProv, 0);
b64_encode(buf, 16, buf2, sizeof(buf2));
return (buf2);
}
break;
#endif
#endif
#ifdef AUTHENABLE_SHA1
case AUTHTYPE_SHA1:
if (!para)
return NULL;
#ifndef _WIN32
if ((i = b64_encode(SHA1(para, strlen(para), NULL),
SHA_DIGEST_LENGTH, buf, sizeof(buf))))
{
@@ -326,6 +400,27 @@ char *Auth_Make(short type, char *para)
else
return NULL;
break;
#else
{
HCRYPTPROV hProv;
HCRYPTHASH hHash;
DWORD size = 512;
if (!CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, 0))
return NULL;
if (!CryptCreateHash(hProv, CALG_SHA1, 0, 0, &hHash))
return NULL;
if (!CryptHashData(hHash, para, strlen(para), 0))
return NULL;
if (!CryptGetHashParam(hHash, HP_HASHVAL, buf, &size, 0))
return NULL;
CryptDestroyHash(hHash);
CryptReleaseContext(hProv, 0);
b64_encode(buf, 20, buf2, sizeof(buf2));
return (buf2);
}
break;
#endif
#endif
#ifdef AUTHENABLE_RIPEMD160
case AUTHTYPE_RIPEMD160: