Compare commits

...

2 Commits

Author SHA1 Message Date
6ee4389b57 clean up crypto packages 2025-09-06 21:11:34 -05:00
c97592e485 Update rc4.cpp 2025-09-06 20:20:32 -05:00
6 changed files with 59 additions and 63 deletions

View File

@ -1,9 +1,7 @@
// Copyright (C) 2007-2025 EQ2EMulator // Copyright (C) 2007-2025 EQ2EMulator
// Licensed under GPL v3 // Licensed under GPL v3
#include <stdio.h> unsigned long IntArray[] = {
unsigned long IntArray[] = {
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA,
0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988,
@ -68,55 +66,55 @@ unsigned long IntArray[] = {
0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF,
0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94,
0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D,
}; };
unsigned long CRC16(const unsigned char *buf, int size, int key) unsigned long CRC16(const unsigned char *buf, int size, int key)
{ {
unsigned long ecx = key; //mov ecx, [esp+arg_8] unsigned long ecx = key; //mov ecx, [esp+arg_8]
unsigned long eax = ecx; //mov eax, ecx unsigned long eax = ecx; //mov eax, ecx
unsigned long edi; unsigned long edi;
eax = ~ eax; //not eax eax = ~ eax; //not eax
eax&=0xFF; //and eax, 0FFh eax&=0xFF; //and eax, 0FFh
eax=IntArray[eax]; //mov eax, dword_0_10115D38[eax*4] IntArray eax=IntArray[eax]; //mov eax, dword_0_10115D38[eax*4] IntArray
eax ^= 0x00FFFFFF; //xor eax, 0FFFFFFh eax ^= 0x00FFFFFF; //xor eax, 0FFFFFFh
int edx = ecx; //mov edx, ecx int edx = ecx; //mov edx, ecx
edx = edx >> 8; //sar edx, 8 edx = edx >> 8; //sar edx, 8
edx = edx ^ eax; //xor edx, eax edx = edx ^ eax; //xor edx, eax
eax = eax >> 8; //sar eax, 8 eax = eax >> 8; //sar eax, 8
edx &= 0xFF; //and edx, 0FFh edx &= 0xFF; //and edx, 0FFh
eax &= 0x00FFFFFF; //and eax, 0FFFFFFh eax &= 0x00FFFFFF; //and eax, 0FFFFFFh
eax ^= IntArray[edx]; //xor eax, dword_0_10115D38[edx*4] eax ^= IntArray[edx]; //xor eax, dword_0_10115D38[edx*4]
edx = ecx; //mov edx, ecx edx = ecx; //mov edx, ecx
edx = edx >> 0x10; //sar edx, 10h edx = edx >> 0x10; //sar edx, 10h
edx ^= eax; //xor edx, eax edx ^= eax; //xor edx, eax
eax = eax >> 8; //sar eax, 8 eax = eax >> 8; //sar eax, 8
edx &= 0xFF; //and edx, 0FFh edx &= 0xFF; //and edx, 0FFh
int esi = IntArray[edx]; //mov esi, dword_0_10115D38[edx*4] int esi = IntArray[edx]; //mov esi, dword_0_10115D38[edx*4]
edx = size; //mov edx, [esp+4+arg_4] edx = size; //mov edx, [esp+4+arg_4]
eax &= 0x00FFFFFF; //and eax, 0FFFFFFh eax &= 0x00FFFFFF; //and eax, 0FFFFFFh
eax ^= esi; //xor eax, esi eax ^= esi; //xor eax, esi
ecx = ecx >> 0x18; //sar ecx, 18h ecx = ecx >> 0x18; //sar ecx, 18h
ecx ^= eax; //xor ecx, eax ecx ^= eax; //xor ecx, eax
ecx &= 0xFF; //and ecx, 0FFh ecx &= 0xFF; //and ecx, 0FFh
esi = IntArray[ecx]; //mov esi, dword_0_10115D38[ecx*4] esi = IntArray[ecx]; //mov esi, dword_0_10115D38[ecx*4]
ecx = (int)*buf; //mov ecx, [esp+4+arg_0] ecx = (int)*buf; //mov ecx, [esp+4+arg_0]
eax = eax >> 8; //sar eax, 8 eax = eax >> 8; //sar eax, 8
eax &= 0x00FFFFFF; //and eax, 0FFFFFFh eax &= 0x00FFFFFF; //and eax, 0FFFFFFh
eax ^= esi; //xor eax, esi eax ^= esi; //xor eax, esi
for(int x = 0; x < size; x++) { for(int x = 0; x < size; x++) {
//eax is the crc, ecx is the current part of the buffer //eax is the crc, ecx is the current part of the buffer
int edx = 0; //xor edx, edx int edx = 0; //xor edx, edx
edx = buf[x] & 0x00FF; //mov dl, [ecx] edx = buf[x] & 0x00FF; //mov dl, [ecx]
edx ^= eax; //xor edx, eax edx ^= eax; //xor edx, eax
eax = eax >> 8; //sar eax, 8 eax = eax >> 8; //sar eax, 8
edx &= 0xFF; //and edx, 0FFh edx &= 0xFF; //and edx, 0FFh
edi = IntArray[edx]; //mov edi, dword_0_10115D38[edx*4] edi = IntArray[edx]; //mov edi, dword_0_10115D38[edx*4]
eax &= 0x00FFFFFF; //and eax, 0FFFFFFh eax &= 0x00FFFFFF; //and eax, 0FFFFFFh
eax ^= edi; //xor eax, edi eax ^= edi; //xor eax, edi
} }
return ~eax; return ~eax;
} }

