From 341abafe66d4506d135b2fb1aac8cc21fed1c7aa Mon Sep 17 00:00:00 2001 From: Alexey Dobriyan Date: Sun, 18 Sep 2011 23:36:16 +0300 Subject: [PATCH] crhash: md5: make T_i embedded constants --- hash-md5.c | 206 +++++++++++++++++++++---------------------------------------- 1 file changed, 69 insertions(+), 137 deletions(-) diff --git a/hash-md5.c b/hash-md5.c index 72a843e..9ef9ecf 100644 --- a/hash-md5.c +++ b/hash-md5.c @@ -5,74 +5,6 @@ #include "hash-md5.h" -static const uint32_t T[64 + 1] = { - 0, - 0xd76aa478, - 0xe8c7b756, - 0x242070db, - 0xc1bdceee, - 0xf57c0faf, - 0x4787c62a, - 0xa8304613, - 0xfd469501, - 0x698098d8, - 0x8b44f7af, - 0xffff5bb1, - 0x895cd7be, - 0x6b901122, - 0xfd987193, - 0xa679438e, - 0x49b40821, - 0xf61e2562, - 0xc040b340, - 0x265e5a51, - 0xe9b6c7aa, - 0xd62f105d, - 0x02441453, - 0xd8a1e681, - 0xe7d3fbc8, - 0x21e1cde6, - 0xc33707d6, - 0xf4d50d87, - 0x455a14ed, - 0xa9e3e905, - 0xfcefa3f8, - 0x676f02d9, - 0x8d2a4c8a, - 0xfffa3942, - 0x8771f681, - 0x6d9d6122, - 0xfde5380c, - 0xa4beea44, - 0x4bdecfa9, - 0xf6bb4b60, - 0xbebfbc70, - 0x289b7ec6, - 0xeaa127fa, - 0xd4ef3085, - 0x04881d05, - 0xd9d4d039, - 0xe6db99e5, - 0x1fa27cf8, - 0xc4ac5665, - 0xf4292244, - 0x432aff97, - 0xab9423a7, - 0xfc93a039, - 0x655b59c3, - 0x8f0ccc92, - 0xffeff47d, - 0x85845dd1, - 0x6fa87e4f, - 0xfe2ce6e0, - 0xa3014314, - 0x4e0811a1, - 0xf7537e82, - 0xbd3af235, - 0x2ad7d2bb, - 0xeb86d391, -}; - static uint32_t rol32(const uint32_t x, const unsigned int n) { return (x << n) | (x >> (32 - n)); @@ -105,8 +37,8 @@ struct md5_context { unsigned int m_len; }; -#define MD5(a, b, c, d, F, k, s, i) \ - a = b + rol32(a + F(b, c, d) + X[k] + T[i], s) +#define MD5(a, b, c, d, F, k, s, Ti) \ + a = b + rol32(a + F(b, c, d) + X[k] + Ti, s) static void __md5_update(void *_ctx, const uint8_t *m) { @@ -122,73 +54,73 @@ static void __md5_update(void *_ctx, const uint8_t *m) for (i = 0; i < 16; i++) X[i] = le32toh(*(uint32_t *)(m + i * sizeof(uint32_t))); - MD5(A, B, C, D, F, 0, 7, 1); - MD5(D, A, B, C, F, 1, 12, 2); - MD5(C, D, A, B, F, 2, 17, 3); - MD5(B, C, D, A, F, 3, 22, 4); - MD5(A, B, C, D, F, 4, 7, 5); - MD5(D, A, B, C, F, 5, 12, 6); - MD5(C, D, A, B, F, 6, 17, 7); - MD5(B, C, D, A, F, 7, 22, 8); - MD5(A, B, C, D, F, 8, 7, 9); - MD5(D, A, B, C, F, 9, 12, 10); - MD5(C, D, A, B, F, 10, 17, 11); - MD5(B, C, D, A, F, 11, 22, 12); - MD5(A, B, C, D, F, 12, 7, 13); - MD5(D, A, B, C, F, 13, 12, 14); - MD5(C, D, A, B, F, 14, 17, 15); - MD5(B, C, D, A, F, 15, 22, 16); - - MD5(A, B, C, D, G, 1, 5, 17); - MD5(D, A, B, C, G, 6, 9, 18); - MD5(C, D, A, B, G, 11, 14, 19); - MD5(B, C, D, A, G, 0, 20, 20); - MD5(A, B, C, D, G, 5, 5, 21); - MD5(D, A, B, C, G, 10, 9, 22); - MD5(C, D, A, B, G, 15, 14, 23); - MD5(B, C, D, A, G, 4, 20, 24); - MD5(A, B, C, D, G, 9, 5, 25); - MD5(D, A, B, C, G, 14, 9, 26); - MD5(C, D, A, B, G, 3, 14, 27); - MD5(B, C, D, A, G, 8, 20, 28); - MD5(A, B, C, D, G, 13, 5, 29); - MD5(D, A, B, C, G, 2, 9, 30); - MD5(C, D, A, B, G, 7, 14, 31); - MD5(B, C, D, A, G, 12, 20, 32); - - MD5(A, B, C, D, H, 5, 4, 33); - MD5(D, A, B, C, H, 8, 11, 34); - MD5(C, D, A, B, H, 11, 16, 35); - MD5(B, C, D, A, H, 14, 23, 36); - MD5(A, B, C, D, H, 1, 4, 37); - MD5(D, A, B, C, H, 4, 11, 38); - MD5(C, D, A, B, H, 7, 16, 39); - MD5(B, C, D, A, H, 10, 23, 40); - MD5(A, B, C, D, H, 13, 4, 41); - MD5(D, A, B, C, H, 0, 11, 42); - MD5(C, D, A, B, H, 3, 16, 43); - MD5(B, C, D, A, H, 6, 23, 44); - MD5(A, B, C, D, H, 9, 4, 45); - MD5(D, A, B, C, H, 12, 11, 46); - MD5(C, D, A, B, H, 15, 16, 47); - MD5(B, C, D, A, H, 2, 23, 48); - - MD5(A, B, C, D, I, 0, 6, 49); - MD5(D, A, B, C, I, 7, 10, 50); - MD5(C, D, A, B, I, 14, 15, 51); - MD5(B, C, D, A, I, 5, 21, 52); - MD5(A, B, C, D, I, 12, 6, 53); - MD5(D, A, B, C, I, 3, 10, 54); - MD5(C, D, A, B, I, 10, 15, 55); - MD5(B, C, D, A, I, 1, 21, 56); - MD5(A, B, C, D, I, 8, 6, 57); - MD5(D, A, B, C, I, 15, 10, 58); - MD5(C, D, A, B, I, 6, 15, 59); - MD5(B, C, D, A, I, 13, 21, 60); - MD5(A, B, C, D, I, 4, 6, 61); - MD5(D, A, B, C, I, 11, 10, 62); - MD5(C, D, A, B, I, 2, 15, 63); - MD5(B, C, D, A, I, 9, 21, 64); + MD5(A, B, C, D, F, 0, 7, 0xd76aa478); + MD5(D, A, B, C, F, 1, 12, 0xe8c7b756); + MD5(C, D, A, B, F, 2, 17, 0x242070db); + MD5(B, C, D, A, F, 3, 22, 0xc1bdceee); + MD5(A, B, C, D, F, 4, 7, 0xf57c0faf); + MD5(D, A, B, C, F, 5, 12, 0x4787c62a); + MD5(C, D, A, B, F, 6, 17, 0xa8304613); + MD5(B, C, D, A, F, 7, 22, 0xfd469501); + MD5(A, B, C, D, F, 8, 7, 0x698098d8); + MD5(D, A, B, C, F, 9, 12, 0x8b44f7af); + MD5(C, D, A, B, F, 10, 17, 0xffff5bb1); + MD5(B, C, D, A, F, 11, 22, 0x895cd7be); + MD5(A, B, C, D, F, 12, 7, 0x6b901122); + MD5(D, A, B, C, F, 13, 12, 0xfd987193); + MD5(C, D, A, B, F, 14, 17, 0xa679438e); + MD5(B, C, D, A, F, 15, 22, 0x49b40821); + + MD5(A, B, C, D, G, 1, 5, 0xf61e2562); + MD5(D, A, B, C, G, 6, 9, 0xc040b340); + MD5(C, D, A, B, G, 11, 14, 0x265e5a51); + MD5(B, C, D, A, G, 0, 20, 0xe9b6c7aa); + MD5(A, B, C, D, G, 5, 5, 0xd62f105d); + MD5(D, A, B, C, G, 10, 9, 0x02441453); + MD5(C, D, A, B, G, 15, 14, 0xd8a1e681); + MD5(B, C, D, A, G, 4, 20, 0xe7d3fbc8); + MD5(A, B, C, D, G, 9, 5, 0x21e1cde6); + MD5(D, A, B, C, G, 14, 9, 0xc33707d6); + MD5(C, D, A, B, G, 3, 14, 0xf4d50d87); + MD5(B, C, D, A, G, 8, 20, 0x455a14ed); + MD5(A, B, C, D, G, 13, 5, 0xa9e3e905); + MD5(D, A, B, C, G, 2, 9, 0xfcefa3f8); + MD5(C, D, A, B, G, 7, 14, 0x676f02d9); + MD5(B, C, D, A, G, 12, 20, 0x8d2a4c8a); + + MD5(A, B, C, D, H, 5, 4, 0xfffa3942); + MD5(D, A, B, C, H, 8, 11, 0x8771f681); + MD5(C, D, A, B, H, 11, 16, 0x6d9d6122); + MD5(B, C, D, A, H, 14, 23, 0xfde5380c); + MD5(A, B, C, D, H, 1, 4, 0xa4beea44); + MD5(D, A, B, C, H, 4, 11, 0x4bdecfa9); + MD5(C, D, A, B, H, 7, 16, 0xf6bb4b60); + MD5(B, C, D, A, H, 10, 23, 0xbebfbc70); + MD5(A, B, C, D, H, 13, 4, 0x289b7ec6); + MD5(D, A, B, C, H, 0, 11, 0xeaa127fa); + MD5(C, D, A, B, H, 3, 16, 0xd4ef3085); + MD5(B, C, D, A, H, 6, 23, 0x04881d05); + MD5(A, B, C, D, H, 9, 4, 0xd9d4d039); + MD5(D, A, B, C, H, 12, 11, 0xe6db99e5); + MD5(C, D, A, B, H, 15, 16, 0x1fa27cf8); + MD5(B, C, D, A, H, 2, 23, 0xc4ac5665); + + MD5(A, B, C, D, I, 0, 6, 0xf4292244); + MD5(D, A, B, C, I, 7, 10, 0x432aff97); + MD5(C, D, A, B, I, 14, 15, 0xab9423a7); + MD5(B, C, D, A, I, 5, 21, 0xfc93a039); + MD5(A, B, C, D, I, 12, 6, 0x655b59c3); + MD5(D, A, B, C, I, 3, 10, 0x8f0ccc92); + MD5(C, D, A, B, I, 10, 15, 0xffeff47d); + MD5(B, C, D, A, I, 1, 21, 0x85845dd1); + MD5(A, B, C, D, I, 8, 6, 0x6fa87e4f); + MD5(D, A, B, C, I, 15, 10, 0xfe2ce6e0); + MD5(C, D, A, B, I, 6, 15, 0xa3014314); + MD5(B, C, D, A, I, 13, 21, 0x4e0811a1); + MD5(A, B, C, D, I, 4, 6, 0xf7537e82); + MD5(D, A, B, C, I, 11, 10, 0xbd3af235); + MD5(C, D, A, B, I, 2, 15, 0x2ad7d2bb); + MD5(B, C, D, A, I, 9, 21, 0xeb86d391); ctx->A += A; ctx->B += B; -- 2.11.4.GIT