mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-22 13:16:23 +00:00
refactor(Core/Misc): acore to Acore (#6043)
This commit is contained in:
@@ -7,25 +7,25 @@
|
||||
#include "Errors.h"
|
||||
#include <limits>
|
||||
|
||||
acore::Crypto::AES::AES(bool encrypting) : _ctx(EVP_CIPHER_CTX_new()), _encrypting(encrypting)
|
||||
Acore::Crypto::AES::AES(bool encrypting) : _ctx(EVP_CIPHER_CTX_new()), _encrypting(encrypting)
|
||||
{
|
||||
EVP_CIPHER_CTX_init(_ctx);
|
||||
int status = EVP_CipherInit_ex(_ctx, EVP_aes_128_gcm(), nullptr, nullptr, nullptr, _encrypting ? 1 : 0);
|
||||
ASSERT(status);
|
||||
}
|
||||
|
||||
acore::Crypto::AES::~AES()
|
||||
Acore::Crypto::AES::~AES()
|
||||
{
|
||||
EVP_CIPHER_CTX_free(_ctx);
|
||||
}
|
||||
|
||||
void acore::Crypto::AES::Init(Key const& key)
|
||||
void Acore::Crypto::AES::Init(Key const& key)
|
||||
{
|
||||
int status = EVP_CipherInit_ex(_ctx, nullptr, nullptr, key.data(), nullptr, -1);
|
||||
ASSERT(status);
|
||||
}
|
||||
|
||||
bool acore::Crypto::AES::Process(IV const& iv, uint8* data, size_t length, Tag& tag)
|
||||
bool Acore::Crypto::AES::Process(IV const& iv, uint8* data, size_t length, Tag& tag)
|
||||
{
|
||||
ASSERT(length <= static_cast<size_t>(std::numeric_limits<int>::max()));
|
||||
int len = static_cast<int>(length);
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include <array>
|
||||
#include <openssl/evp.h>
|
||||
|
||||
namespace acore::Crypto
|
||||
namespace Acore::Crypto
|
||||
{
|
||||
class AC_COMMON_API AES
|
||||
{
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "ARC4.h"
|
||||
#include "Errors.h"
|
||||
|
||||
acore::Crypto::ARC4::ARC4()
|
||||
Acore::Crypto::ARC4::ARC4()
|
||||
: _ctx(EVP_CIPHER_CTX_new())
|
||||
{
|
||||
EVP_CIPHER_CTX_init(_ctx);
|
||||
@@ -15,12 +15,12 @@ acore::Crypto::ARC4::ARC4()
|
||||
ASSERT(result == 1);
|
||||
}
|
||||
|
||||
acore::Crypto::ARC4::~ARC4()
|
||||
Acore::Crypto::ARC4::~ARC4()
|
||||
{
|
||||
EVP_CIPHER_CTX_free(_ctx);
|
||||
}
|
||||
|
||||
void acore::Crypto::ARC4::Init(uint8 const* seed, size_t len)
|
||||
void Acore::Crypto::ARC4::Init(uint8 const* seed, size_t len)
|
||||
{
|
||||
int result1 = EVP_CIPHER_CTX_set_key_length(_ctx, len);
|
||||
ASSERT(result1 == 1);
|
||||
@@ -28,7 +28,7 @@ void acore::Crypto::ARC4::Init(uint8 const* seed, size_t len)
|
||||
ASSERT(result2 == 1);
|
||||
}
|
||||
|
||||
void acore::Crypto::ARC4::UpdateData(uint8* data, size_t len)
|
||||
void Acore::Crypto::ARC4::UpdateData(uint8* data, size_t len)
|
||||
{
|
||||
int outlen = 0;
|
||||
int result1 = EVP_EncryptUpdate(_ctx, data, &outlen, data, len);
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include <array>
|
||||
#include <openssl/evp.h>
|
||||
|
||||
namespace acore::Crypto
|
||||
namespace Acore::Crypto
|
||||
{
|
||||
class ARC4
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "Argon2.h"
|
||||
#include <argon2/argon2.h>
|
||||
|
||||
/*static*/ Optional<std::string> acore::Crypto::Argon2::Hash(std::string const& password, BigNumber const& salt, uint32 nIterations, uint32 kibMemoryCost)
|
||||
/*static*/ Optional<std::string> Acore::Crypto::Argon2::Hash(std::string const& password, BigNumber const& salt, uint32 nIterations, uint32 kibMemoryCost)
|
||||
{
|
||||
char buf[ENCODED_HASH_LEN];
|
||||
std::vector<uint8> saltBytes = salt.ToByteVector();
|
||||
@@ -25,7 +25,7 @@
|
||||
return {};
|
||||
}
|
||||
|
||||
/*static*/ bool acore::Crypto::Argon2::Verify(std::string const& password, std::string const& hash)
|
||||
/*static*/ bool Acore::Crypto::Argon2::Verify(std::string const& password, std::string const& hash)
|
||||
{
|
||||
int status = argon2id_verify(hash.c_str(), password.c_str(), password.length());
|
||||
return (status == ARGON2_OK);
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "Optional.h"
|
||||
#include <string>
|
||||
|
||||
namespace acore::Crypto
|
||||
namespace Acore::Crypto
|
||||
{
|
||||
struct AC_COMMON_API Argon2
|
||||
{
|
||||
|
||||
@@ -16,9 +16,9 @@ AuthCrypt::AuthCrypt() : _initialized(false)
|
||||
void AuthCrypt::Init(SessionKey const& K)
|
||||
{
|
||||
uint8 ServerEncryptionKey[] = { 0xCC, 0x98, 0xAE, 0x04, 0xE8, 0x97, 0xEA, 0xCA, 0x12, 0xDD, 0xC0, 0x93, 0x42, 0x91, 0x53, 0x57 };
|
||||
_serverEncrypt.Init(acore::Crypto::HMAC_SHA1::GetDigestOf(ServerEncryptionKey, K));
|
||||
_serverEncrypt.Init(Acore::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(acore::Crypto::HMAC_SHA1::GetDigestOf(ServerDecryptionKey, K));
|
||||
_clientDecrypt.Init(Acore::Crypto::HMAC_SHA1::GetDigestOf(ServerDecryptionKey, K));
|
||||
|
||||
// Drop first 1024 bytes, as WoW uses ARC4-drop1024.
|
||||
std::array<uint8, 1024> syncBuf;
|
||||
|
||||
@@ -23,8 +23,8 @@ public:
|
||||
bool IsInitialized() const { return _initialized; }
|
||||
|
||||
private:
|
||||
acore::Crypto::ARC4 _clientDecrypt;
|
||||
acore::Crypto::ARC4 _serverEncrypt;
|
||||
Acore::Crypto::ARC4 _clientDecrypt;
|
||||
Acore::Crypto::ARC4 _serverEncrypt;
|
||||
bool _initialized;
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
|
||||
using SHA1 = acore::Crypto::SHA1;
|
||||
using SRP6 = acore::Crypto::SRP6;
|
||||
using SHA1 = Acore::Crypto::SHA1;
|
||||
using SRP6 = Acore::Crypto::SRP6;
|
||||
|
||||
/*static*/ std::array<uint8, 1> const SRP6::g = { 7 };
|
||||
/*static*/ std::array<uint8, 32> const SRP6::N = HexStrToByteArray<32>("894B645E89E1535BBDAD5B8B290650530801B18EBFBF5E8FAB3C82872A3E9BB7", true);
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#include <array>
|
||||
#include <optional>
|
||||
|
||||
namespace acore::Crypto
|
||||
namespace Acore::Crypto
|
||||
{
|
||||
class SRP6
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
#include "Define.h"
|
||||
|
||||
namespace acore::Crypto
|
||||
namespace Acore::Crypto
|
||||
{
|
||||
struct Constants
|
||||
{
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include <iterator>
|
||||
#include <vector>
|
||||
|
||||
namespace acore::Impl
|
||||
namespace Acore::Impl
|
||||
{
|
||||
struct CryptoGenericsImpl
|
||||
{
|
||||
@@ -21,7 +21,7 @@ namespace acore::Impl
|
||||
static typename Cipher::IV GenerateRandomIV()
|
||||
{
|
||||
typename Cipher::IV iv;
|
||||
acore::Crypto::GetRandomBytes(iv);
|
||||
Acore::Crypto::GetRandomBytes(iv);
|
||||
return iv;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace acore::Impl
|
||||
};
|
||||
}
|
||||
|
||||
namespace acore::Crypto
|
||||
namespace Acore::Crypto
|
||||
{
|
||||
template <typename Cipher>
|
||||
void AEEncryptWithRandomIV(std::vector<uint8>& data, typename Cipher::Key const& key)
|
||||
@@ -52,7 +52,7 @@ namespace acore::Crypto
|
||||
using IV = typename Cipher::IV;
|
||||
using Tag = typename Cipher::Tag;
|
||||
// select random IV
|
||||
IV iv = acore::Impl::CryptoGenericsImpl::GenerateRandomIV<Cipher>();
|
||||
IV iv = Acore::Impl::CryptoGenericsImpl::GenerateRandomIV<Cipher>();
|
||||
Tag tag;
|
||||
|
||||
// encrypt data
|
||||
@@ -62,8 +62,8 @@ namespace acore::Crypto
|
||||
ASSERT(success);
|
||||
|
||||
// append trailing IV and tag
|
||||
acore::Impl::CryptoGenericsImpl::AppendToBack(data, iv);
|
||||
acore::Impl::CryptoGenericsImpl::AppendToBack(data, tag);
|
||||
Acore::Impl::CryptoGenericsImpl::AppendToBack(data, iv);
|
||||
Acore::Impl::CryptoGenericsImpl::AppendToBack(data, tag);
|
||||
}
|
||||
|
||||
template <typename Cipher>
|
||||
@@ -80,8 +80,8 @@ namespace acore::Crypto
|
||||
// extract trailing IV and tag
|
||||
IV iv;
|
||||
Tag tag;
|
||||
acore::Impl::CryptoGenericsImpl::SplitFromBack(data, tag);
|
||||
acore::Impl::CryptoGenericsImpl::SplitFromBack(data, iv);
|
||||
Acore::Impl::CryptoGenericsImpl::SplitFromBack(data, tag);
|
||||
Acore::Impl::CryptoGenericsImpl::SplitFromBack(data, iv);
|
||||
|
||||
// decrypt data
|
||||
Cipher cipher(false);
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
class BigNumber;
|
||||
|
||||
namespace acore::Impl
|
||||
namespace Acore::Impl
|
||||
{
|
||||
struct GenericHashImpl
|
||||
{
|
||||
@@ -98,10 +98,10 @@ namespace acore::Impl
|
||||
};
|
||||
}
|
||||
|
||||
namespace acore::Crypto
|
||||
namespace Acore::Crypto
|
||||
{
|
||||
using SHA1 = acore::Impl::GenericHash<EVP_sha1, Constants::SHA1_DIGEST_LENGTH_BYTES>;
|
||||
using SHA256 = acore::Impl::GenericHash<EVP_sha256, Constants::SHA256_DIGEST_LENGTH_BYTES>;
|
||||
using SHA1 = Acore::Impl::GenericHash<EVP_sha1, Constants::SHA1_DIGEST_LENGTH_BYTES>;
|
||||
using SHA256 = Acore::Impl::GenericHash<EVP_sha256, Constants::SHA256_DIGEST_LENGTH_BYTES>;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "Errors.h"
|
||||
#include <openssl/rand.h>
|
||||
|
||||
void acore::Crypto::GetRandomBytes(uint8* buf, size_t len)
|
||||
void Acore::Crypto::GetRandomBytes(uint8* buf, size_t len)
|
||||
{
|
||||
int result = RAND_bytes(buf, len);
|
||||
ASSERT(result == 1);
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "Define.h"
|
||||
#include <array>
|
||||
|
||||
namespace acore::Crypto
|
||||
namespace Acore::Crypto
|
||||
{
|
||||
void GetRandomBytes(uint8* buf, size_t len);
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
class BigNumber;
|
||||
|
||||
namespace acore::Impl
|
||||
namespace Acore::Impl
|
||||
{
|
||||
struct HMACImpl
|
||||
{
|
||||
@@ -110,9 +110,9 @@ namespace acore::Impl
|
||||
};
|
||||
}
|
||||
|
||||
namespace acore::Crypto
|
||||
namespace Acore::Crypto
|
||||
{
|
||||
using HMAC_SHA1 = acore::Impl::GenericHMAC<EVP_sha1, Constants::SHA1_DIGEST_LENGTH_BYTES>;
|
||||
using HMAC_SHA256 = acore::Impl::GenericHMAC<EVP_sha256, Constants::SHA256_DIGEST_LENGTH_BYTES>;
|
||||
using HMAC_SHA1 = Acore::Impl::GenericHMAC<EVP_sha1, Constants::SHA1_DIGEST_LENGTH_BYTES>;
|
||||
using HMAC_SHA256 = Acore::Impl::GenericHMAC<EVP_sha256, Constants::SHA256_DIGEST_LENGTH_BYTES>;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/hmac.h>
|
||||
|
||||
constexpr std::size_t acore::Crypto::TOTP::RECOMMENDED_SECRET_LENGTH;
|
||||
constexpr std::size_t Acore::Crypto::TOTP::RECOMMENDED_SECRET_LENGTH;
|
||||
static constexpr uint32 TOTP_INTERVAL = 30;
|
||||
static constexpr uint32 HMAC_RESULT_SIZE = 20;
|
||||
|
||||
/*static*/ uint32 acore::Crypto::TOTP::GenerateToken(Secret const& secret, time_t timestamp)
|
||||
/*static*/ uint32 Acore::Crypto::TOTP::GenerateToken(Secret const& secret, time_t timestamp)
|
||||
{
|
||||
timestamp /= TOTP_INTERVAL;
|
||||
unsigned char challenge[8];
|
||||
@@ -31,7 +31,7 @@ static constexpr uint32 HMAC_RESULT_SIZE = 20;
|
||||
return (truncated % 1000000);
|
||||
}
|
||||
|
||||
/*static*/ bool acore::Crypto::TOTP::ValidateToken(Secret const& secret, uint32 token)
|
||||
/*static*/ bool Acore::Crypto::TOTP::ValidateToken(Secret const& secret, uint32 token)
|
||||
{
|
||||
time_t now = time(nullptr);
|
||||
return (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include <ctime>
|
||||
#include <vector>
|
||||
|
||||
namespace acore::Crypto
|
||||
namespace Acore::Crypto
|
||||
{
|
||||
struct AC_COMMON_API TOTP
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user