From 79b6a241abfe0cf59637816f40c469952c816e1b Mon Sep 17 00:00:00 2001 From: Antony Dovgal Date: Mon, 18 Aug 2008 14:33:00 +0000 Subject: [PATCH] MFH: fix bug #45028 (CRC32 output endianness is different between crc32() and hash()) --- NEWS | 2 ++ ext/hash/hash_crc32.c | 12 +++++++++++- ext/hash/tests/crc32.phpt | 12 ++++++------ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/NEWS b/NEWS index 0e71605cdf..471b3a3ce4 100644 --- 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 diff --git a/ext/hash/hash_crc32.c b/ext/hash/hash_crc32.c index 481c2c827e..508c9f1448 100644 --- a/ext/hash/hash_crc32.c +++ b/ext/hash/hash_crc32.c @@ -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) diff --git a/ext/hash/tests/crc32.phpt b/ext/hash/tests/crc32.phpt index c51209c60d..3862fb17a6 100644 --- a/ext/hash/tests/crc32.phpt +++ b/ext/hash/tests/crc32.phpt @@ -28,9 +28,9 @@ echo hash('crc32b', '12345678901234567890123456789012345678901234567890123456789 882174a0 96790816 00000000 -43beb7e8 -c2412435 -7f9d1520 -bd50274c -d2e6c21f -724aa97c +e8b7be43 +352441c2 +20159d7f +4c2750bd +1fc2e6d2 +7ca94a72 -- 2.50.1