1
From 30361fa5f3266c0f088bbc89eb06dddbd032fc54 Mon Sep 17 00:00:00 2001
2
From: =?utf-8?q?Diego=20Elio=20'Flameeyes'=20Petten=C3=B2?= <flameeyes@gmail.com>
3
Date: Wed, 7 Apr 2010 15:58:04 +0200
4
Subject: [PATCH] Fix md5 code under 64-bit platforms.
6
The code was previously singling out the Alpha platform as 64-bit, but
7
that's definitely not the only platform where unsigned long is 64-bit
10
This change actually relies on C89 standard integers (uint32_t) so that
11
there is no more risk of getting it wrong.
13
src/md5.c | 28 ++++++++++++++--------------
14
src/md5.h | 10 +++-------
15
2 files changed, 17 insertions(+), 21 deletions(-)
17
diff --git a/src/md5.c b/src/md5.c
18
index 3b51e76..df24f16 100644
22
#include <string.h> /* for memcpy() */
25
-static void MD5Transform(uint32 buf[4], uint32 const in[16]);
26
+static void MD5Transform(uint32_t buf[4], uint32_t const in[16]);
29
#define byteReverse(buf, len) /* Nothing */
30
@@ -30,11 +30,11 @@ void byteReverse(unsigned char *buf, unsigned longs);
32
void byteReverse(unsigned char *buf, unsigned longs)
37
- t = (uint32) ((unsigned) buf[3] << 8 | buf[2]) << 16 |
38
+ t = (uint32_t) ((unsigned) buf[3] << 8 | buf[2]) << 16 |
39
((unsigned) buf[1] << 8 | buf[0]);
40
- *(uint32 *) buf = t;
41
+ *(uint32_t *) buf = t;
45
@@ -62,12 +62,12 @@ void MD5Init(struct MD5Context *ctx)
47
void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
55
- if ((ctx->bits[0] = t + ((uint32) len << 3)) < t)
56
+ if ((ctx->bits[0] = t + ((uint32_t) len << 3)) < t)
57
ctx->bits[1]++; /* Carry from low to high */
58
ctx->bits[1] += len >> 29;
60
@@ -85,7 +85,7 @@ void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
63
byteReverse(ctx->in, 16);
64
- MD5Transform(ctx->buf, (uint32 *) ctx->in);
65
+ MD5Transform(ctx->buf, (uint32_t *) ctx->in);
69
@@ -94,7 +94,7 @@ void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
71
memcpy(ctx->in, buf, 64);
72
byteReverse(ctx->in, 16);
73
- MD5Transform(ctx->buf, (uint32 *) ctx->in);
74
+ MD5Transform(ctx->buf, (uint32_t *) ctx->in);
78
@@ -129,7 +129,7 @@ void MD5Final(unsigned char *digest, struct MD5Context *ctx)
79
/* Two lots of padding: Pad the first block to 64 bytes */
81
byteReverse(ctx->in, 16);
82
- MD5Transform(ctx->buf, (uint32 *) ctx->in);
83
+ MD5Transform(ctx->buf, (uint32_t *) ctx->in);
85
/* Now fill the next block with 56 bytes */
86
memset(ctx->in, 0, 56);
87
@@ -140,10 +140,10 @@ void MD5Final(unsigned char *digest, struct MD5Context *ctx)
88
byteReverse(ctx->in, 14);
90
/* Append length in bits and transform */
91
- ((uint32 *) ctx->in)[14] = ctx->bits[0];
92
- ((uint32 *) ctx->in)[15] = ctx->bits[1];
93
+ ((uint32_t *) ctx->in)[14] = ctx->bits[0];
94
+ ((uint32_t *) ctx->in)[15] = ctx->bits[1];
96
- MD5Transform(ctx->buf, (uint32 *) ctx->in);
97
+ MD5Transform(ctx->buf, (uint32_t *) ctx->in);
98
byteReverse((unsigned char *) ctx->buf, 4);
99
memcpy(digest, ctx->buf, 16);
100
memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
101
@@ -173,9 +173,9 @@ void MD5Final(unsigned char *digest, struct MD5Context *ctx)
102
* reflect the addition of 16 longwords of new data. MD5Update blocks
103
* the data and converts bytes into longwords for this routine.
105
-static void MD5Transform(uint32 buf[4], uint32 const in[16])
106
+static void MD5Transform(uint32_t buf[4], uint32_t const in[16])
108
- register uint32 a, b, c, d;
109
+ register uint32_t a, b, c, d;
113
diff --git a/src/md5.h b/src/md5.h
114
index 6d8d047..a8a952f 100644
122
-typedef unsigned int uint32;
124
-typedef unsigned long uint32;
133
unsigned char in[64];