Skip to content

Commit eac8166

Browse files
Grundiknikic
authored andcommitted
Fix bug #73127
gost-crypto hash was incorrect if input data contained long 0xFF sequence, due to a carry-propagation bug.
1 parent 9450e23 commit eac8166

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ PHP NEWS
3434
. Fixed bug #69860 (php-fpm process accounting is broken with keepalive).
3535
(Denis Yeldandi)
3636

37+
- Hash:
38+
. Fixed bug #73127 (gost-crypto hash incorrect if input data contains long
39+
0xFF sequence). (Grundik)
40+
3741
- GD:
3842
. Fixed bug #74031 (ReflectionFunction for imagepng is missing last two
3943
parameters). (finwe)

ext/hash/hash_gost.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,13 @@ static inline void Gost(PHP_GOST_CTX *context, php_hash_uint32 data[8])
227227
static inline void GostTransform(PHP_GOST_CTX *context, const unsigned char input[32])
228228
{
229229
int i, j;
230-
php_hash_uint32 data[8], temp = 0, save = 0;
230+
php_hash_uint32 data[8], temp = 0;
231231

232232
for (i = 0, j = 0; i < 8; ++i, j += 4) {
233233
data[i] = ((php_hash_uint32) input[j]) | (((php_hash_uint32) input[j + 1]) << 8) |
234234
(((php_hash_uint32) input[j + 2]) << 16) | (((php_hash_uint32) input[j + 3]) << 24);
235-
save = context->state[i + 8];
236235
context->state[i + 8] += data[i] + temp;
237-
temp = ((context->state[i + 8] < data[i]) || (context->state[i + 8] < save)) ? 1 : 0;
236+
temp = context->state[i + 8] < data[i] ? 1 : (context->state[i + 8] == data[i] ? temp : 0);
238237
}
239238

240239
Gost(context, data);

ext/hash/tests/bug73127.phpt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
Bug #73127 (gost-crypto hash incorrect if input data contains long 0xFF sequence)
3+
--FILE--
4+
<?php // $Id$
5+
6+
$test1 = str_repeat("\xFF", 40);
7+
$test2 = str_repeat("\x00", 40);
8+
echo hash('gost-crypto', $test1),
9+
"\n",
10+
hash('gost', $test1),
11+
"\n",
12+
hash('gost-crypto', $test2),
13+
"\n",
14+
hash('gost', $test2),
15+
"\n",
16+
hash('gost-crypto', ''),
17+
"\n",
18+
hash('gost', '')
19+
;
20+
?>
21+
--EXPECT--
22+
231d8bb980d3faa30fee6ec475df5669cf6c24bbce22f46d6737470043a99f8e
23+
9eaf96ba62f90fae6707f1d4274d1a9d6680f5a121d4387815aa3a6ec42439c5
24+
bbf1f3179409c853cd3e396d67b0e10a266c218a4fd19f149c39aa4f6d37a007
25+
a0be0b90fea5a5b50c90c9429d07bb98fa0c06f0c30210e94c7d80c3125c67ac
26+
981e5f3ca30c841487830f84fb433e13ac1101569b9c13584ac483234cd656c0
27+
ce85b99cc46752fffee35cab9a7b0278abb4c2d2055cff685af4912c49490f8d

0 commit comments

Comments
 (0)