Skip to content

Commit

Permalink
Merge branch '1.0' into 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
terrafrost committed Mar 27, 2022
2 parents 05b5db2 + e38b76f commit 8a9f9f0
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions lib/mcrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
use phpseclib3\Crypt\RC4;
use phpseclib3\Crypt\Random;
use phpseclib3\Crypt\Common\SymmetricKey as Base;
use phpseclib3\Common\Functions\Strings;

if (!defined('MCRYPT_MODE_ECB')) {
/**#@+
Expand Down Expand Up @@ -107,6 +108,20 @@
}

if (!function_exists('phpseclib_mcrypt_list_algorithms')) {
/**
* Returns the string length
*
* PHP8.1 emits a warning if $string isn't a string
*
* @param string $string
* @return int
* @access private
*/
function phpseclib_strlen($string)
{
return Strings::is_stringable($string) ? strlen($string) : 0;
}

/**
* Sets the key
*
Expand Down Expand Up @@ -182,7 +197,7 @@ function phpseclib_set_iv(Base $td, $iv)
{
if ($td->getMode() != 'ecb' && $td->getMode() != 'stream') {
$length = $td->getBlockLength() >> 3;
$iv = str_pad(substr($iv, 0, $length), $length, "\0");
$iv = str_pad(substr(Strings::is_stringable($iv) ? $iv : '', 0, $length), $length, "\0");
$td->setIV($iv);
}
}
Expand Down Expand Up @@ -647,10 +662,10 @@ function phpseclib_mcrypt_enc_self_test(Base $td)
function phpseclib_mcrypt_generic_init(Base $td, $key, $iv)
{
$iv_size = phpseclib_mcrypt_enc_get_iv_size($td);
if (strlen($iv) != $iv_size && $td->getMode() != 'ecb') {
trigger_error('mcrypt_generic_init(): Iv size incorrect; supplied length: ' . strlen($iv) . ', needed: ' . $iv_size, E_USER_WARNING);
if (phpseclib_strlen($iv) != $iv_size && $td->getMode() != 'ecb') {
trigger_error('mcrypt_generic_init(): Iv size incorrect; supplied length: ' . phpseclib_strlen($iv) . ', needed: ' . $iv_size, E_USER_WARNING);
}
if (!strlen($key)) {
if (!phpseclib_strlen($key)) {
trigger_error('mcrypt_generic_init(): Key size is 0', E_USER_WARNING);
return -3;
}
Expand Down

0 comments on commit 8a9f9f0

Please sign in to comment.