AES: update unit tests

This commit is contained in:
terrafrost 2014-10-15 17:59:48 -05:00
parent c8b55b8929
commit e7708b0d20
3 changed files with 9 additions and 9 deletions

View File

@ -9,9 +9,8 @@ class Unit_Crypt_AES_InternalTest extends Unit_Crypt_AES_TestCase
{ {
static public function setUpBeforeClass() static public function setUpBeforeClass()
{ {
parent::setUpBeforeClass(); self::$engine = CRYPT_MODE_INTERNAL;
self::ensureConstant('CRYPT_AES_MODE', CRYPT_AES_MODE_INTERNAL); parent::setUpBeforeClass();
self::ensureConstant('CRYPT_RIJNDAEL_MODE', CRYPT_RIJNDAEL_MODE_INTERNAL);
} }
} }

View File

@ -13,9 +13,8 @@ class Unit_Crypt_AES_McryptTest extends Unit_Crypt_AES_TestCase
self::markTestSkipped('mcrypt extension is not available.'); self::markTestSkipped('mcrypt extension is not available.');
} }
parent::setUpBeforeClass(); self::$engine = CRYPT_MODE_MCRYPT;
self::ensureConstant('CRYPT_AES_MODE', CRYPT_AES_MODE_MCRYPT); parent::setUpBeforeClass();
self::ensureConstant('CRYPT_RIJNDAEL_MODE', CRYPT_RIJNDAEL_MODE_MCRYPT);
} }
} }

View File

@ -9,12 +9,11 @@ require_once 'Crypt/AES.php';
abstract class Unit_Crypt_AES_TestCase extends PhpseclibTestCase abstract class Unit_Crypt_AES_TestCase extends PhpseclibTestCase
{ {
protected static $engine;
static public function setUpBeforeClass() static public function setUpBeforeClass()
{ {
parent::setUpBeforeClass(); parent::setUpBeforeClass();
self::reRequireFile('Crypt/Rijndael.php');
self::reRequireFile('Crypt/AES.php');
} }
/** /**
@ -64,6 +63,7 @@ abstract class Unit_Crypt_AES_TestCase extends PhpseclibTestCase
public function testEncryptDecryptWithContinuousBuffer($mode, $plaintext, $iv, $key) public function testEncryptDecryptWithContinuousBuffer($mode, $plaintext, $iv, $key)
{ {
$aes = new Crypt_AES(constant($mode)); $aes = new Crypt_AES(constant($mode));
$aes->setEngine(self::$engine);
$aes->enableContinuousBuffer(); $aes->enableContinuousBuffer();
$aes->setIV($iv); $aes->setIV($iv);
$aes->setKey($key); $aes->setKey($key);
@ -85,6 +85,7 @@ abstract class Unit_Crypt_AES_TestCase extends PhpseclibTestCase
// https://web.archive.org/web/20070209120224/http://fp.gladman.plus.com/cryptography_technology/rijndael/aesdvec.zip // https://web.archive.org/web/20070209120224/http://fp.gladman.plus.com/cryptography_technology/rijndael/aesdvec.zip
$aes = new Crypt_Rijndael(); $aes = new Crypt_Rijndael();
$aes->setEngine(self::$engine);
$aes->disablePadding(); $aes->disablePadding();
$aes->setKey(pack('H*', '2b7e151628aed2a6abf7158809cf4f3c762e7160')); // 160-bit key. Valid in Rijndael. $aes->setKey(pack('H*', '2b7e151628aed2a6abf7158809cf4f3c762e7160')); // 160-bit key. Valid in Rijndael.
$ciphertext = $aes->encrypt(pack('H*', '3243f6a8885a308d313198a2e0370734')); $ciphertext = $aes->encrypt(pack('H*', '3243f6a8885a308d313198a2e0370734'));
@ -99,6 +100,7 @@ abstract class Unit_Crypt_AES_TestCase extends PhpseclibTestCase
// same as the above - just with a different ciphertext // same as the above - just with a different ciphertext
$aes = new Crypt_AES(); $aes = new Crypt_AES();
$aes->setEngine(self::$engine);
$aes->disablePadding(); $aes->disablePadding();
$aes->setKey(pack('H*', '2b7e151628aed2a6abf7158809cf4f3c762e7160')); // 160-bit key. AES should null pad to 192-bits $aes->setKey(pack('H*', '2b7e151628aed2a6abf7158809cf4f3c762e7160')); // 160-bit key. AES should null pad to 192-bits
$ciphertext = $aes->encrypt(pack('H*', '3243f6a8885a308d313198a2e0370734')); $ciphertext = $aes->encrypt(pack('H*', '3243f6a8885a308d313198a2e0370734'));