Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
terrafrost committed Feb 22, 2024
1 parent a7cba67 commit a2985ce
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions tests/MCryptCompatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit a2985ce

Please sign in to comment.