aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/common/Cryptography/SHA1.h3
-rw-r--r--src/common/Cryptography/SHA256.h3
-rw-r--r--src/common/Cryptography/SessionKeyGeneration.h (renamed from src/common/Cryptography/WardenKeyGeneration.h)37
-rw-r--r--src/server/game/Warden/WardenMac.cpp4
-rw-r--r--src/server/game/Warden/WardenWin.cpp4
5 files changed, 29 insertions, 22 deletions
diff --git a/src/common/Cryptography/SHA1.h b/src/common/Cryptography/SHA1.h
index ffa02176a2d..944350265f4 100644
--- a/src/common/Cryptography/SHA1.h
+++ b/src/common/Cryptography/SHA1.h
@@ -21,6 +21,7 @@
#include "Define.h"
#include <string>
+#include <type_traits>
#include <openssl/sha.h>
class BigNumber;
@@ -28,6 +29,8 @@ class BigNumber;
class SHA1Hash
{
public:
+ typedef std::integral_constant<uint32, SHA_DIGEST_LENGTH> DigestLength;
+
SHA1Hash();
~SHA1Hash();
diff --git a/src/common/Cryptography/SHA256.h b/src/common/Cryptography/SHA256.h
index d31c24ed93b..33f23f639a4 100644
--- a/src/common/Cryptography/SHA256.h
+++ b/src/common/Cryptography/SHA256.h
@@ -20,6 +20,7 @@
#include "Define.h"
#include <string>
+#include <type_traits>
#include <openssl/sha.h>
class BigNumber;
@@ -27,6 +28,8 @@ class BigNumber;
class SHA256Hash
{
public:
+ typedef std::integral_constant<uint32, SHA256_DIGEST_LENGTH> DigestLength;
+
SHA256Hash();
~SHA256Hash();
diff --git a/src/common/Cryptography/WardenKeyGeneration.h b/src/common/Cryptography/SessionKeyGeneration.h
index 18118ece649..0ec4479b765 100644
--- a/src/common/Cryptography/WardenKeyGeneration.h
+++ b/src/common/Cryptography/SessionKeyGeneration.h
@@ -16,17 +16,16 @@
* 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
-#define _WARDEN_KEY_GENERATION_H
-
-class SHA1Randx
+template<class Hash>
+class SessionKeyGenerator
{
public:
- SHA1Randx(uint8* buff, uint32 size)
+ SessionKeyGenerator(uint8* buff, uint32 size)
{
uint32 halfSize = size / 2;
@@ -34,15 +33,15 @@ public:
sh.UpdateData(buff, halfSize);
sh.Finalize();
- memcpy(o1, sh.GetDigest(), 20);
+ memcpy(o1, sh.GetDigest(), Hash::DigestLength::value);
sh.Initialize();
sh.UpdateData(buff + halfSize, size - halfSize);
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();
}
@@ -51,7 +50,7 @@ public:
{
for (uint32 i = 0; i < sz; ++i)
{
- if (taken == 20)
+ if (taken == Hash::DigestLength::value)
FillUp();
buf[i] = o0[taken];
@@ -63,19 +62,21 @@ private:
void FillUp()
{
sh.Initialize();
- sh.UpdateData(o1, 20);
- sh.UpdateData(o0, 20);
- sh.UpdateData(o2, 20);
+ sh.UpdateData(o1, Hash::DigestLength::value);
+ sh.UpdateData(o0, Hash::DigestLength::value);
+ sh.UpdateData(o2, Hash::DigestLength::value);
sh.Finalize();
- memcpy(o0, sh.GetDigest(), 20);
+ memcpy(o0, sh.GetDigest(), Hash::DigestLength::value);
taken = 0;
}
- SHA1Hash sh;
+ Hash sh;
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__
diff --git a/src/server/game/Warden/WardenMac.cpp b/src/server/game/Warden/WardenMac.cpp
index 6df1dc7561c..3c89792745b 100644
--- a/src/server/game/Warden/WardenMac.cpp
+++ b/src/server/game/Warden/WardenMac.cpp
@@ -16,7 +16,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "Cryptography/WardenKeyGeneration.h"
+#include "Cryptography/SessionKeyGeneration.h"
#include "Common.h"
#include "WorldPacket.h"
#include "WorldSession.h"
@@ -39,7 +39,7 @@ void WardenMac::Init(WorldSession* pClient, BigNumber* K)
{
_session = pClient;
// Generate Warden Key
- SHA1Randx WK(K->AsByteArray().get(), K->GetNumBytes());
+ SessionKeyGenerator<SHA1Hash> WK(K->AsByteArray().get(), K->GetNumBytes());
WK.Generate(_inputKey, 16);
WK.Generate(_outputKey, 16);
/*
diff --git a/src/server/game/Warden/WardenWin.cpp b/src/server/game/Warden/WardenWin.cpp
index b99a6cd3ac9..96857dd26d3 100644
--- a/src/server/game/Warden/WardenWin.cpp
+++ b/src/server/game/Warden/WardenWin.cpp
@@ -17,7 +17,7 @@
*/
#include "Cryptography/HmacHash.h"
-#include "Cryptography/WardenKeyGeneration.h"
+#include "Cryptography/SessionKeyGeneration.h"
#include "Common.h"
#include "WorldPacket.h"
#include "WorldSession.h"
@@ -42,7 +42,7 @@ void WardenWin::Init(WorldSession* session, BigNumber* k)
{
_session = session;
// Generate Warden Key
- SHA1Randx WK(k->AsByteArray().get(), k->GetNumBytes());
+ SessionKeyGenerator<SHA1Hash> WK(k->AsByteArray().get(), k->GetNumBytes());
WK.Generate(_inputKey, 16);
WK.Generate(_outputKey, 16);