Шутка в том, что не трудно. в начале функци CUserSocket::OnCreate
PHP код:
m_pAuthUser = new CAuthUser;
m_pAuthUser->Init();
где
PHP код:
R_RANDOM_STRUCT *CAuthUser::InitRandomStruct(void)
{
static unsigned char seedByte = 0;
unsigned int bytesNeeded;
static R_RANDOM_STRUCT randomStruct;
R_RandomInit(&randomStruct);
srand((unsigned)time(NULL));
while (1) {
seedByte = rand();
R_GetRandomBytesNeeded(&bytesNeeded, &randomStruct);
if(bytesNeeded == 0)
break;
R_RandomUpdate(&randomStruct, &seedByte, 1);
}
return(&randomStruct);
}
void CAuthUser::scrambleModulus()
{
unsigned char *scrambledMod = m_RSA, temp;
memcpy(m_RSA, m_rsaPubKey.modulus, 0x80);
// step 1 : 0x4d-0x50 <-> 0x00-0x04
for (int i = 0; i < 4; i++)
{
temp = scrambledMod[0x00 + i];
scrambledMod[0x00 + i] = scrambledMod[0x4d + i];
scrambledMod[0x4d + i] = temp;
}
// step 2 : xor first 0x40 bytes with last 0x40 bytes
for (int i = 0; i < 0x40; i++)
{
scrambledMod[i] = (scrambledMod[i] ^ scrambledMod[0x40 + i]);
}
// step 3 : xor bytes 0x0d-0x10 with bytes 0x34-0x38
for (int i = 0; i < 4; i++)
{
scrambledMod[0x0d + i] = (scrambledMod[0x0d + i] ^ scrambledMod[0x34 + i]);
}
// step 4 : xor last 0x40 bytes with first 0x40 bytes
for (int i = 0; i < 0x40; i++)
{
scrambledMod[0x40 + i] = (scrambledMod[0x40 + i] ^ scrambledMod[i]);
}
}
void CAuthUser::Init()
{
R_RANDOM_STRUCT *randomStruct;
R_RSA_PROTO_KEY protoKey;
randomStruct = InitRandomStruct();
protoKey.bits = 1024;
protoKey.useFermat4 = 1;
if(R_GeneratePEMKeys(&m_rsaPubKey, &m_rsaPrivKey, &protoKey, randomStruct)) {
MessageBox(NULL, L"ERROR", L"Error", MB_OK || MB_ICONSTOP);
return;
}
scrambleModulus();
}