1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
<?php
/**
* @author Andreas Fischer <bantu@phpbb.com>
* @copyright MMXIII Andreas Fischer
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/
use phpseclib3\Crypt\DES;
use phpseclib3\Tests\PhpseclibTestCase;
// 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_DESTest extends PhpseclibTestCase
{
public function testEncryptPadding()
{
$engines = [
'PHP',
'Eval',
'mcrypt',
'OpenSSL',
];
foreach ($engines as $engine) {
$des = new DES('cbc');
$des->setKey("d\0\0\0\0\0\0\0");
$des->setIV("d\0\0\0\0\0\0\0");
if (!$des->isValidEngine($engine)) {
self::markTestSkipped("Unable to initialize $engine engine");
}
$des->setPreferredEngine($engine);
$result = pack('H*', '3e7613642049af1e');
$test = $des->encrypt('d');
$this->assertEquals($result, $test, "Failed asserting that the $engine engine produced the correct result");
}
}
public function testDecryptPadding()
{
$engines = [
'PHP',
'Eval',
'mcrypt',
'OpenSSL',
];
foreach ($engines as $engine) {
$des = new DES('cbc');
$des->setKey("\0\0\0\0\0\0\0\0");
$des->setIV("\0\0\0\0\0\0\0\0");
$des->disablePadding();
if (!$des->isValidEngine($engine)) {
self::markTestSkipped("Unable to initialize $engine engine");
}
$des->setPreferredEngine($engine);
$result = pack('H*', '79b305d1ce555221');
$test = $des->decrypt("d\0\0\0\0\0\0\0");
$this->assertEquals($result, $test, "Failed asserting that the $engine engine produced the correct result");
}
}
}
|