From: Hamatoma Date: Sun, 8 Feb 2015 17:33:02 +0000 (+0100) Subject: ReMD5 issues X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=38feba852d1901db04c85f2548ea158adb7e4a4b;p=crepublib ReMD5 issues --- diff --git a/cunit/cuReMD5.cpp b/cunit/cuReMD5.cpp index bb0c990..22559c5 100644 --- a/cunit/cuReMD5.cpp +++ b/cunit/cuReMD5.cpp @@ -31,23 +31,33 @@ private: 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()); } }; diff --git a/math/ReMD5.cpp b/math/ReMD5.cpp index 6dbf609..2f89478 100644 --- a/math/ReMD5.cpp +++ b/math/ReMD5.cpp @@ -13,6 +13,7 @@ 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)) @@ -182,6 +183,10 @@ void ReMD5::processChunk(const uint8_t block[64]){ //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); diff --git a/math/md5.cpp b/math/md5.cpp index 9ca7a97..9584c7f 100644 --- a/math/md5.cpp +++ b/math/md5.cpp @@ -83,23 +83,39 @@ static int s_ix = 0; // 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; } @@ -169,6 +185,9 @@ void MD5::transform(const uint1 block[blocksize]) 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 */