2013-01-03 16:48:14 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2014-02-15 18:57:49 +00:00
|
|
|
* @author Andreas Fischer <bantu@phpbb.com>
|
|
|
|
* @copyright MMXIII Andreas Fischer
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
2013-01-03 16:48:14 +00:00
|
|
|
*/
|
|
|
|
|
2014-06-01 19:13:20 +00:00
|
|
|
class Unit_Crypt_AES_ContinuousBufferTest extends Unit_Crypt_AES_TestCase
|
2013-01-03 16:48:14 +00:00
|
|
|
{
|
2014-02-15 18:57:49 +00:00
|
|
|
// String intented
|
|
|
|
protected $modes = array(
|
|
|
|
'CRYPT_AES_MODE_CTR',
|
|
|
|
'CRYPT_AES_MODE_OFB',
|
|
|
|
'CRYPT_AES_MODE_CFB',
|
|
|
|
);
|
2013-01-04 13:08:41 +00:00
|
|
|
|
2014-02-15 18:57:49 +00:00
|
|
|
protected $plaintexts = array(
|
|
|
|
'',
|
|
|
|
'12345678901234567', // https://github.com/phpseclib/phpseclib/issues/39
|
|
|
|
"\xDE\xAD\xBE\xAF",
|
|
|
|
':-):-):-):-):-):-)', // https://github.com/phpseclib/phpseclib/pull/43
|
|
|
|
);
|
2013-01-04 13:08:41 +00:00
|
|
|
|
2014-02-15 18:57:49 +00:00
|
|
|
protected $ivs = array(
|
|
|
|
'',
|
|
|
|
'test123',
|
|
|
|
);
|
2013-01-04 13:08:41 +00:00
|
|
|
|
2014-02-15 18:57:49 +00:00
|
|
|
protected $keys = array(
|
|
|
|
'',
|
|
|
|
':-8', // https://github.com/phpseclib/phpseclib/pull/43
|
|
|
|
'FOOBARZ',
|
|
|
|
);
|
2013-01-04 13:08:41 +00:00
|
|
|
|
2014-02-15 18:57:49 +00:00
|
|
|
/**
|
|
|
|
* Produces all combinations of test values.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function allCombinations()
|
|
|
|
{
|
|
|
|
$result = array();
|
2013-01-04 13:08:41 +00:00
|
|
|
|
2014-02-15 18:57:49 +00:00
|
|
|
// @codingStandardsIgnoreStart
|
|
|
|
foreach ($this->modes as $mode)
|
|
|
|
foreach ($this->plaintexts as $plaintext)
|
|
|
|
foreach ($this->ivs as $iv)
|
|
|
|
foreach ($this->keys as $key)
|
|
|
|
$result[] = array($mode, $plaintext, $iv, $key);
|
|
|
|
// @codingStandardsIgnoreEnd
|
2013-01-04 13:08:41 +00:00
|
|
|
|
2014-02-15 18:57:49 +00:00
|
|
|
return $result;
|
|
|
|
}
|
2013-01-04 13:08:41 +00:00
|
|
|
|
2014-02-15 18:57:49 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider allCombinations
|
|
|
|
*/
|
|
|
|
public function testEncryptDecrypt($mode, $plaintext, $iv, $key)
|
|
|
|
{
|
|
|
|
$aes = new Crypt_AES(constant($mode));
|
|
|
|
$aes->enableContinuousBuffer();
|
|
|
|
$aes->setIV($iv);
|
|
|
|
$aes->setKey($key);
|
2013-01-03 16:48:14 +00:00
|
|
|
|
2014-02-15 18:57:49 +00:00
|
|
|
$actual = '';
|
|
|
|
for ($i = 0, $strlen = strlen($plaintext); $i < $strlen; ++$i) {
|
|
|
|
$actual .= $aes->decrypt($aes->encrypt($plaintext[$i]));
|
|
|
|
}
|
2013-01-03 16:48:14 +00:00
|
|
|
|
2014-02-15 18:57:49 +00:00
|
|
|
$this->assertEquals($plaintext, $actual);
|
|
|
|
}
|
2013-01-03 16:48:14 +00:00
|
|
|
}
|