diff --git a/Source/Utility/MD5.cpp b/Source/Utility/MD5.cpp new file mode 100644 index 0000000..a8efa61 --- /dev/null +++ b/Source/Utility/MD5.cpp @@ -0,0 +1,48 @@ +#include "Utility/MD5.h" + +#include +#include +#include + +namespace { + // INLINED + inline std::uint32_t FoldDigest(const unsigned char* digest) { + return ((digest[0] ^ digest[1] ^ digest[2] ^ digest[3]) << 8) + | (digest[4] ^ digest[5] ^ digest[6] ^ digest[7]) + | ((digest[8] ^ digest[9] ^ digest[10] ^ digest[11]) << 16) + | (static_cast(digest[12] ^ digest[13] ^ digest[14] ^ digest[15]) << 24); + } +} + +// FUNCTION: fn_00121 +MD5::MD5() { +} + + + + +#define MD5_F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z)))) +#define MD5_F2(x, y, z) ((y) ^ ((z) & ((x) ^ (y)))) +#define MD5_F3(x, y, z) ((x) ^ (y) ^ (z)) +#define MD5_F4(x, y, z) ((y) ^ ((x) | ~(z))) +#define MD5_STEP(f, a, b, c, d, x, s, t) do { \ + (a) += f((b), (c), (d)) + (x) + (t); \ + (a) = (((a) << (s)) | ((a) >> (32 - (s)))) + (b); \ +} while (0) + + +#undef MD5_STEP +#undef MD5_F4 +#undef MD5_F3 +#undef MD5_F2 +#undef MD5_F1 + + + + + + + + + + diff --git a/Source/Utility/MD5.h b/Source/Utility/MD5.h new file mode 100644 index 0000000..116701b --- /dev/null +++ b/Source/Utility/MD5.h @@ -0,0 +1,37 @@ +#ifndef RAGNAROK_SOURCE_UTILITY_MD5_H +#define RAGNAROK_SOURCE_UTILITY_MD5_H + +#include + +class MD5 { +public: + MD5(); + ~MD5(); + + int Initialize(); + void Update(const unsigned char* input, std::uint32_t length); + unsigned char* Finalize(); + unsigned char* DigestBuffer(const unsigned char* input, std::uint32_t length, unsigned char* digest); + std::uint32_t HashBuffer(const unsigned char* input, std::uint32_t length); + std::uint32_t HashString(const char* text); + std::uint32_t HashString(const wchar_t* text); + std::uint32_t HashFile(const wchar_t* filename); + std::uint32_t HashStringLower(const char* text); + std::uint32_t HashStringLower(const wchar_t* text); + std::uint32_t HashFile(const char* filename); + +private: + const unsigned char* Decode(std::uint32_t* output, const unsigned char* input, std::uint32_t count); + std::uint32_t* Transform(std::uint32_t* state, const std::uint32_t* input); + + union { + /* 0000 */ unsigned char m_buffer[64]; + /* 0000 */ std::uint32_t m_words[16]; + }; + /* 0040 */ std::uint32_t m_state[4]; + /* 0050 */ std::uint32_t m_byteCount[2]; +}; + +static_assert(sizeof(MD5) == 0x58); + +#endif diff --git a/compile.json b/compile.json index 1983a8c..49b4d91 100644 --- a/compile.json +++ b/compile.json @@ -574,6 +574,7 @@ "Source/Utility/Async/NRecycleObjectPoolMgr.cpp": 0, "Source/Utility/Base64.cpp": 0, "Source/Utility/GuidParse.cpp": 0, + "Source/Utility/MD5.cpp": 0, "Source/Utility/Math/AffineLookAt.cpp": 0, "Source/Utility/Math/AffineMatrix.cpp": 0, "Source/Utility/Math/ClientAngles.cpp": 0,