clean up crypto packages

This commit is contained in:
Sky Johnson 2025-09-06 21:11:34 -05:00
parent c97592e485
commit 6ee4389b57
5 changed files with 55 additions and 59 deletions

View File

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

View File

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

View File

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

View File

@ -2,7 +2,6 @@
// Licensed under GPL v3
#include "sha512.h"
#include <algorithm>
#include <cstdio>
#include <cstring>
@ -158,7 +157,7 @@ std::string sha512(std::string_view input) noexcept
ctx.final(digest.data());
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]);
}
return std::string{buf.data()};

View File

@ -1,3 +1,6 @@
// Copyright (C) 2007-2025 EQ2EMulator
// Licensed under GPL v3
#pragma once
#include <array>
@ -21,9 +24,9 @@ protected:
using uint64 = std::uint64_t;
static const std::array<uint64, 80> sha512_k;
void transform(const unsigned char* message, unsigned int block_nb) noexcept;
unsigned int m_tot_len{};
unsigned int m_len{};
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;
#define SHA2_SHFR(x, n) (x >> 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)))
@ -70,5 +73,3 @@ protected:
| ((uint64) *((str) + 1) << 48) \
| ((uint64) *((str) + 0) << 56); \
}
#endif