com php-src: Fix bug #70312 - HAVAL gives wrong hashes in specific cases: ext/hash/hash_haval.c ext/hash/tests/bug70312 .phpt

From: Date: Tue, 01 Sep 2015 08:16:30 +0000
Subject: com php-src: Fix bug #70312 - HAVAL gives wrong hashes in specific cases: ext/hash/hash_haval.c ext/hash/tests/bug70312 .phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-88823@lists.php.net to get a copy of this message
Commit: 1390a5812b151e0ea8f74e64bfeaa5df4dd5b801 Author: Stanislav Malyshev <stas@php.net> Tue, 1 Sep 2015 01:16:30 -0700 Parents: 906f19f1365488f90f7473e833a7a13f2c1387ac Branches: PHP-5.4 PHP-5.4.45 Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=1390a5812b151e0ea8f74e64bfeaa5df4dd5b801 Log: Fix bug #70312 - HAVAL gives wrong hashes in specific cases Bugs: https://bugs.php.net/70312 Changed paths: M ext/hash/hash_haval.c A ext/hash/tests/bug70312.phpt Diff: diff --git a/ext/hash/hash_haval.c b/ext/hash/hash_haval.c index 32437ce..2102743 100644 --- a/ext/hash/hash_haval.c +++ b/ext/hash/hash_haval.c @@ -336,7 +336,7 @@ PHP_HASH_API void PHP_HAVAL128Final(unsigned char *digest, PHP_HAVAL_CTX * conte /* Pad out to 118 mod 128. */ - index = (unsigned int) ((context->count[0] >> 3) & 0x3f); + index = (unsigned int) ((context->count[0] >> 3) & 0x7f); padLen = (index < 118) ? (118 - index) : (246 - index); PHP_HAVALUpdate(context, PADDING, padLen); @@ -390,7 +390,7 @@ PHP_HASH_API void PHP_HAVAL160Final(unsigned char *digest, PHP_HAVAL_CTX * conte /* Pad out to 118 mod 128. */ - index = (unsigned int) ((context->count[0] >> 3) & 0x3f); + index = (unsigned int) ((context->count[0] >> 3) & 0x7f); padLen = (index < 118) ? (118 - index) : (246 - index); PHP_HAVALUpdate(context, PADDING, padLen); @@ -444,7 +444,7 @@ PHP_HASH_API void PHP_HAVAL192Final(unsigned char *digest, PHP_HAVAL_CTX * conte /* Pad out to 118 mod 128. */ - index = (unsigned int) ((context->count[0] >> 3) & 0x3f); + index = (unsigned int) ((context->count[0] >> 3) & 0x7f); padLen = (index < 118) ? (118 - index) : (246 - index); PHP_HAVALUpdate(context, PADDING, padLen); @@ -484,7 +484,7 @@ PHP_HASH_API void PHP_HAVAL224Final(unsigned char *digest, PHP_HAVAL_CTX * conte /* Pad out to 118 mod 128. */ - index = (unsigned int) ((context->count[0] >> 3) & 0x3f); + index = (unsigned int) ((context->count[0] >> 3) & 0x7f); padLen = (index < 118) ? (118 - index) : (246 - index); PHP_HAVALUpdate(context, PADDING, padLen); @@ -525,7 +525,7 @@ PHP_HASH_API void PHP_HAVAL256Final(unsigned char *digest, PHP_HAVAL_CTX * conte /* Pad out to 118 mod 128. */ - index = (unsigned int) ((context->count[0] >> 3) & 0x3f); + index = (unsigned int) ((context->count[0] >> 3) & 0x7f); padLen = (index < 118) ? (118 - index) : (246 - index); PHP_HAVALUpdate(context, PADDING, padLen); diff --git a/ext/hash/tests/bug70312.phpt b/ext/hash/tests/bug70312.phpt new file mode 100644 index 0000000..5ded1ac --- /dev/null +++ b/ext/hash/tests/bug70312.phpt @@ -0,0 +1,18 @@ +--TEST-- +Bug #70312 HAVAL gives wrong hashes in specific cases +--SKIPIF-- +<?php if(!extension_loaded("hash")) print "skip"; ?> +--FILE-- +<?php +var_dump(hash('haval128,5', '1234567890123456789012345678901234567890123456789012345678901234')); +var_dump(hash('haval160,5', '1234567890123456789012345678901234567890123456789012345678901234')); +var_dump(hash('haval192,5', '1234567890123456789012345678901234567890123456789012345678901234')); +var_dump(hash('haval224,5', '1234567890123456789012345678901234567890123456789012345678901234')); +var_dump(hash('haval256,5', '1234567890123456789012345678901234567890123456789012345678901234')); +?> +--EXPECTF-- +string(32) "f3f0d23819b87228b4b70ee350afaa9d" +string(40) "aded6485e137f11d7292212ba3fa961714df0564" +string(48) "e53da2b16269fe732e9a898a96707a9f28404d7333b02286" +string(56) "c574fb307f0817b514b9bb2e7c4bfaffb7ad667aca3c8b523fefcf10" +string(64) "fb73c19300b14d5cb393d929bf005e6c2d459a4c9c009e9813af1d2d3637ee8f" \ No newline at end of file

« previous php.cvs (#88823) next »