57 #ifndef Xrd_Big_Endian
58 void XrdCksCalcmd5::byteReverse(
unsigned char *buf,
unsigned longs) {}
61 void XrdCksCalcmd5::byteReverse(
unsigned char *buf,
unsigned longs)
64 do {t = (
unsigned int) ((
unsigned) buf[3] << 8 | buf[2]) << 16 |
65 ((
unsigned) buf[1] << 8 | buf[0]);
66 *(
unsigned int *) buf = t;
86 myContext.buf[0] = 0x67452301;
87 myContext.buf[1] = 0xefcdab89;
88 myContext.buf[2] = 0x98badcfe;
89 myContext.buf[3] = 0x10325476;
91 myContext.bits[0] = 0;
92 myContext.bits[1] = 0;
101 void XrdCksCalcmd5::MD5Update(
unsigned char const *buf,
unsigned int len)
107 t = myContext.bits[0];
108 if ((myContext.bits[0] = t + ((
unsigned int) len << 3)) < t)
113 myContext.bits[1] += len >> 29;
121 if (t) {
unsigned char *p = (
unsigned char *) myContext.in + t;
123 if (len < t) {memcpy(p, buf, len);
return;}
125 byteReverse(myContext.in, 16);
126 MD5Transform(myContext.buf, (
unsigned int *) myContext.in);
134 {memcpy(myContext.in, buf, 64);
135 byteReverse(myContext.in, 16);
136 MD5Transform(myContext.buf, (
unsigned int *) myContext.in);
143 memcpy(myContext.in, buf, len);
160 count = (myContext.bits[0] >> 3) & 0x3F;
165 p = myContext.in + count;
170 count = 64 - 1 - count;
175 {memset(p, 0, count);
176 byteReverse(myContext.in, 16);
177 MD5Transform(myContext.buf, (
unsigned int *) myContext.in);
178 memset(myContext.in, 0, 56);
179 }
else memset(p, 0, count - 8);
181 byteReverse(myContext.in, 14);
187 myContext.i64[7] = myContext.b64;
189 MD5Transform(myContext.buf, (
unsigned int *) myContext.in);
190 byteReverse((
unsigned char *) myContext.buf, 4);
194 memcpy(myDigest, myContext.buf, 16);
195 return (
char *)myDigest;
208 #define F1(x, y, z) (z ^ (x & (y ^ z)))
209 #define F2(x, y, z) F1(z, x, y)
210 #define F3(x, y, z) (x ^ y ^ z)
211 #define F4(x, y, z) (y ^ (x | ~z))
215 #define MD5STEP(f, w, x, y, z, data, s) \
216 ( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x )
222 void XrdCksCalcmd5::MD5Transform(
unsigned int buf[4],
unsigned int const in[16])
224 unsigned int a, b, c, d;
231 MD5STEP(
F1, a, b, c, d, in[0] + 0xd76aa478, 7);
232 MD5STEP(
F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
233 MD5STEP(
F1, c, d, a, b, in[2] + 0x242070db, 17);
234 MD5STEP(
F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
235 MD5STEP(
F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
236 MD5STEP(
F1, d, a, b, c, in[5] + 0x4787c62a, 12);
237 MD5STEP(
F1, c, d, a, b, in[6] + 0xa8304613, 17);
238 MD5STEP(
F1, b, c, d, a, in[7] + 0xfd469501, 22);
239 MD5STEP(
F1, a, b, c, d, in[8] + 0x698098d8, 7);
240 MD5STEP(
F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
241 MD5STEP(
F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
242 MD5STEP(
F1, b, c, d, a, in[11] + 0x895cd7be, 22);
243 MD5STEP(
F1, a, b, c, d, in[12] + 0x6b901122, 7);
244 MD5STEP(
F1, d, a, b, c, in[13] + 0xfd987193, 12);
245 MD5STEP(
F1, c, d, a, b, in[14] + 0xa679438e, 17);
246 MD5STEP(
F1, b, c, d, a, in[15] + 0x49b40821, 22);
248 MD5STEP(
F2, a, b, c, d, in[1] + 0xf61e2562, 5);
249 MD5STEP(
F2, d, a, b, c, in[6] + 0xc040b340, 9);
250 MD5STEP(
F2, c, d, a, b, in[11] + 0x265e5a51, 14);
251 MD5STEP(
F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
252 MD5STEP(
F2, a, b, c, d, in[5] + 0xd62f105d, 5);
253 MD5STEP(
F2, d, a, b, c, in[10] + 0x02441453, 9);
254 MD5STEP(
F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
255 MD5STEP(
F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
256 MD5STEP(
F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
257 MD5STEP(
F2, d, a, b, c, in[14] + 0xc33707d6, 9);
258 MD5STEP(
F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
259 MD5STEP(
F2, b, c, d, a, in[8] + 0x455a14ed, 20);
260 MD5STEP(
F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
261 MD5STEP(
F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
262 MD5STEP(
F2, c, d, a, b, in[7] + 0x676f02d9, 14);
263 MD5STEP(
F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
265 MD5STEP(
F3, a, b, c, d, in[5] + 0xfffa3942, 4);
266 MD5STEP(
F3, d, a, b, c, in[8] + 0x8771f681, 11);
267 MD5STEP(
F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
268 MD5STEP(
F3, b, c, d, a, in[14] + 0xfde5380c, 23);
269 MD5STEP(
F3, a, b, c, d, in[1] + 0xa4beea44, 4);
270 MD5STEP(
F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
271 MD5STEP(
F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
272 MD5STEP(
F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
273 MD5STEP(
F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
274 MD5STEP(
F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
275 MD5STEP(
F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
276 MD5STEP(
F3, b, c, d, a, in[6] + 0x04881d05, 23);
277 MD5STEP(
F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
278 MD5STEP(
F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
279 MD5STEP(
F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
280 MD5STEP(
F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
282 MD5STEP(
F4, a, b, c, d, in[0] + 0xf4292244, 6);
283 MD5STEP(
F4, d, a, b, c, in[7] + 0x432aff97, 10);
284 MD5STEP(
F4, c, d, a, b, in[14] + 0xab9423a7, 15);
285 MD5STEP(
F4, b, c, d, a, in[5] + 0xfc93a039, 21);
286 MD5STEP(
F4, a, b, c, d, in[12] + 0x655b59c3, 6);
287 MD5STEP(
F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
288 MD5STEP(
F4, c, d, a, b, in[10] + 0xffeff47d, 15);
289 MD5STEP(
F4, b, c, d, a, in[1] + 0x85845dd1, 21);
290 MD5STEP(
F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
291 MD5STEP(
F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
292 MD5STEP(
F4, c, d, a, b, in[6] + 0xa3014314, 15);
293 MD5STEP(
F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
294 MD5STEP(
F4, a, b, c, d, in[4] + 0xf7537e82, 6);
295 MD5STEP(
F4, d, a, b, c, in[11] + 0xbd3af235, 10);
296 MD5STEP(
F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
297 MD5STEP(
F4, b, c, d, a, in[9] + 0xeb86d391, 21);
#define MD5STEP(f, w, x, y, z, data, s)