summaryrefslogtreecommitdiff
path: root/ext/hash/hash_md.c
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@php.net>2008-02-08 09:11:17 +0000
committerDmitry Stogov <dmitry@php.net>2008-02-08 09:11:17 +0000
commit3ea9c13c4be01cb055e65fbeda034ade5e3c7ed8 (patch)
treef54e121e2fc0c53bff658e9cef4f12050cf3d7e9 /ext/hash/hash_md.c
parent54680a30fc7f893a559b0dd166872e2e79920ed4 (diff)
downloadphp-git-3ea9c13c4be01cb055e65fbeda034ade5e3c7ed8.tar.gz
Improved md5() implementation (Solar Designer)
Diffstat (limited to 'ext/hash/hash_md.c')
-rw-r--r--ext/hash/hash_md.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/ext/hash/hash_md.c b/ext/hash/hash_md.c
index a9e3469d70..f50eee2a11 100644
--- a/ext/hash/hash_md.c
+++ b/ext/hash/hash_md.c
@@ -442,8 +442,8 @@ const unsigned char block[64];
/* MD4 */
-#define MD4_F(x,y,z) (((x) & (y)) | ((~(x)) & (z)))
-#define MD4_G(x,y,z) (((x) & (y)) | ((x) & (z)) | ((y) & (z)))
+#define MD4_F(x,y,z) ((z) ^ ((x) & ((y) ^ (z))))
+#define MD4_G(x,y,z) (((x) & ((y) | (z))) | ((y) & (z)))
#define MD4_H(x,y,z) ((x) ^ (y) ^ (z))
#define ROTL32(s,v) (((v) << (s)) | ((v) >> (32 - (s))))
@@ -518,8 +518,23 @@ static void MD4Transform(php_hash_uint32 state[4], const unsigned char block[64]
state[3] += d;
}
+/* {{{ PHP_MD4Init
+ * MD4 initialization. Begins an MD4 operation, writing a new context.
+ */
+PHP_HASH_API void PHP_MD4Init(PHP_MD4_CTX * context)
+{
+ context->count[0] = context->count[1] = 0;
+ /* Load magic initialization constants.
+ */
+ context->state[0] = 0x67452301;
+ context->state[1] = 0xefcdab89;
+ context->state[2] = 0x98badcfe;
+ context->state[3] = 0x10325476;
+}
+/* }}} */
+
/* {{{ PHP_MD4Update
- MD4 block update operation. Continues an MD5 message-digest
+ MD4 block update operation. Continues an MD4 message-digest
operation, processing another message block, and updating the
context.
*/