xref: /PHP-5.3/ext/mcrypt/tests/bug37595.phpt (revision 1f655451)
1--TEST--
2Bug #37595 (mcrypt_generic calculates data length in wrong way)
3--SKIPIF--
4<?php if (!extension_loaded("mcrypt")) print "skip"; ?>
5--FILE--
6<?php
7
8$cipher_alg = MCRYPT_BLOWFISH;
9$skey = array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
10$key='';
11foreach($skey as $t) {
12	    $key .= chr($t);
13		}
14
15$sstr = array(1,2,3,4,5,6,7,8);
16$iv='';
17foreach($sstr as $s) {
18    $iv .= chr($s);
19}
20
21$str = "12345678";
22
23$td = mcrypt_module_open(MCRYPT_BLOWFISH,'',MCRYPT_MODE_CBC,'');
24
25$data = Array(
26	'12345678',
27	'123456789',
28	"\x001234567",
29	'',
30	'1234567812345678',
31	'12345678123456789'
32	);
33
34foreach ($data as $val) {
35	mcrypt_generic_init($td, $key, $iv);
36	$enc = mcrypt_generic($td, $val);
37
38	mcrypt_generic_deinit($td);
39
40	mcrypt_generic_init($td, $key, $iv);
41	var_dump($dec = @mdecrypt_generic($td, $enc));
42}
43
44mcrypt_module_close($td);
45
46echo "Done\n";
47?>
48--EXPECTF--
49string(8) "12345678"
50string(16) "123456789�������"
51string(8) "�1234567"
52
53Warning: mcrypt_generic(): An empty string was passed in %s on line %d
54bool(false)
55string(16) "1234567812345678"
56string(24) "12345678123456789�������"
57Done
58