From 8522e44467ebcac54201def2c6583639e74e9e24 Mon Sep 17 00:00:00 2001 From: yazoo Date: Tue, 29 Jan 2008 07:43:06 +0000 Subject: Portage win32 --- MPQCryptography.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'MPQCryptography.c') diff --git a/MPQCryptography.c b/MPQCryptography.c index 9791c0a..6c33e55 100644 --- a/MPQCryptography.c +++ b/MPQCryptography.c @@ -25,7 +25,12 @@ #endif #include "MPQCryptography.h" + +#ifdef WIN32 +#include "stdint.h" +#else #include "inttypes.h" +#endif static int crypt_table_initialized = 0; static uint32_t crypt_table[0x500]; @@ -88,13 +93,13 @@ void __mpqlib_init_cryptography() void __mpqlib_encrypt(void *_data, uint32_t length, uint32_t key, bool disable_input_swapping) { - char * data = (char *) _data; - assert(crypt_table_initialized); - assert(data); - + char * data = (char *) _data; uint32_t *buffer32 = (uint32_t *) data; uint32_t seed = 0xEEEEEEEE; uint32_t ch; + + assert(crypt_table_initialized); + assert(data); // Round to 4 bytes length = length / 4; @@ -126,13 +131,13 @@ void __mpqlib_encrypt(void *_data, uint32_t length, uint32_t key, bool disable_i void __mpqlib_decrypt(void *_data, uint32_t length, uint32_t key, bool disable_output_swapping) { char * data = (char *) _data; - assert(crypt_table_initialized); - assert(data); - uint32_t *buffer32 = (uint32_t *) data; uint32_t seed = 0xEEEEEEEE; uint32_t ch; + assert(crypt_table_initialized); + assert(data); + // Round to 4 bytes length = length / 4; @@ -166,14 +171,14 @@ void __mpqlib_decrypt(void *_data, uint32_t length, uint32_t key, bool disable_o uint32_t __mpqlib_hash_cstring(const char *string, uint32_t type) { - assert(crypt_table_initialized); - assert(string); - uint32_t seed1 = 0x7FED7FED; uint32_t seed2 = 0xEEEEEEEE; uint32_t shifted_type = (type << 8); int32_t ch; + assert(crypt_table_initialized); + assert(string); + while (*string != 0) { ch = *string++; if (ch > 0x60 && ch < 0x7b) @@ -188,14 +193,14 @@ uint32_t __mpqlib_hash_cstring(const char *string, uint32_t type) uint32_t __mpqlib_hash_data(const char *data, uint32_t length, uint32_t type) { - assert(crypt_table_initialized); - assert(data); - uint32_t seed1 = 0x7FED7FED; uint32_t seed2 = 0xEEEEEEEE; uint32_t shifted_type = (type << 8); int32_t ch; + assert(crypt_table_initialized); + assert(data); + while (length > 0) { ch = *data++; -- cgit v1.2.3