Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:35295 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 60849 invoked by uid 1010); 7 Feb 2008 12:19:18 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 60834 invoked from network); 7 Feb 2008 12:19:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Feb 2008 12:19:18 -0000 Authentication-Results: pb1.pair.com smtp.mail=solar@openwall.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=solar@openwall.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain openwall.com designates 195.42.179.200 as permitted sender) X-PHP-List-Original-Sender: solar@openwall.com X-Host-Fingerprint: 195.42.179.200 mother.openwall.net Received: from [195.42.179.200] ([195.42.179.200:4173] helo=mother.openwall.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 14/0C-10179-547FAA74 for ; Thu, 07 Feb 2008 07:19:18 -0500 Received: (qmail 15541 invoked from network); 7 Feb 2008 12:19:14 -0000 Received: from localhost (HELO pvt.openwall.com) (127.0.0.1) by localhost with SMTP; 7 Feb 2008 12:19:14 -0000 Received: by pvt.openwall.com (Postfix, from userid 503) id 7A4D22FD0E; Thu, 7 Feb 2008 15:13:53 +0300 (MSK) Date: Thu, 7 Feb 2008 15:13:53 +0300 To: Dmitry Stogov Cc: Sara Golemon , Stanislav Malyshev , Andi Gutmans , PHP Internals List Message-ID: <20080207121353.GA11906@openwall.com> References: <20071209010552.GA12561@openwall.com> <47A849D0.8050508@zend.com> <20080205235055.GA19309@openwall.com> <47AAD95A.8010109@zend.com> <20080207112109.GA30558@openwall.com> <20080207115027.GA30811@openwall.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="EeQfGwPcQSOJBaQU" Content-Disposition: inline In-Reply-To: <20080207115027.GA30811@openwall.com> User-Agent: Mutt/1.4.2.3i Subject: untie the MD4 code from MD5 (was: faster & public domain MD5 implementation) From: solar@openwall.com (Solar Designer) --EeQfGwPcQSOJBaQU Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 --EeQfGwPcQSOJBaQU Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="php-5.2.5-untie-md4.diff" --- 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 *); --EeQfGwPcQSOJBaQU--