Skip to content

Commit 5ccf766

Browse files
committed
more unit tests
1 parent 67d04c3 commit 5ccf766

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/MCryptCompatTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,39 @@ public function testBadParamsMcryptCompat()
3535
{
3636
phpseclib_mcrypt_encrypt('rijndael-128', 'abc', 'asdf', 'cbc', 'zz');
3737
}
38+
39+
/**
40+
* in theory, in continuous mode, you ought to be able to encrypt / decrypt successive substring's of a
41+
* cipher/plain-text and get the same result as you would if you did the whole cipher/plain-text in one
42+
* go but with mcrypt you can't whereas with mcrypt_compat you can. imho this is a bug in mcrypt and it's
43+
* not behavior that mcrypt_compat emulates. testMcryptNCFB() and testPhpseclibNCFB() demonstrate
44+
*/
45+
public function ncfbHelper($prefix)
46+
{
47+
$td = call_user_func($prefix . 'mcrypt_module_open', 'rijndael-128', '', 'ncfb', '');
48+
call_user_func($prefix . 'mcrypt_generic_init', $td, str_repeat('a', 16), str_repeat('a', 16));
49+
$blocks = array(10, 5, 17, 16);
50+
$v1 = $v2 = '';
51+
foreach ($blocks as $block) {
52+
$v1.= call_user_func($prefix . 'mdecrypt_generic', $td, str_repeat('c', $block));
53+
$v2.= str_repeat('c', $block);
54+
}
55+
call_user_func($prefix . 'mcrypt_generic_deinit', $td);
56+
call_user_func($prefix . 'mcrypt_generic_init', $td, str_repeat('a', 16), str_repeat('a', 16));
57+
$v2 = call_user_func($prefix . 'mdecrypt_generic', $td, $v2);
58+
59+
return array($v1, $v2);
60+
}
61+
62+
public function testMcryptNCFB()
63+
{
64+
list($v1, $v2) = $this->ncfbHelper('');
65+
$this->assertNotSame($v1, $v2);
66+
}
67+
68+
public function testPhpseclibNCFB()
69+
{
70+
list($v1, $v2) = $this->ncfbHelper('phpseclib_');
71+
$this->assertSame($v1, $v2);
72+
}
3873
}

0 commit comments

Comments
 (0)