I wrote: > OK, I think I found it. ext/hash/php_hash_md.h has this: > > #define PHP_MD4Init PHP_MD5Init > > which breaks when the two implementations are not that similar anymore. > Replacing the MD4 implementation with mine as well would fix this (or > hide the bug, depending on your point of view), but for now I think the > right fix would be to define a PHP_MD4Init() function explicitly.
The patch is attached. It contains two other tiny changes: 1. Replaces two of MD4's basic functions with more optimal versions (faster and smaller code). 2. Corrects a typo in a nearby comment. This patch may be applied independently and before the MD5 replacement patch - but it is required for the MD5 replacement patch. Alexander
--- php-5.2.5/ext/hash/hash_md.c.orig 2007-01-09 01:29:25 +0300 +++ php-5.2.5/ext/hash/hash_md.c 2008-02-07 14:58:03 +0300 @@ -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[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. */ --- php-5.2.5/ext/hash/php_hash_md.h.orig 2007-01-01 12:36:01 +0300 +++ php-5.2.5/ext/hash/php_hash_md.h 2008-02-07 14:58:35 +0300 @@ -81,7 +81,7 @@ unsigned char buffer[64]; } PHP_MD4_CTX; -#define PHP_MD4Init PHP_MD5Init +PHP_HASH_API void PHP_MD4Init(PHP_MD4_CTX *); PHP_HASH_API void PHP_MD4Update(PHP_MD4_CTX *context, const unsigned char *, unsigned int); PHP_HASH_API void PHP_MD4Final(unsigned char[16], PHP_MD4_CTX *);
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php