mirror of
https://github.com/phpseclib/phpseclib.git
synced 2024-11-17 18:55:13 +00:00
Merge branch '1.0' into 2.0
This commit is contained in:
commit
6d3c04ef4d
@ -706,10 +706,13 @@ abstract class Base
|
||||
return !defined('OPENSSL_RAW_DATA') ? substr($result, 0, -$this->block_size) : $result;
|
||||
case self::MODE_CBC:
|
||||
$result = openssl_encrypt($plaintext, $this->cipher_name_openssl, $this->key, $this->openssl_options, $this->encryptIV);
|
||||
if (!defined('OPENSSL_RAW_DATA')) {
|
||||
$result = substr($result, 0, -$this->block_size);
|
||||
}
|
||||
if ($this->continuousBuffer) {
|
||||
$this->encryptIV = substr($result, -$this->block_size);
|
||||
}
|
||||
return !defined('OPENSSL_RAW_DATA') ? substr($result, 0, -$this->block_size) : $result;
|
||||
return $result;
|
||||
case self::MODE_CTR:
|
||||
return $this->_openssl_ctr_process($plaintext, $this->encryptIV, $this->enbuffer);
|
||||
case self::MODE_CFB:
|
||||
@ -1012,10 +1015,13 @@ abstract class Base
|
||||
if (!defined('OPENSSL_RAW_DATA')) {
|
||||
$padding = str_repeat(chr($this->block_size), $this->block_size) ^ substr($ciphertext, -$this->block_size);
|
||||
$ciphertext.= substr(openssl_encrypt($padding, $this->cipher_name_openssl_ecb, $this->key, true), 0, $this->block_size);
|
||||
$offset = 2 * $this->block_size;
|
||||
} else {
|
||||
$offset = $this->block_size;
|
||||
}
|
||||
$plaintext = openssl_decrypt($ciphertext, $this->cipher_name_openssl, $this->key, $this->openssl_options, $this->decryptIV);
|
||||
if ($this->continuousBuffer) {
|
||||
$this->decryptIV = substr($ciphertext, -$this->block_size);
|
||||
$this->decryptIV = substr($ciphertext, -$offset, $this->block_size);
|
||||
}
|
||||
break;
|
||||
case self::MODE_CTR:
|
||||
|
@ -371,4 +371,20 @@ abstract class Unit_Crypt_AES_TestCase extends PhpseclibTestCase
|
||||
$this->assertSame($ciphertext, 'fd4250c0d234aa7e1aa592820aa8406b');
|
||||
$this->assertSame($aes->getKeyLength(), 256);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group github938
|
||||
*/
|
||||
public function testContinuousBuffer()
|
||||
{
|
||||
$aes = new Crypt_AES();
|
||||
$aes->disablePadding();
|
||||
$aes->enableContinuousBuffer();
|
||||
$aes->setIV(pack('H*', '0457bdb4a6712986688349a29eb82535'));
|
||||
$aes->setKey(pack('H*', '00d596e2c8189b2592fac358e7396ad2'));
|
||||
$aes->decrypt(pack('H*', '9aa234ea7c750a8109a0f32d768b964e'));
|
||||
$plaintext = $aes->decrypt(pack('H*', '0457bdb4a6712986688349a29eb82535'));
|
||||
$expected = pack('H*', '6572617574689e1be8d2d8d43c594cf3');
|
||||
$this->assertSame($plaintext, $expected);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user