testBase();
}
void testOld(){
-#if 1
+#if 0
MD5 md5;
- md5.update("", 0);
+ const char* text = "The quick brown fox jumps over the lazy dog";
+ text = "01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVEXYZ01234567890\n";
+
+ md5.update(text, strlen(text));
md5.finalize();
std::string dig = md5.hexdigest();
const char* dig2 = (const char*) dig.c_str();
+ printf ("%s:\n%s\n", text, dig.c_str());
dig2++;
#endif
}
void testBase(){
ReMD5 md5;
- md5.update((const uint8_t*)"", 0);
- checkEqu("d41d8cd98f00b204e9800998ecf8427e",
+ const char* text = "01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVEXYZ01234567890\n";
+ md5.update((const uint8_t*)text, strlen(text));
+ checkEqu("c0a278c051a6898f6ad05da7fa80a1c4",
md5.hexDigest().str());
md5.reset();
- md5.update((const uint8_t*)"01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVEXYZ01234567890\n", -1);
- checkEqu("c0a278c051a6898f6ad05da7fa80a1c4",
+ text = "The quick brown fox jumps over the lazy dog";
+ md5.update((const uint8_t*) text, -1);
+ checkEqu("9e107d9d372bb6826bd81d3542a419d6",
+ md5.hexDigest().str());
+ md5.reset();
+ md5.update((const uint8_t*)"", 0);
+ checkEqu("d41d8cd98f00b204e9800998ecf8427e",
md5.hexDigest().str());
}
};
const int ReMD5::m_s[64] = {
7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
+ 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21
};
// for x in [1..64] : int(2**32 * sin(x))
//Main loop:
int F, g;
+#define TRACE_MD5
+#if defined TRACE_MD5
+ printf("neu: (%s)\n", block);
+#endif
for (int i = 0; i < 64; i++){
#if defined TRACE_MD5
printf("%2d: A: %08x B: %08x C: %08x D%08x\n", i, A, B, C, D);
// FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
// Rotation is separate from addition to prevent recomputation.
inline void MD5::FF(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac) {
+#define TRACE_MD5
#if defined TRACE_MD5
printf("%2d: A: %08x B: %08x C: %08x D%08x\n", s_ix++ % 16, a, b, c, d);
- printf(" K[%2d]: %08x M[?]: %08x shift: %02d ac: %08x\n",
- s_ix - 1, 0xd76aa478, x, s, ac);
+ printf(" K[%2d]: %08x M[?]: %08x shift: %02d\n",
+ s_ix - 1, ac, x, s);
#endif
a = rotate_left(a+ F(b,c,d) + x + ac, s) + b;
}
inline void MD5::GG(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac) {
+#if defined TRACE_MD5
+ printf("%2d: A: %08x B: %08x C: %08x D%08x\n", s_ix++ % 16, a, b, c, d);
+ printf(" K[%2d]: %08x M[?]: %08x shift: %02d\n",
+ s_ix - 1, ac, x, s);
+#endif
a = rotate_left(a + G(b,c,d) + x + ac, s) + b;
}
inline void MD5::HH(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac) {
+#if defined TRACE_MD5
+ printf("%2d: A: %08x B: %08x C: %08x D%08x\n", s_ix++ % 16, a, b, c, d);
+ printf(" K[%2d]: %08x M[?]: %08x shift: %02d\n",
+ s_ix - 1, ac, x, s);
+#endif
a = rotate_left(a + H(b,c,d) + x + ac, s) + b;
}
inline void MD5::II(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac) {
+#if defined TRACE_MD5
+ printf("%2d: A: %08x B: %08x C: %08x D%08x\n", s_ix++ % 16, a, b, c, d);
+ printf(" K[%2d]: %08x M[?]: %08x shift: %02d\n",
+ s_ix - 1, ac, x, s);
+#endif
a = rotate_left(a + I(b,c,d) + x + ac, s) + b;
}
uint4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
decode (x, block, blocksize);
+#if defined TRACE_MD5
+ printf("old: (%s)\n", block);
+#endif
/* Round 1 */
FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */