diff options
-rw-r--r-- | MPQCryptography.c | 101 | ||||
-rw-r--r-- | MPQCryptography.h | 32 | ||||
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | extract.c | 4 | ||||
-rw-r--r-- | hashtab.c | 5 | ||||
-rw-r--r-- | hashtab.h | 6 | ||||
-rw-r--r-- | lookupa.h | 6 | ||||
-rw-r--r-- | mpq-bios.c | 22 | ||||
-rw-r--r-- | mpq-bios.h | 6 | ||||
-rw-r--r-- | mpq-file.h | 6 | ||||
-rw-r--r-- | mpq-misc.h | 6 | ||||
-rw-r--r-- | mpqlib-stdint.h (renamed from stdint.h) | 6 | ||||
-rw-r--r-- | mpqlib.vcproj | 2 | ||||
-rw-r--r-- | recycle.c | 6 |
14 files changed, 32 insertions, 178 deletions
diff --git a/MPQCryptography.c b/MPQCryptography.c index 6c33e55..e18e279 100644 --- a/MPQCryptography.c +++ b/MPQCryptography.c @@ -9,48 +9,21 @@ /* * Ripped for mpqlib - all endinaness stuff has been killed. + * Also, all the unnecessary code has been ripped out. * Other than that, this is the exact same code. */ #include <assert.h> #include <string.h> -#include <zlib.h> - -#ifdef USE_SSL -#include <openssl/err.h> -#include <openssl/evp.h> -#include <openssl/md5.h> -#include <openssl/obj_mac.h> -#include <openssl/sha.h> -#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]; /****TODO****/ /* Re-implement various endianess fixes. */ -#ifdef USE_SSL -static void memrev(unsigned char *buf, size_t count) -{ - unsigned char *r; - - for (r = buf + count - 1; buf < r; buf++, r--) { - *buf ^= *r; - *r ^= *buf; - *buf ^= *r; - } -} -#endif - const uint32_t *__mpqlib_get_cryptography_table() { assert(crypt_table_initialized); @@ -82,18 +55,11 @@ void __mpqlib_init_cryptography() } } } - // Load up OpenSSL -#ifdef USE_SSL - OpenSSL_add_all_digests(); - OpenSSL_add_all_algorithms(); - OpenSSL_add_all_ciphers(); - ERR_load_crypto_strings(); -#endif } -void __mpqlib_encrypt(void *_data, uint32_t length, uint32_t key, bool disable_input_swapping) +void __mpqlib_encrypt(void *_data, uint32_t length, uint32_t key, char disable_input_swapping) { - char * data = (char *) _data; + char * data = (char *) _data; uint32_t *buffer32 = (uint32_t *) data; uint32_t seed = 0xEEEEEEEE; uint32_t ch; @@ -128,7 +94,7 @@ 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) +void __mpqlib_decrypt(void *_data, uint32_t length, uint32_t key, char disable_output_swapping) { char * data = (char *) _data; uint32_t *buffer32 = (uint32_t *) data; @@ -211,62 +177,3 @@ uint32_t __mpqlib_hash_data(const char *data, uint32_t length, uint32_t type) return seed1; } - -void __mpqlib_crc32(const unsigned char *buffer, uint32_t length, uint32_t * crc, uint32_t flags) -{ - uint32_t local_crc = 0; - const uint32_t *crc_table = (uint32_t *) get_crc_table(); - const unsigned char *buffer_end = buffer + length; - - if (crc) - local_crc = *crc; - if (flags & __MPQLIB_CRC_INIT) - local_crc = 0xFFFFFFFF; - - if (flags & __MPQLIB_CRC_UPDATE) { - while (buffer < buffer_end) { - local_crc = ((local_crc >> 8) & 0x00FFFFFF) ^ crc_table[(local_crc ^ *buffer) & 0xFF]; - buffer++; - } - } - - if (flags & __MPQLIB_CRC_FINALIZE) - local_crc = local_crc ^ 0xFFFFFFFF; - if (crc) - *crc = local_crc; -} - -#ifdef USE_SSL -int __mpqlib_verify_weak_signature(RSA * public_key, const unsigned char *signature, const unsigned char *digest) -{ - unsigned char reversed_signature[__MPQLIB_WEAK_SIGNATURE_SIZE]; - - memcpy(reversed_signature, signature + 8, __MPQLIB_WEAK_SIGNATURE_SIZE); - memrev(reversed_signature, __MPQLIB_WEAK_SIGNATURE_SIZE); - - return RSA_verify(NID_md5, digest, MD5_DIGEST_LENGTH, reversed_signature, __MPQLIB_WEAK_SIGNATURE_SIZE, public_key); -} - -int __mpqlib_verify_strong_signature(RSA * public_key, const unsigned char *signature, const unsigned char *digest) -{ - unsigned char reversed_signature[__MPQLIB_STRONG_SIGNATURE_SIZE]; - - memcpy(reversed_signature, signature + 4, __MPQLIB_STRONG_SIGNATURE_SIZE); - memrev(reversed_signature, __MPQLIB_STRONG_SIGNATURE_SIZE); - - unsigned char real_digest[__MPQLIB_STRONG_SIGNATURE_SIZE]; - - memset(real_digest, 0xbb, sizeof(real_digest)); - real_digest[0] = 0x0b; - - uint32_t digest_offset = sizeof(real_digest) - SHA_DIGEST_LENGTH; - - memcpy(real_digest + digest_offset, digest, SHA_DIGEST_LENGTH); - memrev(real_digest + digest_offset, SHA_DIGEST_LENGTH); - - RSA_public_decrypt(__MPQLIB_STRONG_SIGNATURE_SIZE, reversed_signature, reversed_signature, public_key, RSA_NO_PADDING); - unsigned long error = ERR_get_error(); - - return (!error && memcmp(reversed_signature, real_digest, __MPQLIB_STRONG_SIGNATURE_SIZE) == 0); -} -#endif diff --git a/MPQCryptography.h b/MPQCryptography.h index 01aa418..53bac82 100644 --- a/MPQCryptography.h +++ b/MPQCryptography.h @@ -7,50 +7,24 @@ * */ -#ifdef WIN32 -#include "stdint.h" -#include <stdlib.h> -#define bool char -#else -#include <stdbool.h> -#include <stdint.h> -#include <openssl/rsa.h> -#endif +#include "mpqlib-stdint.h" #if defined(__cplusplus) extern "C" { #endif -#if !defined(__MPQLIB_WEAK_SIGNATURE_SIZE) -#define __MPQLIB_WEAK_SIGNATURE_SIZE 64 -#endif - -#if !defined(__MPQLIB_STRONG_SIGNATURE_SIZE) -#define __MPQLIB_STRONG_SIGNATURE_SIZE 256 -#endif - void __mpqlib_init_cryptography(void); const uint32_t *__mpqlib_get_cryptography_table(void); void __mpqlib_encrypt(void *data, uint32_t length, uint32_t key, - bool disable_input_swapping); + char disable_input_swapping); void __mpqlib_decrypt(void *data, uint32_t length, uint32_t key, - bool disable_output_swapping); + char disable_output_swapping); 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); -#define __MPQLIB_CRC_INIT 0x1 -#define __MPQLIB_CRC_UPDATE 0x2 -#define __MPQLIB_CRC_FINALIZE 0x4 - void __mpqlib_crc32(const unsigned char *buffer, uint32_t length, uint32_t * crc, uint32_t flags); - -#ifdef USE_SSL - int __mpqlib_verify_weak_signature(RSA * public_key, const unsigned char *signature, const unsigned char *digest); - int __mpqlib_verify_strong_signature(RSA * public_key, const unsigned char *signature, const unsigned char *digest); -#endif - #if defined(__cplusplus) } #endif @@ -3,7 +3,7 @@ LD = gcc AR = ar rcs CPPFLAGS = -g -Wall -Werror -D_FILE_OFFSET_BITS=64 -I. -LDFLAGS = -g +LDFLAGS = -g -lz SOURCE_LIST = \ MPQCryptography.c \ @@ -1242,7 +1242,7 @@ static void huff_init_tree(struct huffman_tree *ht, struct huffman_tree_item *hi /* * Compression structure (size: 12596 bytes on x86-32) */ -#ifdef WIN32 +#ifdef _MSC_VER #pragma pack(1) #endif typedef struct { @@ -1276,7 +1276,7 @@ typedef struct { unsigned char clen_bits[0x10]; /* 3104 - Number of valid bits for copied block */ unsigned short len_base[0x10]; /* 3114 - Buffer for */ } -#ifndef WIN32 +#ifndef _MSC_VER __attribute__ ((packed)) #endif pkzip_data_cmp; @@ -28,11 +28,6 @@ This implements a hash table. -------------------------------------------------------------------- */ -#ifdef WIN32 -#include "stdint.h" -#else -#include <stdint.h> -#endif #include <memory.h> #include "lookupa.h" @@ -31,11 +31,7 @@ This implements a hash table. #ifndef HASHTAB #define HASHTAB -#ifdef WIN32 -#include "stdint.h" -#else -#include <stdint.h> -#endif +#include "mpqlib-stdint.h" #include <stdlib.h> /* PRIVATE TYPES AND DEFINITIONS */ @@ -10,11 +10,7 @@ Source is http://burtleburtle.net/bob/c/lookupa.h #ifndef LOOKUPA #define LOOKUPA -#ifdef WIN32 -#include "stdint.h" -#else -#include <stdint.h> -#endif +#include "mpqlib-stdint.h" #define CHECKSTATE 8 #define hashsize(n) ((uint32_t)1<<(n)) @@ -1,10 +1,13 @@ #define _LARGEFILE64_SOURCE -#ifdef WIN32 #include <stdio.h> +#ifdef WIN32 #include <io.h> #include <sys/types.h> #define lseek64 _lseeki64 +#define O_RDONLY _O_RDONLY +#define O_BINARY _O_BINARY +#define O_LARGEFILE 0 #else #include <unistd.h> #endif @@ -25,10 +28,9 @@ /* * MPQ header. */ -#ifdef WIN32 +#ifdef _MSC_VER #pragma pack(1) #endif - typedef struct { /* basic version of the header. */ char magic[4]; @@ -47,7 +49,7 @@ typedef struct { uint16_t hash_table_offset_high; uint16_t block_table_offset_high; } -#ifndef WIN32 +#ifndef _MSC_VER __attribute__ ((packed)) #endif mpq_header_t; @@ -63,7 +65,7 @@ typedef struct { uint16_t platform; uint32_t file_block_index; } -#ifndef WIN32 +#ifndef _MSC_VER __attribute__ ((packed)) #endif mpq_hash_t; @@ -78,7 +80,7 @@ typedef struct { uint32_t file_size; uint32_t flags; } -#ifndef WIN32 +#ifndef _MSC_VER __attribute__ ((packed)) #endif mpq_block_t; @@ -104,7 +106,7 @@ typedef struct { } block_t; struct mpq_archive_t { - int fd; + int fd; int closeit; uint32_t header_size; @@ -131,11 +133,7 @@ struct mpq_archive_t * mpqlib_open_archive(const char * fname) { int fd; struct mpq_archive_t * r; -#ifdef WIN32 - if ((fd = open(fname, _O_RDONLY | _O_BINARY)) == -1) { -#else - if ((fd = open(fname, O_RDONLY | O_LARGEFILE | O_BINARY)) == -1) { -#endif + if ((fd = open(fname, O_RDONLY | O_LARGEFILE | O_BINARY)) == -1) { __mpqlib_errno = MPQLIB_ERROR_OPEN; return NULL; } @@ -1,11 +1,7 @@ #ifndef __MPQ_BIOS_H__ #define __MPQ_BIOS_H__ -#ifdef WIN32 -#include "stdint.h" -#else -#include <stdint.h> -#endif +#include "mpqlib-stdint.h" struct mpq_archive_t; @@ -1,11 +1,7 @@ #ifndef __MPQ_FILE_H__ #define __MPQ_FILE_H__ -#ifdef WIN32 -#include "stdint.h" -#else -#include <stdint.h> -#endif +#include "mpqlib-stdint.h" struct mpq_file_t; enum mpqlib_file_seek_t { @@ -1,11 +1,7 @@ #ifndef __MPQ_MISC_H__ #define __MPQ_MISC_H__ -#ifdef WIN32 -typedef unsigned long int uint32_t; -#else -#include <stdint.h> -#endif +#include "mpqlib-stdint.h" #ifdef __cplusplus extern "C" { diff --git a/stdint.h b/mpqlib-stdint.h index dd9c546..1dc4e2d 100644 --- a/stdint.h +++ b/mpqlib-stdint.h @@ -1,10 +1,14 @@ #ifndef __STD_INT_H_ #define __STD_INT_H_ +#ifdef WIN32 typedef unsigned char uint8_t; typedef unsigned short int uint16_t; typedef signed long int int32_t; typedef unsigned long int uint32_t; typedef unsigned __int64 uint64_t; +#else +#include <stdint.h> +#endif -#endif
\ No newline at end of file +#endif diff --git a/mpqlib.vcproj b/mpqlib.vcproj index c6a6ff4..ad7a08b 100644 --- a/mpqlib.vcproj +++ b/mpqlib.vcproj @@ -243,7 +243,7 @@ > </File> <File - RelativePath=".\stdint.h" + RelativePath=".\mpqlib-stdint.h" > </File> </Filter> @@ -13,11 +13,7 @@ This also decreases memory fragmentation, and freeing structures -------------------------------------------------------------------- */ -#ifdef WIN32 -#include "stdint.h" -#else -#include <stdint.h> -#endif +#include "mpqlib-stdint.h" #include <stdio.h> #include <memory.h> #include "recycle.h" |