RSA signature stuff.
This commit is contained in:
parent
2706e50881
commit
ad6220fa0b
21
src/Main.cpp
21
src/Main.cpp
@ -14,11 +14,6 @@ namespace Main
|
|||||||
{
|
{
|
||||||
Components::Loader::Uninitialize();
|
Components::Loader::Uninitialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreInit()
|
|
||||||
{
|
|
||||||
ltc_mp = ltm_desc;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
|
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
|
||||||
@ -47,7 +42,21 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReser
|
|||||||
|
|
||||||
})->Install();
|
})->Install();
|
||||||
|
|
||||||
Main::PreInit();
|
// auto key = Utils::Cryptography::RSA::GenerateKey(2048);
|
||||||
|
// std::string message = "ZOB1234543253253452345";
|
||||||
|
// std::string signature = Utils::Cryptography::RSA::SignMessage(key, message);
|
||||||
|
//
|
||||||
|
// // Invalidate the signature
|
||||||
|
// //signature[0] ^= 0xFF;
|
||||||
|
//
|
||||||
|
// if (Utils::Cryptography::RSA::VerifyMessage(key, message, signature))
|
||||||
|
// {
|
||||||
|
// MessageBoxA(0, "Valid", 0, 0);
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// MessageBoxA(0, "Invalid!", 0, 0);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
else if (ul_reason_for_call == DLL_PROCESS_DETACH)
|
else if (ul_reason_for_call == DLL_PROCESS_DETACH)
|
||||||
{
|
{
|
||||||
|
@ -70,6 +70,7 @@
|
|||||||
#include "Utils\Memory.hpp"
|
#include "Utils\Memory.hpp"
|
||||||
#include "Utils\Hooking.hpp"
|
#include "Utils\Hooking.hpp"
|
||||||
#include "Utils\Compression.hpp"
|
#include "Utils\Compression.hpp"
|
||||||
|
#include "Utils\Cryptography.hpp"
|
||||||
|
|
||||||
#include "Steam\Steam.hpp"
|
#include "Steam\Steam.hpp"
|
||||||
|
|
||||||
|
48
src/Utils/Cryptography.cpp
Normal file
48
src/Utils/Cryptography.cpp
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
#include "STDInclude.hpp"
|
||||||
|
|
||||||
|
/// http://www.opensource.apple.com/source/CommonCrypto/CommonCrypto-55010/Source/libtomcrypt/doc/libTomCryptDoc.pdf
|
||||||
|
|
||||||
|
namespace Utils
|
||||||
|
{
|
||||||
|
namespace Cryptography
|
||||||
|
{
|
||||||
|
RSA::Key RSA::GenerateKey(int bits)
|
||||||
|
{
|
||||||
|
RSA::Key key;
|
||||||
|
|
||||||
|
register_prng(&sprng_desc);
|
||||||
|
register_hash(&sha1_desc);
|
||||||
|
|
||||||
|
ltc_mp = ltm_desc;
|
||||||
|
|
||||||
|
rsa_make_key(NULL, find_prng("sprng"), bits / 8, 65537, key.GetKeyPtr());
|
||||||
|
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string RSA::SignMessage(RSA::Key key, std::string message)
|
||||||
|
{
|
||||||
|
uint8_t buffer[0x200]; // Default size is 512
|
||||||
|
DWORD length = sizeof(buffer);
|
||||||
|
|
||||||
|
register_prng(&sprng_desc);
|
||||||
|
register_hash(&sha1_desc);
|
||||||
|
|
||||||
|
ltc_mp = ltm_desc;
|
||||||
|
|
||||||
|
rsa_sign_hash(reinterpret_cast<const uint8_t*>(message.data()), message.size(), buffer, &length, NULL, find_prng("sprng"), find_hash("sha1"), 0, key.GetKeyPtr());
|
||||||
|
|
||||||
|
return std::string(reinterpret_cast<char*>(buffer), length);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RSA::VerifyMessage(Key key, std::string message, std::string signature)
|
||||||
|
{
|
||||||
|
register_hash(&sha1_desc);
|
||||||
|
|
||||||
|
ltc_mp = ltm_desc;
|
||||||
|
|
||||||
|
int result = 0;
|
||||||
|
return (rsa_verify_hash(reinterpret_cast<const uint8_t*>(signature.data()), signature.size(), reinterpret_cast<const uint8_t*>(message.data()), message.size(), find_hash("sha1"), 0, &result, key.GetKeyPtr()) == CRYPT_OK && result != 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
32
src/Utils/Cryptography.hpp
Normal file
32
src/Utils/Cryptography.hpp
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
namespace Utils
|
||||||
|
{
|
||||||
|
namespace Cryptography
|
||||||
|
{
|
||||||
|
class RSA
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
class Key
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Key() { ZeroMemory(&this->KeyStorage, sizeof(this->KeyStorage)); };
|
||||||
|
Key(rsa_key* key) : Key(*key) {};
|
||||||
|
Key(rsa_key key) : KeyStorage(key) {};
|
||||||
|
Key(const Key& obj) : KeyStorage(obj.KeyStorage) {};
|
||||||
|
|
||||||
|
~Key() {}
|
||||||
|
|
||||||
|
rsa_key* GetKeyPtr()
|
||||||
|
{
|
||||||
|
return &this->KeyStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
rsa_key KeyStorage;
|
||||||
|
};
|
||||||
|
|
||||||
|
static RSA::Key GenerateKey(int bits);
|
||||||
|
static std::string SignMessage(Key key, std::string message);
|
||||||
|
static bool VerifyMessage(Key key, std::string message, std::string signature);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user