mike            Sun Feb 19 23:43:23 2006 UTC

  Modified files:              
    /php-src/ext/hash   config.m4 hash_tiger.c php_hash_types.h 
  Log:
  MF51: fix tiger on big endian platforms
  
http://cvs.php.net/viewcvs.cgi/php-src/ext/hash/config.m4?r1=1.10&r2=1.11&diff_format=u
Index: php-src/ext/hash/config.m4
diff -u php-src/ext/hash/config.m4:1.10 php-src/ext/hash/config.m4:1.11
--- php-src/ext/hash/config.m4:1.10     Sat Nov 26 13:15:06 2005
+++ php-src/ext/hash/config.m4  Sun Feb 19 23:43:23 2006
@@ -1,12 +1,14 @@
-dnl $Id: config.m4,v 1.10 2005/11/26 13:15:06 mike Exp $
+dnl $Id: config.m4,v 1.11 2006/02/19 23:43:23 mike Exp $
 dnl config.m4 for extension hash
 
 PHP_ARG_ENABLE(hash, whether to enable hash support,
-[  --enable-hash           Enable hash support])
+[  --disable-hash           Disable hash support], yes)
 
 if test "$PHP_HASH" != "no"; then
   AC_DEFINE(HAVE_HASH_EXT,1,[Have HASH Extension])
 
+  PHP_C_BIGENDIAN
+
   AC_CHECK_SIZEOF(short, 2)
   AC_CHECK_SIZEOF(int, 4)
   AC_CHECK_SIZEOF(long, 4)
http://cvs.php.net/viewcvs.cgi/php-src/ext/hash/hash_tiger.c?r1=1.5&r2=1.6&diff_format=u
Index: php-src/ext/hash/hash_tiger.c
diff -u php-src/ext/hash/hash_tiger.c:1.5 php-src/ext/hash/hash_tiger.c:1.6
--- php-src/ext/hash/hash_tiger.c:1.5   Sun Jan  1 13:09:50 2006
+++ php-src/ext/hash/hash_tiger.c       Sun Feb 19 23:43:23 2006
@@ -17,7 +17,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: hash_tiger.c,v 1.5 2006/01/01 13:09:50 sniper Exp $ */
+/* $Id: hash_tiger.c,v 1.6 2006/02/19 23:43:23 mike Exp $ */
 
 #include "php_hash.h"
 #include "php_hash_tiger.h"
@@ -88,6 +88,24 @@
        } \
        feedforward
 
+#define split_ex(str) \
+       x0=str[0]; x1=str[1]; x2=str[2]; x3=str[3]; \
+       x4=str[4]; x5=str[5]; x6=str[6]; x7=str[7];
+#ifdef WORDS_BIGENDIAN
+#      define split(str) \
+       { \
+               int i; \
+               php_hash_uint64 tmp[8]; \
+                \
+               for (i = 0; i < 64; ++i) { \
+                       ((unsigned char *) tmp)[i^7] = ((unsigned char *) 
str)[i]; \
+               } \
+               split_ex(tmp); \
+       }
+#else
+#      define split split_ex
+#endif
+
 #define tiger_compress(passes, str, state) \
 { \
        register php_hash_uint64 a, b, c, tmpa, x0, x1, x2, x3, x4, x5, x6, x7; 
\
@@ -98,8 +116,7 @@
        b = state[1]; \
        c = state[2]; \
        \
-       x0=str[0]; x1=str[1]; x2=str[2]; x3=str[3]; \
-       x4=str[4]; x5=str[5]; x6=str[6]; x7=str[7]; \
+       split(str); \
        \
        compress(passes); \
        \
@@ -118,7 +135,7 @@
                memset(&context->buffer[context->length], 0, 
8-context->length%8);
                context->length += 8-context->length%8;
        }
-    
+       
        if (context->length > 56) {
                memset(&context->buffer[context->length], 0, 64 - 
context->length);
                tiger_compress(context->passes, ((php_hash_uint64 *) 
context->buffer), context->state);
@@ -126,8 +143,19 @@
        } else {
                memset(&context->buffer[context->length], 0, 56 - 
context->length);
        }
-       
+
+#ifndef WORDS_BIGENDIAN        
        memcpy(&context->buffer[56], &context->passed, sizeof(php_hash_uint64));
+#else
+       context->buffer[56] = (unsigned char) (context->passed & 0xff);
+       context->buffer[57] = (unsigned char) ((context->passed >> 8) & 0xff);
+       context->buffer[58] = (unsigned char) ((context->passed >> 16) & 0xff);
+       context->buffer[59] = (unsigned char) ((context->passed >> 24) & 0xff);
+       context->buffer[60] = (unsigned char) ((context->passed >> 32) & 0xff);
+       context->buffer[61] = (unsigned char) ((context->passed >> 40) & 0xff);
+       context->buffer[62] = (unsigned char) ((context->passed >> 48) & 0xff);
+       context->buffer[63] = (unsigned char) ((context->passed >> 56) & 0xff);
+#endif
        tiger_compress(context->passes, ((php_hash_uint64 *) context->buffer), 
context->state);
 }
 
@@ -165,11 +193,12 @@
                }
                
                for (; i + 64 <= len; i += 64) {
-                       tiger_compress(context->passes, ((const php_hash_uint64 
*) (input + i)), context->state);
+                       memcpy(context->buffer, &input[i], 64);
+                       tiger_compress(context->passes, ((const php_hash_uint64 
*) context->buffer), context->state);
                        context->passed += 512;
                }
-               
-               memcpy(context->buffer, input + i, r);
+               memset(&context->buffer[r], 0, 64-r);
+               memcpy(context->buffer, &input[i], r);
                context->length = r;
        }
 }
http://cvs.php.net/viewcvs.cgi/php-src/ext/hash/php_hash_types.h?r1=1.3&r2=1.4&diff_format=u
Index: php-src/ext/hash/php_hash_types.h
diff -u php-src/ext/hash/php_hash_types.h:1.3 
php-src/ext/hash/php_hash_types.h:1.4
--- php-src/ext/hash/php_hash_types.h:1.3       Sun Jan  1 13:09:50 2006
+++ php-src/ext/hash/php_hash_types.h   Sun Feb 19 23:43:23 2006
@@ -16,13 +16,17 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: php_hash_types.h,v 1.3 2006/01/01 13:09:50 sniper Exp $ */
+/* $Id: php_hash_types.h,v 1.4 2006/02/19 23:43:23 mike Exp $ */
 
 #ifndef PHP_HASH_TYPES_H
 #define PHP_HASH_TYPES_H
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
+#else
+#ifndef PHP_WIN32
+#include "php_config.h"
+#endif
 #endif
 
 #ifndef PHP_WIN32

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to