2009-02-04 10:33:18 -06:00
|
|
|
/*
|
2009-02-04 12:42:26 +01:00
|
|
|
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
2008-10-14 11:57:03 -05:00
|
|
|
*
|
2010-01-16 20:19:18 +03:00
|
|
|
* Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/>
|
2008-10-02 16:23:55 -05:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2008-10-14 11:57:03 -05:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2008-10-02 16:23:55 -05:00
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
2008-10-14 11:57:03 -05:00
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2008-10-02 16:23:55 -05:00
|
|
|
*/
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
#include "AuthCrypt.h"
|
|
|
|
|
#include "Hmac.h"
|
2009-06-11 00:45:59 -05:00
|
|
|
#include "Log.h"
|
|
|
|
|
#include "BigNumber.h"
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2010-04-11 11:11:32 +04:00
|
|
|
AuthCrypt::AuthCrypt() : _clientDecrypt(SHA_DIGEST_LENGTH), _serverEncrypt(SHA_DIGEST_LENGTH)
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
|
|
|
|
_initialized = false;
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2009-06-11 00:45:59 -05:00
|
|
|
AuthCrypt::~AuthCrypt()
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2009-06-11 00:45:59 -05:00
|
|
|
void AuthCrypt::Init(BigNumber *K)
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
2010-04-11 11:11:32 +04:00
|
|
|
uint8 ServerEncryptionKey[SEED_KEY_SIZE] = { 0xCC, 0x98, 0xAE, 0x04, 0xE8, 0x97, 0xEA, 0xCA, 0x12, 0xDD, 0xC0, 0x93, 0x42, 0x91, 0x53, 0x57 };
|
2009-06-11 00:45:59 -05:00
|
|
|
HmacHash serverEncryptHmac(SEED_KEY_SIZE, (uint8*)ServerEncryptionKey);
|
|
|
|
|
uint8 *encryptHash = serverEncryptHmac.ComputeHash(K);
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2010-04-11 11:11:32 +04:00
|
|
|
uint8 ServerDecryptionKey[SEED_KEY_SIZE] = { 0xC2, 0xB3, 0x72, 0x3C, 0xC6, 0xAE, 0xD9, 0xB5, 0x34, 0x3C, 0x53, 0xEE, 0x2F, 0x43, 0x67, 0xCE };
|
2009-06-11 00:45:59 -05:00
|
|
|
HmacHash clientDecryptHmac(SEED_KEY_SIZE, (uint8*)ServerDecryptionKey);
|
|
|
|
|
uint8 *decryptHash = clientDecryptHmac.ComputeHash(K);
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2009-06-11 00:45:59 -05:00
|
|
|
//SARC4 _serverDecrypt(encryptHash);
|
|
|
|
|
_clientDecrypt.Init(decryptHash);
|
|
|
|
|
_serverEncrypt.Init(encryptHash);
|
|
|
|
|
//SARC4 _clientEncrypt(decryptHash);
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2009-06-11 00:45:59 -05:00
|
|
|
uint8 syncBuf[1024];
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2009-06-11 00:45:59 -05:00
|
|
|
memset(syncBuf, 0, 1024);
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2009-06-11 00:45:59 -05:00
|
|
|
_serverEncrypt.UpdateData(1024, syncBuf);
|
|
|
|
|
//_clientEncrypt.UpdateData(1024, syncBuf);
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2009-06-11 00:45:59 -05:00
|
|
|
memset(syncBuf, 0, 1024);
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2009-06-11 00:45:59 -05:00
|
|
|
//_serverDecrypt.UpdateData(1024, syncBuf);
|
|
|
|
|
_clientDecrypt.UpdateData(1024, syncBuf);
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2009-06-11 00:45:59 -05:00
|
|
|
_initialized = true;
|
2008-10-02 16:23:55 -05:00
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2009-06-11 00:45:59 -05:00
|
|
|
void AuthCrypt::DecryptRecv(uint8 *data, size_t len)
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
2009-06-11 00:45:59 -05:00
|
|
|
if (!_initialized)
|
|
|
|
|
return;
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2009-06-11 00:45:59 -05:00
|
|
|
_clientDecrypt.UpdateData(len, data);
|
2008-10-02 16:23:55 -05:00
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2009-06-11 00:45:59 -05:00
|
|
|
void AuthCrypt::EncryptSend(uint8 *data, size_t len)
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
2009-06-11 00:45:59 -05:00
|
|
|
if (!_initialized)
|
|
|
|
|
return;
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2009-06-11 00:45:59 -05:00
|
|
|
_serverEncrypt.UpdateData(len, data);
|
2008-10-02 16:23:55 -05:00
|
|
|
}
|
2009-02-17 20:07:49 -06:00
|
|
|
|