]> 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:29:55 +0000 (14:29 +0000)
committerAntony Dovgal <tony2001@php.net>
Mon, 18 Aug 2008 14:29:55 +0000 (14:29 +0000)
NEWS
ext/hash/hash_crc32.c
ext/hash/tests/crc32.phpt
ext/hash/tests/hash_copy_001.phpt

diff --git a/NEWS b/NEWS
index 4bac30841227706943e4056854abc8c89030978d..e6d34ea9e8a4334c68515c0c2493c637dc1a7b12 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -37,6 +37,8 @@ PHP                                                                        NEWS
 - Fixed bug #45384 (parse_ini_file will result in parse error with no trailing 
   newline). (Arnaud)
 - Fixed bug #45044 (relative paths not resolved correctly). (Dmitry)
+- Fixed bug #45028 (CRC32 output endianness is different between crc32() 
+  and hash()). (Tony)
 - Fixed bug #44925 (preg_grep() modifies input array). (Nuno)
 - Fixed bug #44842 (parse_ini_file keys that start/end with underscore). 
   (Arnaud)
index ccc6de3b0dc409e947266d4034e160d3e8e06bb7..9f03ad07046338317cf8f0f0dfe6dcd1a90ce446 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;
+}
+
 PHP_HASH_API int PHP_CRC32Copy(const php_hash_ops *ops, PHP_CRC32_CTX *orig_context, PHP_CRC32_CTX *copy_context)
 {
        copy_context->state = orig_context->state;
@@ -75,7 +85,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,
        (php_hash_copy_func_t) PHP_CRC32Copy,
        4, /* what to say here? */
        4,
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
index e3f5081f011f42c08a5c7dcca7a01f5eac036508..a6d4c6179768f7b81cfa647de7a532a898e538c7 100644 (file)
@@ -75,8 +75,8 @@ string(8) "28097c6f"
 string(8) "28097c6f"
 string(8) "e5cfc160"
 string(8) "e5cfc160"
-string(8) "4e7a1469"
-string(8) "4e7a1469"
+string(8) "69147a4e"
+string(8) "69147a4e"
 string(32) "86362472c8895e68e223ef8b3711d8d9"
 string(32) "86362472c8895e68e223ef8b3711d8d9"
 string(40) "fabdf6905f3ba18a3c93d6a16b91e31f7222a7a4"
@@ -155,8 +155,8 @@ string(8) "28097c6f"
 string(8) "471714d9"
 string(8) "e5cfc160"
 string(8) "59f8d3d2"
-string(8) "4e7a1469"
-string(8) "9939e63e"
+string(8) "69147a4e"
+string(8) "3ee63999"
 string(32) "86362472c8895e68e223ef8b3711d8d9"
 string(32) "ebeeeb05c18af1e53d2d127b561d5e0d"
 string(40) "fabdf6905f3ba18a3c93d6a16b91e31f7222a7a4"