diff --git a/tests/MCryptCompatTest.php b/tests/MCryptCompatTest.php index 2466157..cb7534e 100644 --- a/tests/MCryptCompatTest.php +++ b/tests/MCryptCompatTest.php @@ -836,26 +836,40 @@ public function testOldMcryptNoIVWarning() phpseclib_mcrypt_helper_old('rijndael-128', $key, $data, 'cbc', $iv, 'encrypt'); } - public function testOldMcryptNoIV() + public function testOldMcryptShortIVWarning() { $key = 'key'; $data = 'data'; $iv = 'iv'; - $result = @phpseclib_mcrypt_helper_old('rijndael-128', $key, $data, 'cbc', $iv, 'encrypt'); + $this->setExpectedException('PHPUnit_Framework_Error_Warning', 'mcrypt_encrypt(): The IV parameter must be as long as the blocksize'); - $this->assertEquals('69c48f0bce2c81abd64bbab839080574', bin2hex($result)); + phpseclib_mcrypt_helper_old('rijndael-128', $key, $data, 'cbc', $iv, 'encrypt'); } - public function testOldMcryptShortIVWarning() + public function testOldMcryptShortIV() { $key = 'key'; $data = 'data'; $iv = 'iv'; - $this->setExpectedException('PHPUnit_Framework_Error_Warning', 'mcrypt_encrypt(): The IV parameter must be as long as the blocksize'); + $result = @phpseclib_mcrypt_helper_old('rijndael-128', $key, $data, 'cbc', $iv, 'encrypt'); - phpseclib_mcrypt_helper_old('rijndael-128', $key, $data, 'cbc', $iv, 'encrypt'); + $this->assertEquals('69c48f0bce2c81abd64bbab839080574', bin2hex($result)); + } + + public function testOldMcryptNoIV() + { + $key = str_pad($key, $length, "\0"); + $data = 'data'; + $iv = null; + + $result = @phpseclib_mcrypt_helper_old('rijndael-128', $key, $data, 'cbc', $iv, 'encrypt'); + + // this yields the same result that testOldMcryptShortIV() yields. when the IV is invalid it's assumed to be all null bytes, + // whilst a key that's not the right length is either null padded or truncated as appropriate + + $this->assertEquals('69c48f0bce2c81abd64bbab839080574', bin2hex($result)); } public function providerForIVSizeChecks()