summaryrefslogtreecommitdiff
path: root/csgo-loader/csgo-client/Security/Encryption.cpp
diff options
context:
space:
mode:
authorboris <wzn@moneybot.cc>2019-01-01 20:31:51 +1300
committerboris <wzn@moneybot.cc>2019-01-01 20:31:51 +1300
commit7a3b48831bfc9c4aa8c39c1e42d5bf5dd73e43c5 (patch)
tree954898c772081536a5ff4dc36a42591608b797c0 /csgo-loader/csgo-client/Security/Encryption.cpp
parentb9702fe8541e61f27f5c788dc72feaefe5abfc0d (diff)
whole buncha fixes & switching to vmp
Diffstat (limited to 'csgo-loader/csgo-client/Security/Encryption.cpp')
-rw-r--r--csgo-loader/csgo-client/Security/Encryption.cpp43
1 files changed, 25 insertions, 18 deletions
diff --git a/csgo-loader/csgo-client/Security/Encryption.cpp b/csgo-loader/csgo-client/Security/Encryption.cpp
index 133946a..d361d1c 100644
--- a/csgo-loader/csgo-client/Security/Encryption.cpp
+++ b/csgo-loader/csgo-client/Security/Encryption.cpp
@@ -563,21 +563,36 @@ namespace Wrapper
}
// Wrapper for the AES256 encryption algorithm.
- void Encryption::Start() { }
+ void Encryption::Start()
+ {
+ // Create cryptographic context.
+ if(!CryptAcquireContextA(&m_CryptProvider, nullptr, nullptr, PROV_RSA_AES, 0))
+ {
+ if(!CryptAcquireContextA(&m_CryptProvider, nullptr, nullptr, PROV_RSA_AES, CRYPT_NEWKEYSET))
+ INFO_ASSERT("Critical failure\nContact an admin with the following code: %08x", GetLastError());
+ }
+
+ uint8_t RandomBytes[32];
+ uint32_t RandomBytesCount = sizeof RandomBytes;
+
+ // Generate random bytes to use as encryption key.
+ if(CryptGenRandom(m_CryptProvider, RandomBytesCount, RandomBytes))
+ std::memcpy(m_EncryptionKey, RandomBytes, RandomBytesCount);
+
+ // Release context.
+ if(m_CryptProvider)
+ CryptReleaseContext(m_CryptProvider, 0);
+ }
void Encryption::Start(ByteArray &EncryptionKey)
{
// If an encryption key is provided, initialise the wrapper with
// the passed parameter.
if(!EncryptionKey.empty())
- {
- for(auto &It : EncryptionKey)
- m_EncryptionKey.emplace_back(It);
- }
- else
- {
+ std::memcpy(m_EncryptionKey, EncryptionKey.data(), EncryptionKey.size());
+
+ if(EncryptionKey.empty())
Start();
- }
}
ByteArray Encryption::Encrypt(ByteArray &Data)
@@ -585,11 +600,7 @@ namespace Wrapper
// Encrypt outgoing data.
ByteArray Encrypted;
- #ifdef DEBUG
- Encrypted = Data;
- #else
- Aes256::encrypt(m_EncryptionKey, Data, Encrypted);
- #endif
+ Aes256::encrypt(GetKey(), Data, Encrypted);
return Encrypted;
}
@@ -599,11 +610,7 @@ namespace Wrapper
// Decrypt incoming data.
ByteArray Decrypted;
- #ifdef DEBUG
- Decrypted = Data;
- #else
- Aes256::decrypt(m_EncryptionKey, Data, Decrypted);
- #endif
+ Aes256::decrypt(GetKey(), Data, Decrypted);
return Decrypted;
}