1
0
mirror of https://github.com/danog/phpseclib.git synced 2024-11-30 04:39:21 +01:00

Use protected iv_size attribute to store required IV size

This commit is contained in:
danogentili 2017-02-11 16:24:47 +03:00
parent 12dc23d9ab
commit e2f91cca38

View File

@ -135,6 +135,14 @@ abstract class SymmetricKey
*/ */
protected $block_size = 16; protected $block_size = 16;
/**
* The IV Length of the block cipher
*
* @var int
* @access private
*/
protected $iv_size = 16;
/** /**
* The Key * The Key
* *
@ -470,11 +478,12 @@ abstract class SymmetricKey
case self::MODE_CBC: case self::MODE_CBC:
$this->paddable = true; $this->paddable = true;
break; break;
case self::MODE_IGE:
$this->iv_size = $this->block_size*2;
case self::MODE_CTR: case self::MODE_CTR:
case self::MODE_CFB: case self::MODE_CFB:
case self::MODE_OFB: case self::MODE_OFB:
case self::MODE_STREAM: case self::MODE_STREAM:
case self::MODE_IGE:
$this->paddable = false; $this->paddable = false;
break; break;
default: default:
@ -505,8 +514,8 @@ abstract class SymmetricKey
throw new \InvalidArgumentException('This algorithm does not use an IV.'); throw new \InvalidArgumentException('This algorithm does not use an IV.');
} }
if (strlen($iv) != $this->block_size*($this->mode === self::MODE_IGE ? 2 : 1)) { if (strlen($iv) != $this->iv_size) {
throw new \LengthException('Received initialization vector of size ' . strlen($iv) . ', but size ' . $this->block_size*($this->mode === self::MODE_IGE ? 2 : 1). ' is required'); throw new \LengthException('Received initialization vector of size ' . strlen($iv) . ', but size ' . $this->iv_size. ' is required');
} }