mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-23 10:26:28 +01:00
Core/Crypto: Renamed SHA1Randx/WardenKeyGeneration and made it a template class
This commit is contained in:
@@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include "Define.h"
|
#include "Define.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <type_traits>
|
||||||
#include <openssl/sha.h>
|
#include <openssl/sha.h>
|
||||||
|
|
||||||
class BigNumber;
|
class BigNumber;
|
||||||
@@ -28,6 +29,8 @@ class BigNumber;
|
|||||||
class SHA1Hash
|
class SHA1Hash
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
typedef std::integral_constant<uint32, SHA_DIGEST_LENGTH> DigestLength;
|
||||||
|
|
||||||
SHA1Hash();
|
SHA1Hash();
|
||||||
~SHA1Hash();
|
~SHA1Hash();
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include "Define.h"
|
#include "Define.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <type_traits>
|
||||||
#include <openssl/sha.h>
|
#include <openssl/sha.h>
|
||||||
|
|
||||||
class BigNumber;
|
class BigNumber;
|
||||||
@@ -27,6 +28,8 @@ class BigNumber;
|
|||||||
class SHA256Hash
|
class SHA256Hash
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
typedef std::integral_constant<uint32, SHA256_DIGEST_LENGTH> DigestLength;
|
||||||
|
|
||||||
SHA256Hash();
|
SHA256Hash();
|
||||||
~SHA256Hash();
|
~SHA256Hash();
|
||||||
|
|
||||||
|
|||||||
@@ -16,17 +16,16 @@
|
|||||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "SHA1.h"
|
#ifndef SessionKeyGeneration_h__
|
||||||
|
#define SessionKeyGeneration_h__
|
||||||
|
|
||||||
#include <cstring>
|
#include "Common.h"
|
||||||
|
|
||||||
#ifndef _WARDEN_KEY_GENERATION_H
|
template<class Hash>
|
||||||
#define _WARDEN_KEY_GENERATION_H
|
class SessionKeyGenerator
|
||||||
|
|
||||||
class SHA1Randx
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SHA1Randx(uint8* buff, uint32 size)
|
SessionKeyGenerator(uint8* buff, uint32 size)
|
||||||
{
|
{
|
||||||
uint32 halfSize = size / 2;
|
uint32 halfSize = size / 2;
|
||||||
|
|
||||||
@@ -34,15 +33,15 @@ public:
|
|||||||
sh.UpdateData(buff, halfSize);
|
sh.UpdateData(buff, halfSize);
|
||||||
sh.Finalize();
|
sh.Finalize();
|
||||||
|
|
||||||
memcpy(o1, sh.GetDigest(), 20);
|
memcpy(o1, sh.GetDigest(), Hash::DigestLength::value);
|
||||||
|
|
||||||
sh.Initialize();
|
sh.Initialize();
|
||||||
sh.UpdateData(buff + halfSize, size - halfSize);
|
sh.UpdateData(buff + halfSize, size - halfSize);
|
||||||
sh.Finalize();
|
sh.Finalize();
|
||||||
|
|
||||||
memcpy(o2, sh.GetDigest(), 20);
|
memcpy(o2, sh.GetDigest(), Hash::DigestLength::value);
|
||||||
|
|
||||||
memset(o0, 0x00, 20);
|
memset(o0, 0x00, Hash::DigestLength::value);
|
||||||
|
|
||||||
FillUp();
|
FillUp();
|
||||||
}
|
}
|
||||||
@@ -51,7 +50,7 @@ public:
|
|||||||
{
|
{
|
||||||
for (uint32 i = 0; i < sz; ++i)
|
for (uint32 i = 0; i < sz; ++i)
|
||||||
{
|
{
|
||||||
if (taken == 20)
|
if (taken == Hash::DigestLength::value)
|
||||||
FillUp();
|
FillUp();
|
||||||
|
|
||||||
buf[i] = o0[taken];
|
buf[i] = o0[taken];
|
||||||
@@ -63,19 +62,21 @@ private:
|
|||||||
void FillUp()
|
void FillUp()
|
||||||
{
|
{
|
||||||
sh.Initialize();
|
sh.Initialize();
|
||||||
sh.UpdateData(o1, 20);
|
sh.UpdateData(o1, Hash::DigestLength::value);
|
||||||
sh.UpdateData(o0, 20);
|
sh.UpdateData(o0, Hash::DigestLength::value);
|
||||||
sh.UpdateData(o2, 20);
|
sh.UpdateData(o2, Hash::DigestLength::value);
|
||||||
sh.Finalize();
|
sh.Finalize();
|
||||||
|
|
||||||
memcpy(o0, sh.GetDigest(), 20);
|
memcpy(o0, sh.GetDigest(), Hash::DigestLength::value);
|
||||||
|
|
||||||
taken = 0;
|
taken = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SHA1Hash sh;
|
Hash sh;
|
||||||
uint32 taken;
|
uint32 taken;
|
||||||
uint8 o0[20], o1[20], o2[20];
|
uint8 o0[Hash::DigestLength::value];
|
||||||
|
uint8 o1[Hash::DigestLength::value];
|
||||||
|
uint8 o2[Hash::DigestLength::value];
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif // SessionKeyGeneration_h__
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Cryptography/WardenKeyGeneration.h"
|
#include "Cryptography/SessionKeyGeneration.h"
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include "WorldPacket.h"
|
#include "WorldPacket.h"
|
||||||
#include "WorldSession.h"
|
#include "WorldSession.h"
|
||||||
@@ -39,7 +39,7 @@ void WardenMac::Init(WorldSession* pClient, BigNumber* K)
|
|||||||
{
|
{
|
||||||
_session = pClient;
|
_session = pClient;
|
||||||
// Generate Warden Key
|
// Generate Warden Key
|
||||||
SHA1Randx WK(K->AsByteArray().get(), K->GetNumBytes());
|
SessionKeyGenerator<SHA1Hash> WK(K->AsByteArray().get(), K->GetNumBytes());
|
||||||
WK.Generate(_inputKey, 16);
|
WK.Generate(_inputKey, 16);
|
||||||
WK.Generate(_outputKey, 16);
|
WK.Generate(_outputKey, 16);
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Cryptography/HmacHash.h"
|
#include "Cryptography/HmacHash.h"
|
||||||
#include "Cryptography/WardenKeyGeneration.h"
|
#include "Cryptography/SessionKeyGeneration.h"
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include "WorldPacket.h"
|
#include "WorldPacket.h"
|
||||||
#include "WorldSession.h"
|
#include "WorldSession.h"
|
||||||
@@ -42,7 +42,7 @@ void WardenWin::Init(WorldSession* session, BigNumber* k)
|
|||||||
{
|
{
|
||||||
_session = session;
|
_session = session;
|
||||||
// Generate Warden Key
|
// Generate Warden Key
|
||||||
SHA1Randx WK(k->AsByteArray().get(), k->GetNumBytes());
|
SessionKeyGenerator<SHA1Hash> WK(k->AsByteArray().get(), k->GetNumBytes());
|
||||||
WK.Generate(_inputKey, 16);
|
WK.Generate(_inputKey, 16);
|
||||||
WK.Generate(_outputKey, 16);
|
WK.Generate(_outputKey, 16);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user