r727 - in trunk/code: client qcommon
DONOTREPLY at icculus.org
DONOTREPLY at icculus.org
Thu Apr 27 09:39:41 EDT 2006
Author: thilo
Date: 2006-04-27 09:39:41 -0400 (Thu, 27 Apr 2006)
New Revision: 727
Modified:
trunk/code/client/cl_main.c
trunk/code/qcommon/md4.c
trunk/code/qcommon/md5.c
trunk/code/qcommon/q_shared.h
Log:
- Introduced various new typedefs for windows platform (int32_t, int64_t, etc...)
- Applied md5 64-bit safety patch by Tony White.
Modified: trunk/code/client/cl_main.c
===================================================================
--- trunk/code/client/cl_main.c 2006-04-26 13:36:58 UTC (rev 726)
+++ trunk/code/client/cl_main.c 2006-04-27 13:39:41 UTC (rev 727)
@@ -2549,8 +2549,7 @@
Cvar_Set( "cl_running", "1" );
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" );
}
Modified: trunk/code/qcommon/md4.c
===================================================================
--- trunk/code/qcommon/md4.c 2006-04-26 13:36:58 UTC (rev 726)
+++ trunk/code/qcommon/md4.c 2006-04-27 13:39:41 UTC (rev 727)
@@ -30,21 +30,9 @@
#include "q_shared.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 {
- uint32 A, B, C, D;
- uint32 totalN;
+ uint32_t A, B, C, D;
+ uint32_t totalN;
};
@@ -58,23 +46,19 @@
#define F(X,Y,Z) (((X)&(Y)) | ((~(X))&(Z)))
#define G(X,Y,Z) (((X)&(Y)) | ((X)&(Z)) | ((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))))
-#endif
#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 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 */
-static void mdfour64(uint32 *M)
+static void mdfour64(uint32_t *M)
{
int j;
- uint32 AA, BB, CC, DD;
- uint32 X[16];
- uint32 A,B,C,D;
+ uint32_t AA, BB, CC, DD;
+ uint32_t X[16];
+ uint32_t A,B,C,D;
for (j=0;j<16;j++)
X[j] = M[j];
@@ -111,18 +95,13 @@
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++)
X[j] = 0;
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;
@@ -131,7 +110,7 @@
(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[1] = (x>>8)&0xFF;
@@ -152,8 +131,8 @@
static void mdfour_tail(byte *in, int n)
{
byte buf[128];
- uint32 M[16];
- uint32 b;
+ uint32_t M[16];
+ uint32_t b;
m->totalN += n;
@@ -178,7 +157,7 @@
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);
Modified: trunk/code/qcommon/md5.c
===================================================================
--- trunk/code/qcommon/md5.c 2006-04-26 13:36:58 UTC (rev 726)
+++ trunk/code/qcommon/md5.c 2006-04-27 13:39:41 UTC (rev 727)
@@ -18,8 +18,8 @@
#include "qcommon.h"
typedef struct MD5Context {
- unsigned long int buf[4];
- unsigned long int bits[2];
+ uint32_t buf[4];
+ uint32_t bits[2];
unsigned char in[64];
} MD5_CTX;
@@ -33,12 +33,12 @@
*/
static void byteReverse(unsigned char *buf, unsigned longs)
{
- unsigned long int t;
+ uint32_t t;
do {
- t = (unsigned long int)
+ t = (uint32_t)
((unsigned) buf[3] << 8 | buf[2]) << 16 |
((unsigned) buf[1] << 8 | buf[0]);
- *(unsigned long int *) buf = t;
+ *(uint32_t *) buf = t;
buf += 4;
} while (--longs);
}
@@ -75,10 +75,10 @@
* reflect the addition of 16 longwords of new data. MD5Update blocks
* the data and converts bytes into longwords for this routine.
*/
-static void MD5Transform(unsigned long int buf[4],
- unsigned long int const in[16])
+static void MD5Transform(uint32_t buf[4],
+ uint32_t const in[16])
{
- register unsigned long int a, b, c, d;
+ register uint32_t a, b, c, d;
a = buf[0];
b = buf[1];
@@ -166,12 +166,12 @@
static void MD5Update(struct MD5Context *ctx, unsigned char const *buf,
unsigned len)
{
- register unsigned long int t;
+ uint32_t t;
/* Update bitcount */
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] += len >> 29;
@@ -189,7 +189,7 @@
}
memcpy(p, buf, t);
byteReverse(ctx->in, 16);
- MD5Transform(ctx->buf, (unsigned long int *) ctx->in);
+ MD5Transform(ctx->buf, (uint32_t *) ctx->in);
buf += t;
len -= t;
}
@@ -198,7 +198,7 @@
while (len >= 64) {
memcpy(ctx->in, buf, 64);
byteReverse(ctx->in, 16);
- MD5Transform(ctx->buf, (unsigned long int *) ctx->in);
+ MD5Transform(ctx->buf, (uint32_t *) ctx->in);
buf += 64;
len -= 64;
}
@@ -215,7 +215,7 @@
*/
static void MD5Final(struct MD5Context *ctx, unsigned char *digest)
{
- unsigned long int count;
+ unsigned count;
unsigned char *p;
/* Compute number of bytes mod 64 */
@@ -234,7 +234,7 @@
/* Two lots of padding: Pad the first block to 64 bytes */
memset(p, 0, count);
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 */
memset(ctx->in, 0, 56);
@@ -245,15 +245,15 @@
byteReverse(ctx->in, 14);
/* Append length in bits and transform */
- ((unsigned long int *) ctx->in)[14] = ctx->bits[0];
- ((unsigned long int *) ctx->in)[15] = ctx->bits[1];
+ ((uint32_t *) ctx->in)[14] = ctx->bits[0];
+ ((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);
if (digest!=NULL)
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 */
}
Modified: trunk/code/qcommon/q_shared.h
===================================================================
--- trunk/code/qcommon/q_shared.h 2006-04-26 13:36:58 UTC (rev 726)
+++ trunk/code/qcommon/q_shared.h 2006-04-27 13:39:41 UTC (rev 727)
@@ -109,10 +109,19 @@
//=============================================================
#ifdef Q3_VM
-typedef int intptr_t;
+ typedef int intptr_t;
#else
# ifndef _MSC_VER
# 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
More information about the quake3-commits
mailing list