mirror of
https://github.com/phpseclib/phpseclib.git
synced 2024-12-27 19:54:57 +00:00
Crypt/Base: fix continuous mode in CBC / decryption / OpenSSL
This commit is contained in:
parent
b972a4b36d
commit
bfd467532b
@ -746,10 +746,13 @@ class Crypt_Base
|
|||||||
return !defined('OPENSSL_RAW_DATA') ? substr($result, 0, -$this->block_size) : $result;
|
return !defined('OPENSSL_RAW_DATA') ? substr($result, 0, -$this->block_size) : $result;
|
||||||
case CRYPT_MODE_CBC:
|
case CRYPT_MODE_CBC:
|
||||||
$result = openssl_encrypt($plaintext, $this->cipher_name_openssl, $this->key, $this->openssl_options, $this->encryptIV);
|
$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) {
|
if ($this->continuousBuffer) {
|
||||||
$this->encryptIV = substr($result, -$this->block_size);
|
$this->encryptIV = substr($result, -$this->block_size);
|
||||||
}
|
}
|
||||||
return !defined('OPENSSL_RAW_DATA') ? substr($result, 0, -$this->block_size) : $result;
|
return $result;
|
||||||
case CRYPT_MODE_CTR:
|
case CRYPT_MODE_CTR:
|
||||||
return $this->_openssl_ctr_process($plaintext, $this->encryptIV, $this->enbuffer);
|
return $this->_openssl_ctr_process($plaintext, $this->encryptIV, $this->enbuffer);
|
||||||
case CRYPT_MODE_CFB:
|
case CRYPT_MODE_CFB:
|
||||||
@ -1052,10 +1055,13 @@ class Crypt_Base
|
|||||||
if (!defined('OPENSSL_RAW_DATA')) {
|
if (!defined('OPENSSL_RAW_DATA')) {
|
||||||
$padding = str_repeat(chr($this->block_size), $this->block_size) ^ substr($ciphertext, -$this->block_size);
|
$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);
|
$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);
|
$plaintext = openssl_decrypt($ciphertext, $this->cipher_name_openssl, $this->key, $this->openssl_options, $this->decryptIV);
|
||||||
if ($this->continuousBuffer) {
|
if ($this->continuousBuffer) {
|
||||||
$this->decryptIV = substr($ciphertext, -$this->block_size);
|
$this->decryptIV = substr($ciphertext, -$offset, $this->block_size);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CRYPT_MODE_CTR:
|
case CRYPT_MODE_CTR:
|
||||||
|
Loading…
Reference in New Issue
Block a user