View File

@ -2,12 +2,11 @@
// Licensed under GPL v3 // Licensed under GPL v3
#include "crypto.h" #include "crypto.h"
#include <algorithm>
#include <array> #include <array>
#include <cstring> #include <cstring>
#include <mutex> #include <mutex>
int64 Crypto::RSADecrypt(uchar* text, int16 size) noexcept int64 Crypto::RSADecrypt(uchar* text, [[maybe_unused]] int16 size) noexcept
{ {
int64 ret = 0; int64 ret = 0;
std::array<uchar, 8> buffer{}; std::array<uchar, 8> buffer{};
@ -50,4 +49,3 @@ void Crypto::setRC4Key(int64 key) noexcept
server.reset(); server.reset();
} }
} }

View File

@ -2,14 +2,14 @@
// Licensed under GPL v3 // Licensed under GPL v3
#include "rc4.h" #include "rc4.h"
#include <algorithm> #include <cstddef>
#include <cstring>
#include <numeric>
static constexpr std::array<uchar, 256> get_init_state() noexcept static constexpr std::array<uchar, 256> get_init_state() noexcept
{ {
std::array<uchar, 256> state{}; std::array<uchar, 256> state{};
std::iota(state.begin(), state.end(), 0); for (std::size_t i = 0; i < 256; ++i) {
state[i] = static_cast<uchar>(i);
}
return state; return state;
} }

View File

@ -1,5 +1,6 @@
// Copyright (C) 2007-2025 EQ2EMulator // Copyright (C) 2007-2025 EQ2EMulator
// Licensed under GPL v3 // Licensed under GPL v3
#pragma once #pragma once
#include "../types.h" #include "../types.h"
@ -19,4 +20,3 @@ private:
uchar m_x{}; uchar m_x{};
uchar m_y{}; uchar m_y{};
}; };

View File

@ -2,7 +2,6 @@
// Licensed under GPL v3 // Licensed under GPL v3
#include "sha512.h" #include "sha512.h"
#include <algorithm>
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
@ -158,7 +157,7 @@ std::string sha512(std::string_view input) noexcept
ctx.final(digest.data()); ctx.final(digest.data());
std::array<char, 2 * SHA512::DIGEST_SIZE + 1> buf{}; std::array<char, 2 * SHA512::DIGEST_SIZE + 1> buf{};
for (int i = 0; i < SHA512::DIGEST_SIZE; ++i) { for (unsigned int i = 0; i < SHA512::DIGEST_SIZE; ++i) {
std::sprintf(buf.data() + i * 2, "%02x", digest[i]); std::sprintf(buf.data() + i * 2, "%02x", digest[i]);
} }
return std::string{buf.data()}; return std::string{buf.data()};

View File

@ -1,3 +1,6 @@
// Copyright (C) 2007-2025 EQ2EMulator
// Licensed under GPL v3
#pragma once #pragma once
#include <array> #include <array>
@ -21,9 +24,9 @@ protected:
using uint64 = std::uint64_t; using uint64 = std::uint64_t;
static const std::array<uint64, 80> sha512_k; static const std::array<uint64, 80> sha512_k;
void transform(const unsigned char* message, unsigned int block_nb) noexcept; void transform(const unsigned char* message, unsigned int block_nb) noexcept;
unsigned int m_tot_len{}; unsigned int m_tot_len{};
unsigned int m_len{}; unsigned int m_len{};
std::array<unsigned char, 2 * SHA384_512_BLOCK_SIZE> m_block{}; std::array<unsigned char, 2 * SHA384_512_BLOCK_SIZE> m_block{};
@ -31,7 +34,7 @@ protected:
}; };
[[nodiscard]] std::string sha512(std::string_view input) noexcept; [[nodiscard]] std::string sha512(std::string_view input) noexcept;
#define SHA2_SHFR(x, n) (x >> n) #define SHA2_SHFR(x, n) (x >> n)
#define SHA2_ROTR(x, n) ((x >> n) | (x << ((sizeof(x) << 3) - n))) #define SHA2_ROTR(x, n) ((x >> n) | (x << ((sizeof(x) << 3) - n)))
#define SHA2_ROTL(x, n) ((x << n) | (x >> ((sizeof(x) << 3) - n))) #define SHA2_ROTL(x, n) ((x << n) | (x >> ((sizeof(x) << 3) - n)))
@ -70,5 +73,3 @@ protected:
| ((uint64) *((str) + 1) << 48) \ | ((uint64) *((str) + 1) << 48) \
| ((uint64) *((str) + 0) << 56); \ | ((uint64) *((str) + 0) << 56); \
} }
#endif