Skip to content

Commit e2291e4

Browse files
committed
Merge branch 'PHP-5.4.45' into PHP-5.5.29
* PHP-5.4.45: Fix bug #70312 - HAVAL gives wrong hashes in specific cases
2 parents 3605d1b + 1390a58 commit e2291e4

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

ext/hash/hash_haval.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ PHP_HASH_API void PHP_HAVAL128Final(unsigned char *digest, PHP_HAVAL_CTX * conte
336336

337337
/* Pad out to 118 mod 128.
338338
*/
339-
index = (unsigned int) ((context->count[0] >> 3) & 0x3f);
339+
index = (unsigned int) ((context->count[0] >> 3) & 0x7f);
340340
padLen = (index < 118) ? (118 - index) : (246 - index);
341341
PHP_HAVALUpdate(context, PADDING, padLen);
342342

@@ -390,7 +390,7 @@ PHP_HASH_API void PHP_HAVAL160Final(unsigned char *digest, PHP_HAVAL_CTX * conte
390390

391391
/* Pad out to 118 mod 128.
392392
*/
393-
index = (unsigned int) ((context->count[0] >> 3) & 0x3f);
393+
index = (unsigned int) ((context->count[0] >> 3) & 0x7f);
394394
padLen = (index < 118) ? (118 - index) : (246 - index);
395395
PHP_HAVALUpdate(context, PADDING, padLen);
396396

@@ -444,7 +444,7 @@ PHP_HASH_API void PHP_HAVAL192Final(unsigned char *digest, PHP_HAVAL_CTX * conte
444444

445445
/* Pad out to 118 mod 128.
446446
*/
447-
index = (unsigned int) ((context->count[0] >> 3) & 0x3f);
447+
index = (unsigned int) ((context->count[0] >> 3) & 0x7f);
448448
padLen = (index < 118) ? (118 - index) : (246 - index);
449449
PHP_HAVALUpdate(context, PADDING, padLen);
450450

@@ -484,7 +484,7 @@ PHP_HASH_API void PHP_HAVAL224Final(unsigned char *digest, PHP_HAVAL_CTX * conte
484484

485485
/* Pad out to 118 mod 128.
486486
*/
487-
index = (unsigned int) ((context->count[0] >> 3) & 0x3f);
487+
index = (unsigned int) ((context->count[0] >> 3) & 0x7f);
488488
padLen = (index < 118) ? (118 - index) : (246 - index);
489489
PHP_HAVALUpdate(context, PADDING, padLen);
490490

@@ -525,7 +525,7 @@ PHP_HASH_API void PHP_HAVAL256Final(unsigned char *digest, PHP_HAVAL_CTX * conte
525525

526526
/* Pad out to 118 mod 128.
527527
*/
528-
index = (unsigned int) ((context->count[0] >> 3) & 0x3f);
528+
index = (unsigned int) ((context->count[0] >> 3) & 0x7f);
529529
padLen = (index < 118) ? (118 - index) : (246 - index);
530530
PHP_HAVALUpdate(context, PADDING, padLen);
531531

ext/hash/tests/bug70312.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Bug #70312 HAVAL gives wrong hashes in specific cases
3+
--SKIPIF--
4+
<?php if(!extension_loaded("hash")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
var_dump(hash('haval128,5', '1234567890123456789012345678901234567890123456789012345678901234'));
8+
var_dump(hash('haval160,5', '1234567890123456789012345678901234567890123456789012345678901234'));
9+
var_dump(hash('haval192,5', '1234567890123456789012345678901234567890123456789012345678901234'));
10+
var_dump(hash('haval224,5', '1234567890123456789012345678901234567890123456789012345678901234'));
11+
var_dump(hash('haval256,5', '1234567890123456789012345678901234567890123456789012345678901234'));
12+
?>
13+
--EXPECTF--
14+
string(32) "f3f0d23819b87228b4b70ee350afaa9d"
15+
string(40) "aded6485e137f11d7292212ba3fa961714df0564"
16+
string(48) "e53da2b16269fe732e9a898a96707a9f28404d7333b02286"
17+
string(56) "c574fb307f0817b514b9bb2e7c4bfaffb7ad667aca3c8b523fefcf10"
18+
string(64) "fb73c19300b14d5cb393d929bf005e6c2d459a4c9c009e9813af1d2d3637ee8f"

0 commit comments

Comments
 (0)