mirror of
https://github.com/danog/phpseclib.git
synced 2024-12-04 18:48:24 +01:00
f6e0c4b506
aside from the addition of OpenSSL support a few other changes have been included: - setEngine(), as added by petrich, is depricated (not that it was ever in trunk to begin with) it has been replaced with isValidEngine() and setPreferredEngine(). - replace _generate_xor() with increment_str() _increment_str() had extra functionality that wasn't being used. ie. it could concatenate multiple successive string increments to one another automatically. but not only was that functionality not used - it also made the function less versatile. _increment_str() can be used more easily for iterative brute forcing (for example) - rename Crypt_Base::_stringShift to Crypt_Base::_string_shift (for consistency) - more expansive unit test coverage
69 lines
2.8 KiB
PHP
69 lines
2.8 KiB
PHP
<?php
|
|
/**
|
|
* @author Andreas Fischer <bantu@phpbb.com>
|
|
* @copyright MMXIII Andreas Fischer
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
|
*/
|
|
|
|
require_once 'Crypt/DES.php';
|
|
|
|
// the AES tests establish the correctness of the modes of operation. this test is inteded to establish the consistency of
|
|
// key and iv padding between the multiple engines
|
|
class Unit_Crypt_DES_TestCase extends PhpseclibTestCase
|
|
{
|
|
public function testEncryptPadding()
|
|
{
|
|
$des = new Crypt_DES(CRYPT_MODE_CBC);
|
|
$des->setKey('d');
|
|
$des->setIV('d');
|
|
|
|
$des->setPreferredEngine(CRYPT_MODE_INTERNAL);
|
|
$internal = $des->encrypt('d');
|
|
|
|
$des->setPreferredEngine(CRYPT_MODE_MCRYPT);
|
|
if ($des->getEngine() == CRYPT_MODE_MCRYPT) {
|
|
$mcrypt = $des->encrypt('d');
|
|
$this->assertEquals($internal, $mcrypt, 'Failed asserting that the internal and mcrypt engines produce identical results');
|
|
} else {
|
|
self::markTestSkipped('Unable to initialize mcrypt engine');
|
|
}
|
|
|
|
$des->setPreferredEngine(CRYPT_MODE_OPENSSL);
|
|
if ($des->getEngine() == CRYPT_MODE_OPENSSL) {
|
|
$openssl = $des->encrypt('d');
|
|
$this->assertEquals($internal, $openssl, 'Failed asserting that the internal and OpenSSL engines produce identical results');
|
|
} else {
|
|
self::markTestSkipped('Unable to initialize OpenSSL engine');
|
|
}
|
|
}
|
|
|
|
// phpseclib null pads ciphertext's if they're not long enough and you're in ecb / cbc mode. this silent failure mode is consistent
|
|
// with mcrypt's behavior. maybe throwing an exception would be better but whatever. this test is more intended to establish consistent
|
|
// behavior between the various engine's
|
|
public function testDecryptPadding()
|
|
{
|
|
$des = new Crypt_DES(CRYPT_MODE_CBC);
|
|
// when the key and iv are not specified they should be null padded
|
|
//$des->setKey();
|
|
//$des->setIV();
|
|
|
|
$des->setPreferredEngine(CRYPT_MODE_INTERNAL);
|
|
$internal = $des->decrypt('d');
|
|
|
|
$des->setPreferredEngine(CRYPT_MODE_MCRYPT);
|
|
if ($des->getEngine() == CRYPT_MODE_MCRYPT) {
|
|
$mcrypt = $des->decrypt('d');
|
|
$this->assertEquals($internal, $mcrypt, 'Failed asserting that the internal and mcrypt engines produce identical results');
|
|
} else {
|
|
self::markTestSkipped('Unable to initialize mcrypt engine');
|
|
}
|
|
|
|
$des->setPreferredEngine(CRYPT_MODE_OPENSSL);
|
|
if ($des->getEngine() == CRYPT_MODE_OPENSSL) {
|
|
$openssl = $des->decrypt('d');
|
|
$this->assertEquals($internal, $openssl, 'Failed asserting that the internal and OpenSSL engines produce identical results');
|
|
} else {
|
|
self::markTestSkipped('Unable to initialize OpenSSL engine');
|
|
}
|
|
}
|
|
} |