73 uint4 input_index, buffer_index;
77 std::cerr <<
"MD5::update: Can't update a finalized digest!" << std::endl;
82 buffer_index = (
unsigned int)((
count[0] >> 3) & 0x3F);
85 if ( (
count[0] += ((
uint4) input_length << 3))<((
uint4) input_length << 3) )
91 buffer_space = 64 - buffer_index;
94 if (input_length >= buffer_space) {
100 for (input_index = buffer_space; input_index + 63 < input_length;
111 memcpy(
buffer+buffer_index, input+input_index, input_length-input_index);
121 unsigned char buffer[1024];
126 len=fread(buffer, 1, 1024, file);
147 unsigned char buffer[1024];
150 while (stream.good()){
151 stream.read((
char*)buffer, 1024);
168 unsigned char buffer[1024];
171 while (stream.good()){
172 stream.read((
char*)buffer, 1024);
190 unsigned char bits[8];
191 unsigned int index, padLen;
192 static uint1 PADDING[64]={
193 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
194 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
195 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
199 std::cerr <<
"MD5::finalize: Already finalized this digest!" << std::endl;
208 padLen = (index < 56) ? (56 - index) : (120 - index);
260 std::cerr <<
"MD5::raw_digest: Can't get digest if you haven't "<<
261 "finalized the digest!" << std::endl;
262 return ( (
unsigned char*)
"");
274 char *s=
new char[33];
277 std::cerr <<
"MD5::hex_digest: Can't get digest if you haven't "<<
278 "finalized the digest!" << std::endl;
283 sprintf(s+i*2,
"%02x",
digest[i]);
305 state[0] = 0x67452301;
306 state[1] = 0xefcdab89;
307 state[2] = 0x98badcfe;
308 state[3] = 0x10325476;
347 FF (a, b, c, d, x[ 0],
S11, 0xd76aa478);
348 FF (d, a, b, c, x[ 1],
S12, 0xe8c7b756);
349 FF (c, d, a, b, x[ 2],
S13, 0x242070db);
350 FF (b, c, d, a, x[ 3],
S14, 0xc1bdceee);
351 FF (a, b, c, d, x[ 4],
S11, 0xf57c0faf);
352 FF (d, a, b, c, x[ 5],
S12, 0x4787c62a);
353 FF (c, d, a, b, x[ 6],
S13, 0xa8304613);
354 FF (b, c, d, a, x[ 7],
S14, 0xfd469501);
355 FF (a, b, c, d, x[ 8],
S11, 0x698098d8);
356 FF (d, a, b, c, x[ 9],
S12, 0x8b44f7af);
357 FF (c, d, a, b, x[10],
S13, 0xffff5bb1);
358 FF (b, c, d, a, x[11],
S14, 0x895cd7be);
359 FF (a, b, c, d, x[12],
S11, 0x6b901122);
360 FF (d, a, b, c, x[13],
S12, 0xfd987193);
361 FF (c, d, a, b, x[14],
S13, 0xa679438e);
362 FF (b, c, d, a, x[15],
S14, 0x49b40821);
365 GG (a, b, c, d, x[ 1],
S21, 0xf61e2562);
366 GG (d, a, b, c, x[ 6],
S22, 0xc040b340);
367 GG (c, d, a, b, x[11],
S23, 0x265e5a51);
368 GG (b, c, d, a, x[ 0],
S24, 0xe9b6c7aa);
369 GG (a, b, c, d, x[ 5],
S21, 0xd62f105d);
370 GG (d, a, b, c, x[10],
S22, 0x2441453);
371 GG (c, d, a, b, x[15],
S23, 0xd8a1e681);
372 GG (b, c, d, a, x[ 4],
S24, 0xe7d3fbc8);
373 GG (a, b, c, d, x[ 9],
S21, 0x21e1cde6);
374 GG (d, a, b, c, x[14],
S22, 0xc33707d6);
375 GG (c, d, a, b, x[ 3],
S23, 0xf4d50d87);
376 GG (b, c, d, a, x[ 8],
S24, 0x455a14ed);
377 GG (a, b, c, d, x[13],
S21, 0xa9e3e905);
378 GG (d, a, b, c, x[ 2],
S22, 0xfcefa3f8);
379 GG (c, d, a, b, x[ 7],
S23, 0x676f02d9);
380 GG (b, c, d, a, x[12],
S24, 0x8d2a4c8a);
383 HH (a, b, c, d, x[ 5],
S31, 0xfffa3942);
384 HH (d, a, b, c, x[ 8],
S32, 0x8771f681);
385 HH (c, d, a, b, x[11],
S33, 0x6d9d6122);
386 HH (b, c, d, a, x[14],
S34, 0xfde5380c);
387 HH (a, b, c, d, x[ 1],
S31, 0xa4beea44);
388 HH (d, a, b, c, x[ 4],
S32, 0x4bdecfa9);
389 HH (c, d, a, b, x[ 7],
S33, 0xf6bb4b60);
390 HH (b, c, d, a, x[10],
S34, 0xbebfbc70);
391 HH (a, b, c, d, x[13],
S31, 0x289b7ec6);
392 HH (d, a, b, c, x[ 0],
S32, 0xeaa127fa);
393 HH (c, d, a, b, x[ 3],
S33, 0xd4ef3085);
394 HH (b, c, d, a, x[ 6],
S34, 0x4881d05);
395 HH (a, b, c, d, x[ 9],
S31, 0xd9d4d039);
396 HH (d, a, b, c, x[12],
S32, 0xe6db99e5);
397 HH (c, d, a, b, x[15],
S33, 0x1fa27cf8);
398 HH (b, c, d, a, x[ 2],
S34, 0xc4ac5665);
401 II (a, b, c, d, x[ 0],
S41, 0xf4292244);
402 II (d, a, b, c, x[ 7],
S42, 0x432aff97);
403 II (c, d, a, b, x[14],
S43, 0xab9423a7);
404 II (b, c, d, a, x[ 5],
S44, 0xfc93a039);
405 II (a, b, c, d, x[12],
S41, 0x655b59c3);
406 II (d, a, b, c, x[ 3],
S42, 0x8f0ccc92);
407 II (c, d, a, b, x[10],
S43, 0xffeff47d);
408 II (b, c, d, a, x[ 1],
S44, 0x85845dd1);
409 II (a, b, c, d, x[ 8],
S41, 0x6fa87e4f);
410 II (d, a, b, c, x[15],
S42, 0xfe2ce6e0);
411 II (c, d, a, b, x[ 6],
S43, 0xa3014314);
412 II (b, c, d, a, x[13],
S44, 0x4e0811a1);
413 II (a, b, c, d, x[ 4],
S41, 0xf7537e82);
414 II (d, a, b, c, x[11],
S42, 0xbd3af235);
415 II (c, d, a, b, x[ 2],
S43, 0x2ad7d2bb);
416 II (b, c, d, a, x[ 9],
S44, 0xeb86d391);
436 for (i = 0, j = 0; j < len; i++, j += 4) {
437 output[j] = (
uint1) (input[i] & 0xff);
438 output[j+1] = (
uint1) ((input[i] >> 8) & 0xff);
439 output[j+2] = (
uint1) ((input[i] >> 16) & 0xff);
440 output[j+3] = (
uint1) ((input[i] >> 24) & 0xff);
453 for (i = 0, j = 0; j < len; i++, j += 4)
454 output[i] = ((
uint4)input[j]) | (((
uint4)input[j+1]) << 8) |
455 (((
uint4)input[j+2]) << 16) | (((
uint4)input[j+3]) << 24);
467 for (i = 0; i < len; i++)
468 output[i] = input[i];
478 for (i = 0; i < len; i++)
487 return (x << n) | (x >> (32-n)) ;
496 return (x & y) | (~x & z);
500 return (x & z) | (y & ~z);
519 a +=
F(b, c, d) + x + ac;
525 a +=
G(b, c, d) + x + ac;
531 a +=
H(b, c, d) + x + ac;
537 a +=
I(b, c, d) + x + ac;
static uint4 F(uint4 x, uint4 y, uint4 z)
void transform(uint1 *buffer)
static uint4 G(uint4 x, uint4 y, uint4 z)
void update(unsigned char *input, unsigned int input_length)
static uint4 rotate_left(uint4 x, uint4 n)
static void II(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac)
static uint4 H(uint4 x, uint4 y, uint4 z)
QString getMD5(std::ifstream &stream)
static uint4 I(uint4 x, uint4 y, uint4 z)
static void encode(uint1 *dest, uint4 *src, uint4 length)
static void HH(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac)
MD5 Support allows checksums to be computed for images, determing if they have changed since the albu...
static void memcpy(uint1 *dest, uint1 *src, uint4 length)
static void FF(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac)
bool filesMatch(std::ifstream &stream, QString oldMD5)
static void memset(uint1 *start, uint1 val, uint4 length)
static void GG(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac)
unsigned char * raw_digest()
static void decode(uint4 *dest, uint1 *src, uint4 length)