]> granicus.if.org Git - php/commitdiff
MFH: fix bug #45028 (CRC32 output endianness is different between crc32() and hash())
authorAntony Dovgal <tony2001@php.net>
Mon, 18 Aug 2008 14:33:00 +0000 (14:33 +0000)
committerAntony Dovgal <tony2001@php.net>
Mon, 18 Aug 2008 14:33:00 +0000 (14:33 +0000)
NEWS
ext/hash/hash_crc32.c
ext/hash/tests/crc32.phpt

diff --git a/NEWS b/NEWS
index 0e71605cdf00edb3980b19209cdcf1318a337cc5..471b3a3ce4b955fa8f9d6a47cc620d867eebee97 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -59,6 +59,8 @@ PHP                                                                        NEWS
   (Dmitry)
 - Fixed bug #45139 (ReflectionProperty returns incorrect declaring class).
   (Felipe)
+- Fixed bug #45028 (CRC32 output endianness is different between crc32() 
+  and hash()). (Tony)
 - Fixed bug #45004 (pg_insert() does not accept 4 digit timezone format).
   (Ilia)
 - Fixed bug #44891 Memory leak using registerPHPFunctions and XSLT Variable 
index 481c2c827ef788ca67f675ab18916b97f81af55b..508c9f1448fda9a40cfdb943eca3382a72374392 100644 (file)
@@ -56,6 +56,16 @@ PHP_HASH_API void PHP_CRC32Final(unsigned char digest[4], PHP_CRC32_CTX *context
        context->state = 0;
 }
 
+PHP_HASH_API void PHP_CRC32BFinal(unsigned char digest[4], PHP_CRC32_CTX *context)
+{
+       context->state=~context->state;
+       digest[0] = (unsigned char) ((context->state >> 24) & 0xff);
+       digest[1] = (unsigned char) ((context->state >> 16) & 0xff);
+       digest[2] = (unsigned char) ((context->state >> 8) & 0xff);
+       digest[3] = (unsigned char) (context->state & 0xff);
+       context->state = 0;
+}
+
 const php_hash_ops php_hash_crc32_ops = {
        (php_hash_init_func_t) PHP_CRC32Init,
        (php_hash_update_func_t) PHP_CRC32Update,
@@ -68,7 +78,7 @@ const php_hash_ops php_hash_crc32_ops = {
 const php_hash_ops php_hash_crc32b_ops = {
        (php_hash_init_func_t) PHP_CRC32Init,
        (php_hash_update_func_t) PHP_CRC32BUpdate,
-       (php_hash_final_func_t) PHP_CRC32Final,
+       (php_hash_final_func_t) PHP_CRC32BFinal,
        4, /* what to say here? */
        4,
        sizeof(PHP_CRC32_CTX)
index c51209c60da6cec74fb004237acecc9b8a087219..3862fb17a6a009ee4b67940d4099ad177eff3451 100644 (file)
@@ -28,9 +28,9 @@ echo hash('crc32b', '12345678901234567890123456789012345678901234567890123456789
 882174a0
 96790816
 00000000
-43beb7e8
-c2412435
-7f9d1520
-bd50274c
-d2e6c21f
-724aa97c
+e8b7be43
+352441c2
+20159d7f
+4c2750bd
+1fc2e6d2
+7ca94a72