- 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:
parent
c116695ea7
commit
235e2c215f
4 changed files with 40 additions and 53 deletions
|
@ -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 @@ typedef struct MD5Context {
|
|||
*/
|
||||
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 @@ static void MD5Init(struct MD5Context *ctx)
|
|||
* 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 MD5Transform(unsigned long int buf[4],
|
|||
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 @@ static void MD5Update(struct MD5Context *ctx, unsigned char const *buf,
|
|||
}
|
||||
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 @@ static void MD5Update(struct MD5Context *ctx, unsigned char const *buf,
|
|||
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 MD5Update(struct MD5Context *ctx, unsigned char const *buf,
|
|||
*/
|
||||
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 @@ static void MD5Final(struct MD5Context *ctx, unsigned char *digest)
|
|||
/* 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 @@ static void MD5Final(struct MD5Context *ctx, unsigned char *digest)
|
|||
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 */
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue