- Introduced various new typedefs for windows platform (int32_t, int64_t, etc...)

- Applied md5 64-bit safety patch by Tony White.
This commit is contained in:
Thilo Schulz 2006-04-27 13:39:41 +00:00
parent c116695ea7
commit 235e2c215f
4 changed files with 40 additions and 53 deletions

View file

@ -2549,8 +2549,7 @@ void CL_Init( void ) {
Cvar_Set( "cl_running", "1" ); Cvar_Set( "cl_running", "1" );
CL_GenerateQKey(); CL_GenerateQKey();
// Uncomment this once md5.c has been made 64 bit-safe. Cvar_Get("cl_guid", Com_MD5File(QKEY_FILE, 0), CVAR_USERINFO | CVAR_ROM);
// Cvar_Get("cl_guid", Com_MD5File(QKEY_FILE, 0), CVAR_USERINFO | CVAR_ROM);
Com_Printf( "----- Client Initialization Complete -----\n" ); Com_Printf( "----- Client Initialization Complete -----\n" );
} }

View file

@ -30,21 +30,9 @@
#include "q_shared.h" #include "q_shared.h"
#include "qcommon.h" #include "qcommon.h"
#ifndef int32
#define int32 int
#endif
#if SIZEOF_INT > 4
#define LARGE_INT32
#endif
#ifndef uint32
#define uint32 unsigned int32
#endif
struct mdfour { struct mdfour {
uint32 A, B, C, D; uint32_t A, B, C, D;
uint32 totalN; uint32_t totalN;
}; };
@ -58,23 +46,19 @@ static struct mdfour *m;
#define F(X,Y,Z) (((X)&(Y)) | ((~(X))&(Z))) #define F(X,Y,Z) (((X)&(Y)) | ((~(X))&(Z)))
#define G(X,Y,Z) (((X)&(Y)) | ((X)&(Z)) | ((Y)&(Z))) #define G(X,Y,Z) (((X)&(Y)) | ((X)&(Z)) | ((Y)&(Z)))
#define H(X,Y,Z) ((X)^(Y)^(Z)) #define H(X,Y,Z) ((X)^(Y)^(Z))
#ifdef LARGE_INT32
#define lshift(x,s) ((((x)<<(s))&0xFFFFFFFF) | (((x)>>(32-(s)))&0xFFFFFFFF))
#else
#define lshift(x,s) (((x)<<(s)) | ((x)>>(32-(s)))) #define lshift(x,s) (((x)<<(s)) | ((x)>>(32-(s))))
#endif
#define ROUND1(a,b,c,d,k,s) a = lshift(a + F(b,c,d) + X[k], s) #define ROUND1(a,b,c,d,k,s) a = lshift(a + F(b,c,d) + X[k], s)
#define ROUND2(a,b,c,d,k,s) a = lshift(a + G(b,c,d) + X[k] + 0x5A827999,s) #define ROUND2(a,b,c,d,k,s) a = lshift(a + G(b,c,d) + X[k] + 0x5A827999,s)
#define ROUND3(a,b,c,d,k,s) a = lshift(a + H(b,c,d) + X[k] + 0x6ED9EBA1,s) #define ROUND3(a,b,c,d,k,s) a = lshift(a + H(b,c,d) + X[k] + 0x6ED9EBA1,s)
/* this applies md4 to 64 byte chunks */ /* this applies md4 to 64 byte chunks */
static void mdfour64(uint32 *M) static void mdfour64(uint32_t *M)
{ {
int j; int j;
uint32 AA, BB, CC, DD; uint32_t AA, BB, CC, DD;
uint32 X[16]; uint32_t X[16];
uint32 A,B,C,D; uint32_t A,B,C,D;
for (j=0;j<16;j++) for (j=0;j<16;j++)
X[j] = M[j]; X[j] = M[j];
@ -111,18 +95,13 @@ static void mdfour64(uint32 *M)
A += AA; B += BB; C += CC; D += DD; A += AA; B += BB; C += CC; D += DD;
#ifdef LARGE_INT32
A &= 0xFFFFFFFF; B &= 0xFFFFFFFF;
C &= 0xFFFFFFFF; D &= 0xFFFFFFFF;
#endif
for (j=0;j<16;j++) for (j=0;j<16;j++)
X[j] = 0; X[j] = 0;
m->A = A; m->B = B; m->C = C; m->D = D; m->A = A; m->B = B; m->C = C; m->D = D;
} }
static void copy64(uint32 *M, byte *in) static void copy64(uint32_t *M, byte *in)
{ {
int i; int i;
@ -131,7 +110,7 @@ static void copy64(uint32 *M, byte *in)
(in[i*4+1]<<8) | (in[i*4+0]<<0); (in[i*4+1]<<8) | (in[i*4+0]<<0);
} }
static void copy4(byte *out,uint32 x) static void copy4(byte *out,uint32_t x)
{ {
out[0] = x&0xFF; out[0] = x&0xFF;
out[1] = (x>>8)&0xFF; out[1] = (x>>8)&0xFF;
@ -152,8 +131,8 @@ void mdfour_begin(struct mdfour *md)
static void mdfour_tail(byte *in, int n) static void mdfour_tail(byte *in, int n)
{ {
byte buf[128]; byte buf[128];
uint32 M[16]; uint32_t M[16];
uint32 b; uint32_t b;
m->totalN += n; m->totalN += n;
@ -178,7 +157,7 @@ static void mdfour_tail(byte *in, int n)
static void mdfour_update(struct mdfour *md, byte *in, int n) static void mdfour_update(struct mdfour *md, byte *in, int n)
{ {
uint32 M[16]; uint32_t M[16];
if (n == 0) mdfour_tail(in, n); if (n == 0) mdfour_tail(in, n);

View file

@ -18,8 +18,8 @@
#include "qcommon.h" #include "qcommon.h"
typedef struct MD5Context { typedef struct MD5Context {
unsigned long int buf[4]; uint32_t buf[4];
unsigned long int bits[2]; uint32_t bits[2];
unsigned char in[64]; unsigned char in[64];
} MD5_CTX; } MD5_CTX;
@ -33,12 +33,12 @@ typedef struct MD5Context {
*/ */
static void byteReverse(unsigned char *buf, unsigned longs) static void byteReverse(unsigned char *buf, unsigned longs)
{ {
unsigned long int t; uint32_t t;
do { do {
t = (unsigned long int) t = (uint32_t)
((unsigned) buf[3] << 8 | buf[2]) << 16 | ((unsigned) buf[3] << 8 | buf[2]) << 16 |
((unsigned) buf[1] << 8 | buf[0]); ((unsigned) buf[1] << 8 | buf[0]);
*(unsigned long int *) buf = t; *(uint32_t *) buf = t;
buf += 4; buf += 4;
} while (--longs); } while (--longs);
} }
@ -75,10 +75,10 @@ static void MD5Init(struct MD5Context *ctx)
* reflect the addition of 16 longwords of new data. MD5Update blocks * reflect the addition of 16 longwords of new data. MD5Update blocks
* the data and converts bytes into longwords for this routine. * the data and converts bytes into longwords for this routine.
*/ */
static void MD5Transform(unsigned long int buf[4], static void MD5Transform(uint32_t buf[4],
unsigned long int const in[16]) uint32_t const in[16])
{ {
register unsigned long int a, b, c, d; register uint32_t a, b, c, d;
a = buf[0]; a = buf[0];
b = buf[1]; b = buf[1];
@ -166,12 +166,12 @@ static void MD5Transform(unsigned long int buf[4],
static void MD5Update(struct MD5Context *ctx, unsigned char const *buf, static void MD5Update(struct MD5Context *ctx, unsigned char const *buf,
unsigned len) unsigned len)
{ {
register unsigned long int t; uint32_t t;
/* Update bitcount */ /* Update bitcount */
t = ctx->bits[0]; t = ctx->bits[0];
if ((ctx->bits[0] = t + ((unsigned long int) len << 3)) < t) if ((ctx->bits[0] = t + ((uint32_t) len << 3)) < t)
ctx->bits[1]++; /* Carry from low to high */ ctx->bits[1]++; /* Carry from low to high */
ctx->bits[1] += len >> 29; ctx->bits[1] += len >> 29;
@ -189,7 +189,7 @@ static void MD5Update(struct MD5Context *ctx, unsigned char const *buf,
} }
memcpy(p, buf, t); memcpy(p, buf, t);
byteReverse(ctx->in, 16); byteReverse(ctx->in, 16);
MD5Transform(ctx->buf, (unsigned long int *) ctx->in); MD5Transform(ctx->buf, (uint32_t *) ctx->in);
buf += t; buf += t;
len -= t; len -= t;
} }
@ -198,7 +198,7 @@ static void MD5Update(struct MD5Context *ctx, unsigned char const *buf,
while (len >= 64) { while (len >= 64) {
memcpy(ctx->in, buf, 64); memcpy(ctx->in, buf, 64);
byteReverse(ctx->in, 16); byteReverse(ctx->in, 16);
MD5Transform(ctx->buf, (unsigned long int *) ctx->in); MD5Transform(ctx->buf, (uint32_t *) ctx->in);
buf += 64; buf += 64;
len -= 64; len -= 64;
} }
@ -215,7 +215,7 @@ static void MD5Update(struct MD5Context *ctx, unsigned char const *buf,
*/ */
static void MD5Final(struct MD5Context *ctx, unsigned char *digest) static void MD5Final(struct MD5Context *ctx, unsigned char *digest)
{ {
unsigned long int count; unsigned count;
unsigned char *p; unsigned char *p;
/* Compute number of bytes mod 64 */ /* Compute number of bytes mod 64 */
@ -234,7 +234,7 @@ static void MD5Final(struct MD5Context *ctx, unsigned char *digest)
/* Two lots of padding: Pad the first block to 64 bytes */ /* Two lots of padding: Pad the first block to 64 bytes */
memset(p, 0, count); memset(p, 0, count);
byteReverse(ctx->in, 16); byteReverse(ctx->in, 16);
MD5Transform(ctx->buf, (unsigned long int *) ctx->in); MD5Transform(ctx->buf, (uint32_t *) ctx->in);
/* Now fill the next block with 56 bytes */ /* Now fill the next block with 56 bytes */
memset(ctx->in, 0, 56); memset(ctx->in, 0, 56);
@ -245,15 +245,15 @@ static void MD5Final(struct MD5Context *ctx, unsigned char *digest)
byteReverse(ctx->in, 14); byteReverse(ctx->in, 14);
/* Append length in bits and transform */ /* Append length in bits and transform */
((unsigned long int *) ctx->in)[14] = ctx->bits[0]; ((uint32_t *) ctx->in)[14] = ctx->bits[0];
((unsigned long int *) ctx->in)[15] = ctx->bits[1]; ((uint32_t *) ctx->in)[15] = ctx->bits[1];
MD5Transform(ctx->buf, (unsigned long int *) ctx->in); MD5Transform(ctx->buf, (uint32_t *) ctx->in);
byteReverse((unsigned char *) ctx->buf, 4); byteReverse((unsigned char *) ctx->buf, 4);
if (digest!=NULL) if (digest!=NULL)
memcpy(digest, ctx->buf, 16); memcpy(digest, ctx->buf, 16);
//memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */ memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
} }

View file

@ -109,10 +109,19 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//============================================================= //=============================================================
#ifdef Q3_VM #ifdef Q3_VM
typedef int intptr_t; typedef int intptr_t;
#else #else
# ifndef _MSC_VER # ifndef _MSC_VER
# include <stdint.h> # include <stdint.h>
# else
typedef __int64 int64_t;
typedef __int32 int32_t;
typedef __int16 int16_t;
typedef __int8 int8_t;
typedef unsigned __int64 uint64_t;
typedef unsigned __int32 uint32_t;
typedef unsigned __int16 uint16_t;
typedef unsigned __int8 uint8_t;
# endif # endif
#endif #endif