[9250] Fixed my typo in 9246_01_characters_character.sql
[getmangos.git] / src / shared / Auth / AuthCrypt.cpp
blob782ae008b3f673833bf632f79a0e73ab78a80c0b
1 /*
2 * Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "AuthCrypt.h"
20 #include "Hmac.h"
21 #include "Log.h"
22 #include "BigNumber.h"
24 AuthCrypt::AuthCrypt()
26 _initialized = false;
29 AuthCrypt::~AuthCrypt()
34 void AuthCrypt::Init(BigNumber *K)
36 uint8 ServerEncryptionKey[SEED_KEY_SIZE] = { 0x22, 0xBE, 0xE5, 0xCF, 0xBB, 0x07, 0x64, 0xD9, 0x00, 0x45, 0x1B, 0xD0, 0x24, 0xB8, 0xD5, 0x45 };
37 HmacHash serverEncryptHmac(SEED_KEY_SIZE, (uint8*)ServerEncryptionKey);
38 uint8 *encryptHash = serverEncryptHmac.ComputeHash(K);
40 uint8 ServerDecryptionKey[SEED_KEY_SIZE] = { 0xF4, 0x66, 0x31, 0x59, 0xFC, 0x83, 0x6E, 0x31, 0x31, 0x02, 0x51, 0xD5, 0x44, 0x31, 0x67, 0x98 };
41 HmacHash clientDecryptHmac(SEED_KEY_SIZE, (uint8*)ServerDecryptionKey);
42 uint8 *decryptHash = clientDecryptHmac.ComputeHash(K);
44 //SARC4 _serverDecrypt(encryptHash);
45 _clientDecrypt.Init(decryptHash);
46 _serverEncrypt.Init(encryptHash);
47 //SARC4 _clientEncrypt(decryptHash);
49 uint8 syncBuf[1024];
51 memset(syncBuf, 0, 1024);
53 _serverEncrypt.UpdateData(1024, syncBuf);
54 //_clientEncrypt.UpdateData(1024, syncBuf);
56 memset(syncBuf, 0, 1024);
58 //_serverDecrypt.UpdateData(1024, syncBuf);
59 _clientDecrypt.UpdateData(1024, syncBuf);
61 _initialized = true;
64 void AuthCrypt::DecryptRecv(uint8 *data, size_t len)
66 if (!_initialized)
67 return;
69 _clientDecrypt.UpdateData(len, data);
72 void AuthCrypt::EncryptSend(uint8 *data, size_t len)
74 if (!_initialized)
75 return;
77 _serverEncrypt.UpdateData(len, data);