162 case self::MODE_3CBC:
164 $this->mode_3cbc =
true;
174 $this->des[0]->disablePadding();
175 $this->des[1]->disablePadding();
176 $this->des[2]->disablePadding();
180 parent::__construct(
$mode);
196 if (
$engine == self::ENGINE_OPENSSL) {
197 $this->cipher_name_openssl_ecb =
'des-ede3';
199 $this->cipher_name_openssl =
$mode ==
'ecb' ?
'des-ede3' :
'des-ede3-' .
$mode;
202 return parent::isValidEngine(
$engine);
218 if ($this->mode_3cbc) {
219 $this->des[0]->setIV(
$iv);
220 $this->des[1]->setIV(
$iv);
221 $this->des[2]->setIV(
$iv);
239 $this->key_length = 8;
242 $this->key_length = 16;
245 $this->key_length = 24;
248 parent::setKeyLength($length);
268 $length = $this->explicit_key_length ? $this->key_length : strlen(
$key);
270 $key = str_pad(substr(
$key, 0, 24), 24, chr(0));
273 $key = $length <= 16 ? substr_replace(
$key, substr(
$key, 0, 8), 16) : substr(
$key, 0, 24);
277 parent::setKey(
$key);
283 if ($this->mode_3cbc && $length > 8) {
284 $this->des[0]->setKey(substr(
$key, 0, 8));
285 $this->des[1]->setKey(substr(
$key, 8, 8));
286 $this->des[2]->setKey(substr(
$key, 16, 8));
304 if ($this->mode_3cbc && strlen($this->key) > 8) {
305 return $this->des[2]->encrypt(
308 $this->
_pad($plaintext)
314 return parent::encrypt($plaintext);
327 if ($this->mode_3cbc && strlen($this->key) > 8) {
332 str_pad($ciphertext, (strlen($ciphertext) + 7) & 0xFFFFFFF8,
"\0")
339 return parent::decrypt($ciphertext);
382 parent::enableContinuousBuffer();
383 if ($this->mode_3cbc) {
384 $this->des[0]->enableContinuousBuffer();
385 $this->des[1]->enableContinuousBuffer();
386 $this->des[2]->enableContinuousBuffer();
401 parent::disableContinuousBuffer();
402 if ($this->mode_3cbc) {
403 $this->des[0]->disableContinuousBuffer();
404 $this->des[1]->disableContinuousBuffer();
405 $this->des[2]->disableContinuousBuffer();
421 case strlen($this->key) <= 8:
422 $this->des_rounds = 1;
427 $this->des_rounds = 3;
430 if ($this->mode_3cbc) {
431 $this->des[0]->_setupKey();
432 $this->des[1]->_setupKey();
433 $this->des[2]->_setupKey();
455 if ($this->mode_3cbc) {
456 $this->des[0]->setPreferredEngine(
$engine);
457 $this->des[1]->setPreferredEngine(
$engine);
458 $this->des[2]->setPreferredEngine(
$engine);
461 return parent::setPreferredEngine(
$engine);
_setupKey()
Creates the key schedule.
const MODE_3CBC
Encrypt / decrypt using inner chaining.
const MODE_CBC3
Encrypt / decrypt using outer chaining.
disableContinuousBuffer()
Treat consecutive packets as if they are a discontinuous buffer.
decrypt($ciphertext)
Decrypts a message.
enableContinuousBuffer()
Treat consecutive "packets" as if they are a continuous buffer.
setKeyLength($length)
Sets the key length.
setKey($key)
Sets the key.
_openssl_translate_mode()
phpseclib <-> OpenSSL Mode Mapper
setPreferredEngine($engine)
Sets the internal crypt engine.
_unpad($text)
Unpads a string.
Pure-PHP implementations of keyed-hash message authentication codes (HMACs) and various cryptographic...
_pad($text)
Pads a string.
__construct($mode=Base::MODE_CBC)
Default Constructor.
encrypt($plaintext)
Encrypts a message.
const MODE_CBC
Encrypt / decrypt using the Code Book Chaining mode.
Pure-PHP implementation of Triple DES.
setIV($iv)
Sets the initialization vector.
isValidEngine($engine)
Test for engine validity.
Pure-PHP implementation of DES.