aboutsummaryrefslogtreecommitdiff
path: root/src/common/Cryptography/Authentication
diff options
context:
space:
mode:
authorTreeston <treeston.mmoc@gmail.com>2020-07-26 01:53:34 +0200
committerGitHub <noreply@github.com>2020-07-26 01:53:34 +0200
commit210176fd915cf4ba16f428d3c1a249a71f4aa7a7 (patch)
tree6998a19da1330be8679fe3e760f858915494400b /src/common/Cryptography/Authentication
parentcdaf890af4b5bb7ce256752b49bba2c0f3ed9264 (diff)
Core/Authserver: Authserver cleanup (PR#25093)
- Fix a handful of 1/256 bugs with most significant byte zero in BigNumber - Get rid of (most of) the C-style arrays in authserver - CryptoRandom as a unified source for cryptographic randomness - Bring our other crypto APIs into 2020 - BigNumber usability improvements - Authserver is now actually readable as a result of all of the above
Diffstat (limited to 'src/common/Cryptography/Authentication')
-rw-r--r--src/common/Cryptography/Authentication/AuthCrypt.cpp49
-rw-r--r--src/common/Cryptography/Authentication/AuthCrypt.h15
2 files changed, 22 insertions, 42 deletions
diff --git a/src/common/Cryptography/Authentication/AuthCrypt.cpp b/src/common/Cryptography/Authentication/AuthCrypt.cpp
index c4ff701f5d1..9d50fb026c3 100644
--- a/src/common/Cryptography/Authentication/AuthCrypt.cpp
+++ b/src/common/Cryptography/Authentication/AuthCrypt.cpp
@@ -16,58 +16,39 @@
*/
#include "AuthCrypt.h"
-#include "Cryptography/HMACSHA1.h"
-#include "Cryptography/BigNumber.h"
+#include "BigNumber.h"
+#include "Errors.h"
+#include "HMAC.h"
#include <cstring>
AuthCrypt::AuthCrypt() :
- _clientDecrypt(SHA_DIGEST_LENGTH), _serverEncrypt(SHA_DIGEST_LENGTH),
_initialized(false)
{ }
-void AuthCrypt::Init(BigNumber* K)
+void AuthCrypt::Init(std::array<uint8, 40> const& K)
{
- uint8 ServerEncryptionKey[SEED_KEY_SIZE] = { 0xCC, 0x98, 0xAE, 0x04, 0xE8, 0x97, 0xEA, 0xCA, 0x12, 0xDD, 0xC0, 0x93, 0x42, 0x91, 0x53, 0x57 };
- HmacHash serverEncryptHmac(SEED_KEY_SIZE, (uint8*)ServerEncryptionKey);
- uint8 *encryptHash = serverEncryptHmac.ComputeHash(K);
-
- uint8 ServerDecryptionKey[SEED_KEY_SIZE] = { 0xC2, 0xB3, 0x72, 0x3C, 0xC6, 0xAE, 0xD9, 0xB5, 0x34, 0x3C, 0x53, 0xEE, 0x2F, 0x43, 0x67, 0xCE };
- HmacHash clientDecryptHmac(SEED_KEY_SIZE, (uint8*)ServerDecryptionKey);
- uint8 *decryptHash = clientDecryptHmac.ComputeHash(K);
-
- //ARC4 _serverDecrypt(encryptHash);
- _clientDecrypt.Init(decryptHash);
- _serverEncrypt.Init(encryptHash);
- //ARC4 _clientEncrypt(decryptHash);
+ uint8 ServerEncryptionKey[] = { 0xCC, 0x98, 0xAE, 0x04, 0xE8, 0x97, 0xEA, 0xCA, 0x12, 0xDD, 0xC0, 0x93, 0x42, 0x91, 0x53, 0x57 };
+ _serverEncrypt.Init(Trinity::Crypto::HMAC_SHA1::GetDigestOf(ServerEncryptionKey, K));
+ uint8 ServerDecryptionKey[] = { 0xC2, 0xB3, 0x72, 0x3C, 0xC6, 0xAE, 0xD9, 0xB5, 0x34, 0x3C, 0x53, 0xEE, 0x2F, 0x43, 0x67, 0xCE };
+ _clientDecrypt.Init(Trinity::Crypto::HMAC_SHA1::GetDigestOf(ServerDecryptionKey, K));
// Drop first 1024 bytes, as WoW uses ARC4-drop1024.
- uint8 syncBuf[1024];
- memset(syncBuf, 0, 1024);
-
- _serverEncrypt.UpdateData(1024, syncBuf);
- //_clientEncrypt.UpdateData(1024, syncBuf);
-
- memset(syncBuf, 0, 1024);
-
- //_serverDecrypt.UpdateData(1024, syncBuf);
- _clientDecrypt.UpdateData(1024, syncBuf);
+ std::array<uint8, 1024> syncBuf;
+ _serverEncrypt.UpdateData(syncBuf);
+ _clientDecrypt.UpdateData(syncBuf);
_initialized = true;
}
void AuthCrypt::DecryptRecv(uint8 *data, size_t len)
{
- if (!_initialized)
- return;
-
- _clientDecrypt.UpdateData(len, data);
+ ASSERT(_initialized);
+ _clientDecrypt.UpdateData(data, len);
}
void AuthCrypt::EncryptSend(uint8 *data, size_t len)
{
- if (!_initialized)
- return;
-
- _serverEncrypt.UpdateData(len, data);
+ ASSERT(_initialized);
+ _serverEncrypt.UpdateData(data, len);
}
diff --git a/src/common/Cryptography/Authentication/AuthCrypt.h b/src/common/Cryptography/Authentication/AuthCrypt.h
index c6d4066350c..cb1a217297a 100644
--- a/src/common/Cryptography/Authentication/AuthCrypt.h
+++ b/src/common/Cryptography/Authentication/AuthCrypt.h
@@ -18,24 +18,23 @@
#ifndef _AUTHCRYPT_H
#define _AUTHCRYPT_H
-#include "Cryptography/ARC4.h"
-
-class BigNumber;
+#include "ARC4.h"
+#include <array>
class TC_COMMON_API AuthCrypt
{
public:
AuthCrypt();
- void Init(BigNumber* K);
- void DecryptRecv(uint8 *, size_t);
- void EncryptSend(uint8 *, size_t);
+ void Init(std::array<uint8, 40> const& K);
+ void DecryptRecv(uint8* data, size_t len);
+ void EncryptSend(uint8* data, size_t len);
bool IsInitialized() const { return _initialized; }
private:
- ARC4 _clientDecrypt;
- ARC4 _serverEncrypt;
+ Trinity::Crypto::ARC4 _clientDecrypt;
+ Trinity::Crypto::ARC4 _serverEncrypt;
bool _initialized;
};
#endif