Browse Source

Fix conflicting ShaDigest types.

Darryl Pogue 13 years ago
parent
commit
1b22f044f0
  1. 65
      Sources/Plasma/NucleusLib/pnUtils/pnUtCrypt.cpp
  2. 7
      Sources/Plasma/NucleusLib/pnUtils/pnUtCrypt.h
  3. 4
      Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp
  4. 4
      Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp
  5. 2
      Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCsr.cpp

65
Sources/Plasma/NucleusLib/pnUtils/pnUtCrypt.cpp

@ -49,7 +49,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "pnUtStr.h"
#include "pnUtTime.h"
#include <openssl/md5.h>
#include <openssl/sha.h>
#include <openssl/rc4.h>
@ -82,25 +81,6 @@ ShaDigest s_shaSeed;
*
***/
//============================================================================
void Md5Process (
void * dest,
unsigned sourceCount,
const unsigned sourceBytes[],
const void * sourcePtrs[]
) {
// initialize digest
MD5_CTX md5;
MD5_Init(&md5);
// hash data streams
for (unsigned index = 0; index < sourceCount; ++index)
MD5_Update(&md5, sourcePtrs[index], sourceBytes[index]);
// complete hashing
MD5_Final((unsigned char *)dest, &md5);
}
//============================================================================
void ShaProcess (
void * dest,
@ -120,25 +100,6 @@ void ShaProcess (
SHA_Final((unsigned char *)dest, &sha);
}
//============================================================================
void Sha1Process (
void * dest,
unsigned sourceCount,
const unsigned sourceBytes[],
const void * sourcePtrs[]
) {
// initialize digest
SHA_CTX sha;
SHA1_Init(&sha);
// hash data streams
for (unsigned index = 0; index < sourceCount; ++index)
SHA1_Update(&sha, sourcePtrs[index], sourceBytes[index]);
// complete hashing
SHA1_Final((unsigned char *)dest, &sha);
}
/*****************************************************************************
*
@ -208,18 +169,10 @@ void CryptDigest (
const void * sourcePtrs[] // [sourceCount]
) {
switch (algorithm) {
case kCryptMd5:
Md5Process(dest, sourceCount, sourceBytes, sourcePtrs);
break;
case kCryptSha:
ShaProcess(dest, sourceCount, sourceBytes, sourcePtrs);
break;
case kCryptSha1:
Sha1Process(dest, sourceCount, sourceBytes, sourcePtrs);
break;
DEFAULT_FATAL(algorithm);
}
}
@ -292,21 +245,21 @@ void CryptCreateRandomSeed (
unsigned cur = 0;
unsigned end = max(bytes, sizeof(s_shaSeed));
for (; cur < end; ++cur) {
((uint8_t *) &s_shaSeed)[seedIndex] ^= data[dataIndex];
s_shaSeed[seedIndex] ^= data[dataIndex];
if (++seedIndex >= sizeof(s_shaSeed))
seedIndex = 0;
if (++dataIndex >= bytes)
dataIndex = 0;
}
s_shaSeed.data[2] ^= (uint32_t) &bytes;
s_shaSeed.data[3] ^= (uint32_t) bytes;
s_shaSeed.data[4] ^= (uint32_t) data;
((uint32_t*)s_shaSeed)[2] ^= (uint32_t) &bytes;
((uint32_t*)s_shaSeed)[3] ^= (uint32_t) bytes;
((uint32_t*)s_shaSeed)[4] ^= (uint32_t) data;
}
// Hash seed
ShaDigest digest;
CryptDigest(kCryptSha, &digest, sizeof(s_shaSeed), &s_shaSeed);
CryptDigest(kCryptSha, &digest, sizeof(s_shaSeed), s_shaSeed);
// Update output with contents of digest
{
@ -324,11 +277,9 @@ void CryptCreateRandomSeed (
}
// Combine seed with digest
s_shaSeed.data[0] ^= digest.data[0];
s_shaSeed.data[1] ^= digest.data[1];
s_shaSeed.data[2] ^= digest.data[2];
s_shaSeed.data[3] ^= digest.data[3];
s_shaSeed.data[4] ^= digest.data[4];
for (size_t i = 0; i < SHA_DIGEST_LENGTH; i++) {
s_shaSeed[i] ^= digest[i];
}
}
//============================================================================

7
Sources/Plasma/NucleusLib/pnUtils/pnUtCrypt.h

@ -50,6 +50,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "Pch.h"
#include "pnUtArray.h"
#include "pnEncryption/plChecksum.h"
/*****************************************************************************
*
@ -61,17 +62,11 @@ struct CryptKey;
enum ECryptAlgorithm {
kCryptSha,
kCryptSha1,
kCryptMd5,
kCryptRc4,
kCryptRsa,
kNumCryptAlgorithms
};
struct ShaDigest {
uint32_t data[5];
};
/*****************************************************************************
*

4
Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp

@ -1210,7 +1210,7 @@ void NetCommSetAccountUsernamePassword (
const ShaDigest & namePassHash
) {
StrCopy(s_iniAccountUsername, username, arrsize(s_iniAccountUsername));
s_namePassHash = namePassHash;
memcpy(s_namePassHash, namePassHash, sizeof(ShaDigest));
s_iniReadAccountInfo = false;
}
@ -1252,7 +1252,7 @@ void NetCommAuthenticate (
s_iniAccountUsername,
arrsize(s_account.accountNameAnsi)
);
s_account.accountNamePassHash = s_namePassHash;
memcpy(s_account.accountNamePassHash, s_namePassHash, sizeof(ShaDigest));
NetCliAuthLoginRequest(
s_account.accountName,

4
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp

@ -2649,7 +2649,7 @@ bool LoginRequestTrans::Send () {
PathSplitEmail(s_accountName, nil, 0, domain, arrsize(domain), nil, 0, nil, 0, 0);
if (StrLen(domain) == 0 || StrCmpI(domain, L"gametap") == 0) {
challengeHash = s_accountNamePassHash;
memcpy(challengeHash, s_accountNamePassHash, sizeof(ShaDigest));
}
else {
CryptCreateRandomSeed(
@ -5253,7 +5253,7 @@ void NetCliAuthLoginRequest (
if (accountName)
StrCopy(s_accountName, accountName, arrsize(s_accountName));
if (accountNamePassHash)
s_accountNamePassHash = *accountNamePassHash;
memcpy(s_accountNamePassHash, *accountNamePassHash, sizeof(ShaDigest));
if (authToken)
StrCopy(s_authToken, authToken, arrsize(s_authToken));
if (os)

2
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCsr.cpp

@ -633,11 +633,11 @@ LoginRequestTrans::LoginRequestTrans (
FNetCliCsrLoginCallback callback,
void * param
) : NetCsrTrans(kCsrLoginTrans)
, m_namePassHash(namePassHash)
, m_callback(callback)
, m_param(param)
{
ASSERT(callback);
memcpy(m_namePassHash, namePassHash, sizeof(ShaDigest));
StrCopy(m_csrName, csrName, arrsize(m_csrName));
}

Loading…
Cancel
Save