summaryrefslogtreecommitdiff
blob: 6aa53ac7a78ff5f9cff0cc4ebbf18a6f931c79e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
diff -c1 -r sxid-4.0.5.orig/source/md5.c sxid-4.0.5/source/md5.c
*** sxid-4.0.5.orig/source/md5.c	1998-12-30 13:35:04.000000000 -0500
--- sxid-4.0.5/source/md5.c	2007-03-23 11:58:40.000000000 -0400
***************
*** 17,18 ****
--- 17,27 ----
  
+ /*
+  * This code contains adaptations of changes made in 1997 by
+  * Jim Kingdon of Cyclic Software so as not to require an integer
+  * type that is exactly 32 bits wide.  Jim Kingdon's changes
+  * were explicitly released to the public domain.  The adaptations
+  * were made by Ari Johnson in 2007 and are also hereby released
+  * into the public domain.
+  */
+ 
  #include <string.h>		/* for memcpy() */
***************
*** 20,44 ****
  
! #ifndef HIGHFIRST
! #define byteReverse(buf, len)	/* Nothing */
! #else
! void byteReverse (unsigned char *buf, unsigned longs);
! 
! #ifndef ASM_MD5
! /*
!  * Note: this code is harmless on little-endian machines.
!  */
! void byteReverse (unsigned char *buf, unsigned longs)
! {
!     uint32 t;
  
!     do {
! 	t = (uint32) ((unsigned) buf[3] << 8 | buf[2]) << 16 |
! 	    ((unsigned) buf[1] << 8 | buf[0]);
! 	*(uint32 *) buf = t;
! 	buf += 4;
!     }
!     while (--longs);
  }
- #endif
- #endif
  
--- 29,47 ----
  
! /* Little-endian byte-swapping routines.  Note that these do not
!    depend on the size of datatypes such as uint32, nor do they require
!    us to detect the endianness of the machine we are running on. */
! 
! static uint32
! getu32 (const unsigned char *addr) {
!     return (((((unsigned long)addr[3] << 8) | addr[2]) << 8)
! 		| addr[1]) << 8 | addr[0];
! }
  
! static void
! putu32 (uint32 data, unsigned char *addr) {
!     addr[0] = (unsigned char) data;
!     addr[1] = (unsigned char) (data >> 8);
!     addr[2] = (unsigned char) (data >> 16);
!     addr[3] = (unsigned char) (data >> 24);
  }
  
***************
*** 70,72 ****
      t = ctx->bits[0];
!     if ((ctx->bits[0] = t + ((uint32) len << 3)) < t)
  	ctx->bits[1]++;		/* Carry from low to high */
--- 73,75 ----
      t = ctx->bits[0];
!     if ((ctx->bits[0] = (t + ((uint32) len << 3)) & 0xffffffff) < t)
  	ctx->bits[1]++;		/* Carry from low to high */
***************
*** 79,81 ****
      if (t) {
! 	unsigned char *p = (unsigned char *) ctx->in + t;
  
--- 82,84 ----
      if (t) {
! 	unsigned char *p = ctx->in + t;
  
***************
*** 87,90 ****
  	memcpy (p, buf, t);
! 	byteReverse (ctx->in, 16);
! 	MD5Transform (ctx->buf, (uint32 *) ctx->in);
  	buf += t;
--- 90,92 ----
  	memcpy (p, buf, t);
! 	MD5Transform (ctx->buf, ctx->in);
  	buf += t;
***************
*** 96,99 ****
  	memcpy (ctx->in, buf, 64);
! 	byteReverse (ctx->in, 16);
! 	MD5Transform (ctx->buf, (uint32 *) ctx->in);
  	buf += 64;
--- 98,100 ----
  	memcpy (ctx->in, buf, 64);
! 	MD5Transform (ctx->buf, ctx->in);
  	buf += 64;
***************
*** 131,134 ****
  	memset (p, 0, count);
! 	byteReverse (ctx->in, 16);
! 	MD5Transform (ctx->buf, (uint32 *) ctx->in);
  
--- 132,134 ----
  	memset (p, 0, count);
! 	MD5Transform (ctx->buf, ctx->in);
  
***************
*** 140,150 ****
      }
-     byteReverse (ctx->in, 14);
  
      /* Append length in bits and transform */
!     ((uint32 *) ctx->in)[14] = ctx->bits[0];
!     ((uint32 *) ctx->in)[15] = ctx->bits[1];
  
!     MD5Transform (ctx->buf, (uint32 *) ctx->in);
!     byteReverse ((unsigned char *) ctx->buf, 4);
!     memcpy (digest, ctx->buf, 16);
      memset ((char *) ctx, 0, sizeof (ctx));	/* In case it's sensitive */
--- 140,151 ----
      }
  
      /* Append length in bits and transform */
!     putu32(ctx->bits[0], ctx->in + 56);
!     putu32(ctx->bits[1], ctx->in + 60);
  
!     MD5Transform (ctx->buf, ctx->in);
!     putu32(ctx->buf[0], digest);
!     putu32(ctx->buf[1], digest + 4);
!     putu32(ctx->buf[2], digest + 8);
!     putu32(ctx->buf[3], digest + 12);
      memset ((char *) ctx, 0, sizeof (ctx));	/* In case it's sensitive */
***************
*** 164,166 ****
  #define MD5STEP(f, w, x, y, z, data, s) \
! 	( w += f(x, y, z) + data,  w = w<<s | w>>(32-s),  w += x )
  
--- 165,167 ----
  #define MD5STEP(f, w, x, y, z, data, s) \
! 	( w += f(x, y, z) + data, w &= 0xffffffff, w = w<<s | w>>(32-s), w += x )
  
***************
*** 171,175 ****
   */
! void MD5Transform (uint32 buf[4], uint32 const in[16])
  {
      register uint32 a, b, c, d;
  
--- 172,181 ----
   */
! void MD5Transform (uint32 buf[4], const unsigned char inraw[64])
  {
      register uint32 a, b, c, d;
+     uint32 in[16];
+     int i;
+ 
+     for (i = 0; i < 16; ++i)
+ 	in[i] = getu32 (inraw + 4 * i);
  
diff -c1 -r sxid-4.0.5.orig/source/md5.h sxid-4.0.5/source/md5.h
*** sxid-4.0.5.orig/source/md5.h	1998-12-30 13:35:04.000000000 -0500
--- sxid-4.0.5/source/md5.h	2007-03-23 11:47:25.000000000 -0400
***************
*** 4,13 ****
  
- #ifdef __alpha
- typedef unsigned int uint32;
- 
- #else
  typedef unsigned long uint32;
  
- #endif
- 
  struct MD5Context {
--- 4,7 ----
***************
*** 22,29 ****
  void MD5Final (unsigned char digest[16], struct MD5Context *context);
! void MD5Transform (uint32 buf[4], uint32 const in[16]);
! 
! /*
!  * This is needed to make RSAREF happy on some MS-DOS compilers.
!  */
! typedef struct MD5Context MD5_CTX;
  
--- 16,18 ----
  void MD5Final (unsigned char digest[16], struct MD5Context *context);
! void MD5Transform (uint32 buf[4], const unsigned char in[64]);