mirror of
https://github.com/phpseclib/phpseclib.git
synced 2025-02-12 16:48:27 +00:00
Tests (DES): disable padding for decryption test
When padding is enabled $des->decrypt() will return false with ciphertext's of invalid length. Which makes sense. Null padding doesn't work when padding is enabled because 0 isn't a valid PKCS7 padding character (has to be between 1 and the block_length, inclusive).
This commit is contained in:
parent
b1fdbd6bbd
commit
c8281dd4a3
@ -18,12 +18,18 @@ class Unit_Crypt_DES_TestCase extends PhpseclibTestCase
|
|||||||
$des->setIV('d');
|
$des->setIV('d');
|
||||||
|
|
||||||
$des->setPreferredEngine(CRYPT_ENGINE_INTERNAL);
|
$des->setPreferredEngine(CRYPT_ENGINE_INTERNAL);
|
||||||
|
|
||||||
|
$result = pack('H*', '3e7613642049af1e');
|
||||||
|
|
||||||
$internal = $des->encrypt('d');
|
$internal = $des->encrypt('d');
|
||||||
|
if (!$this->assertEquals($result, $internal)) {
|
||||||
|
$this->assertEquals($result, $internal, 'Failed asserting that the internal engine produced the correct result');
|
||||||
|
}
|
||||||
|
|
||||||
$des->setPreferredEngine(CRYPT_ENGINE_MCRYPT);
|
$des->setPreferredEngine(CRYPT_ENGINE_MCRYPT);
|
||||||
if ($des->getEngine() == CRYPT_ENGINE_MCRYPT) {
|
if ($des->getEngine() == CRYPT_ENGINE_MCRYPT) {
|
||||||
$mcrypt = $des->encrypt('d');
|
$mcrypt = $des->encrypt('d');
|
||||||
$this->assertEquals($internal, $mcrypt, 'Failed asserting that the internal and mcrypt engines produce identical results');
|
$this->assertEquals($result, $mcrypt, 'Failed asserting that the mcrypt engine produced the correct result');
|
||||||
} else {
|
} else {
|
||||||
self::markTestSkipped('Unable to initialize mcrypt engine');
|
self::markTestSkipped('Unable to initialize mcrypt engine');
|
||||||
}
|
}
|
||||||
@ -31,7 +37,7 @@ class Unit_Crypt_DES_TestCase extends PhpseclibTestCase
|
|||||||
$des->setPreferredEngine(CRYPT_ENGINE_OPENSSL);
|
$des->setPreferredEngine(CRYPT_ENGINE_OPENSSL);
|
||||||
if ($des->getEngine() == CRYPT_ENGINE_OPENSSL) {
|
if ($des->getEngine() == CRYPT_ENGINE_OPENSSL) {
|
||||||
$openssl = $des->encrypt('d');
|
$openssl = $des->encrypt('d');
|
||||||
$this->assertEquals($internal, $openssl, 'Failed asserting that the internal and OpenSSL engines produce identical results');
|
$this->assertEquals($result, $openssl, 'Failed asserting that the OpenSSL engine produced the correct result');
|
||||||
} else {
|
} else {
|
||||||
self::markTestSkipped('Unable to initialize OpenSSL engine');
|
self::markTestSkipped('Unable to initialize OpenSSL engine');
|
||||||
}
|
}
|
||||||
@ -43,6 +49,7 @@ class Unit_Crypt_DES_TestCase extends PhpseclibTestCase
|
|||||||
public function testDecryptPadding()
|
public function testDecryptPadding()
|
||||||
{
|
{
|
||||||
$des = new Crypt_DES(CRYPT_MODE_CBC);
|
$des = new Crypt_DES(CRYPT_MODE_CBC);
|
||||||
|
$des->disablePadding();
|
||||||
// when the key and iv are not specified they should be null padded
|
// when the key and iv are not specified they should be null padded
|
||||||
//$des->setKey();
|
//$des->setKey();
|
||||||
//$des->setIV();
|
//$des->setIV();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user