ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
phpseclib\Crypt\RC4 Class Reference
+ Inheritance diagram for phpseclib\Crypt\RC4:
+ Collaboration diagram for phpseclib\Crypt\RC4:

Public Member Functions

 __construct ()
 Default Constructor. More...
 
 isValidEngine ($engine)
 Test for engine validity. More...
 
 setIV ($iv)
 Dummy function. More...
 
 setKeyLength ($length)
 Sets the key length. More...
 
 encrypt ($plaintext)
 Encrypts a message. More...
 
 decrypt ($ciphertext)
 Decrypts a message. More...
 
 _encryptBlock ($in)
 Encrypts a block. More...
 
 _decryptBlock ($in)
 Decrypts a block. More...
 
 _setupKey ()
 Setup the key (expansion) More...
 
 _crypt ($text, $mode)
 Encrypts or decrypts a message. More...
 
- Public Member Functions inherited from phpseclib\Crypt\Base
 __construct ($mode=self::MODE_CBC)
 Default Constructor. More...
 
 setIV ($iv)
 Sets the initialization vector. More...
 
 setKeyLength ($length)
 Sets the key length. More...
 
 getKeyLength ()
 Returns the current key length in bits. More...
 
 getBlockLength ()
 Returns the current block length in bits. More...
 
 setKey ($key)
 Sets the key. More...
 
 setPassword ($password, $method='pbkdf2')
 Sets the password. More...
 
 encrypt ($plaintext)
 Encrypts a message. More...
 
 decrypt ($ciphertext)
 Decrypts a message. More...
 
 _openssl_ctr_process ($plaintext, &$encryptIV, &$buffer)
 OpenSSL CTR Processor. More...
 
 _openssl_ofb_process ($plaintext, &$encryptIV, &$buffer)
 OpenSSL OFB Processor. More...
 
 _openssl_translate_mode ()
 phpseclib <-> OpenSSL Mode Mapper More...
 
 enablePadding ()
 Pad "packets". More...
 
 disablePadding ()
 Do not pad packets. More...
 
 enableContinuousBuffer ()
 Treat consecutive "packets" as if they are a continuous buffer. More...
 
 disableContinuousBuffer ()
 Treat consecutive packets as if they are a discontinuous buffer. More...
 
 isValidEngine ($engine)
 Test for engine validity. More...
 
 setPreferredEngine ($engine)
 Sets the preferred crypt engine. More...
 
 getEngine ()
 Returns the engine currently being utilized. More...
 
 _setEngine ()
 Sets the engine as appropriate. More...
 
 _encryptBlock ($in)
 Encrypts a block. More...
 
 _decryptBlock ($in)
 Decrypts a block. More...
 
 _setupKey ()
 Setup the key (expansion) More...
 
 _setup ()
 Setup the self::ENGINE_INTERNAL $engine. More...
 
 _setupMcrypt ()
 Setup the self::ENGINE_MCRYPT $engine. More...
 
 _pad ($text)
 Pads a string. More...
 
 _unpad ($text)
 Unpads a string. More...
 
 _clearBuffers ()
 Clears internal buffers. More...
 
 _string_shift (&$string, $index=1)
 String Shift. More...
 
 _string_pop (&$string, $index=1)
 String Pop. More...
 
 _increment_str (&$var)
 Increment the current string. More...
 
 _setupInlineCrypt ()
 Setup the performance-optimized function for de/encrypt() More...
 
 _createInlineCryptFunction ($cipher_code)
 Creates the performance-optimized function for en/decrypt() More...
 
_getLambdaFunctions ()
 Holds the lambda_functions table (classwide) More...
 
 _hashInlineCryptFunction ($bytes)
 Generates a digest from $bytes. More...
 

Data Fields

const ENCRYPT = 0
 #+ @access private More...
 
const DECRYPT = 1
 
 $block_size = 0
 
 $key_length = 128
 
 $cipher_name_mcrypt = 'arcfour'
 
 $use_inline_crypt = false
 
 $key = "\0"
 
 $stream
 
- Data Fields inherited from phpseclib\Crypt\Base
const MODE_CTR = -1
 #+ @access public More...
 
const MODE_ECB = 1
 Encrypt / decrypt using the Electronic Code Book mode. More...
 
const MODE_CBC = 2
 Encrypt / decrypt using the Code Book Chaining mode. More...
 
const MODE_CFB = 3
 Encrypt / decrypt using the Cipher Feedback mode. More...
 
const MODE_OFB = 4
 Encrypt / decrypt using the Output Feedback mode. More...
 
const MODE_STREAM = 5
 Encrypt / decrypt using streaming mode. More...
 
const ENGINE_INTERNAL = 1
 #+ @access private More...
 
const ENGINE_MCRYPT = 2
 Base value for the mcrypt implementation $engine switch. More...
 
const ENGINE_OPENSSL = 3
 Base value for the mcrypt implementation $engine switch. More...
 
 $mode
 
 $block_size = 16
 
 $key = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
 
 $iv
 
 $encryptIV
 
 $decryptIV
 
 $continuousBuffer = false
 
 $enbuffer
 
 $debuffer
 
 $enmcrypt
 
 $demcrypt
 
 $enchanged = true
 
 $dechanged = true
 
 $ecb
 
 $cfb_init_len = 600
 
 $changed = true
 
 $padding = true
 
 $paddable = false
 
 $engine
 
 $preferredEngine
 
 $cipher_name_mcrypt
 
 $cipher_name_openssl
 
 $cipher_name_openssl_ecb
 
 $password_default_salt = 'phpseclib/salt'
 
 $inline_crypt
 
 $use_inline_crypt
 
 $openssl_emulate_ctr = false
 
 $openssl_options
 
 $explicit_key_length = false
 
 $skip_key_adjustment = false
 

Additional Inherited Members

- Static Public Attributes inherited from phpseclib\Crypt\Base
static $WHIRLPOOL_AVAILABLE
 

Detailed Description

Definition at line 56 of file RC4.php.

Constructor & Destructor Documentation

◆ __construct()

phpseclib\Crypt\RC4::__construct ( )

Default Constructor.

Determines whether or not the mcrypt extension should be used.

See also
\phpseclib\Crypt\Base::__construct()
Returns
\phpseclib\Crypt\RC4 @access public

Definition at line 132 of file RC4.php.

133 {
134 parent::__construct(Base::MODE_STREAM);
135 }
const MODE_STREAM
Encrypt / decrypt using streaming mode.
Definition: Base.php:90

References phpseclib\Crypt\Base\MODE_STREAM.

Member Function Documentation

◆ _crypt()

phpseclib\Crypt\RC4::_crypt (   $text,
  $mode 
)

Encrypts or decrypts a message.

See also
self::encrypt()
self::decrypt() @access private
Parameters
string$text
int$mode
Returns
string $text

Definition at line 309 of file RC4.php.

310 {
311 if ($this->changed) {
312 $this->_setup();
313 $this->changed = false;
314 }
315
316 $stream = &$this->stream[$mode];
317 if ($this->continuousBuffer) {
318 $i = &$stream[0];
319 $j = &$stream[1];
320 $keyStream = &$stream[2];
321 } else {
322 $i = $stream[0];
323 $j = $stream[1];
324 $keyStream = $stream[2];
325 }
326
327 $len = strlen($text);
328 for ($k = 0; $k < $len; ++$k) {
329 $i = ($i + 1) & 255;
330 $ksi = $keyStream[$i];
331 $j = ($j + $ksi) & 255;
332 $ksj = $keyStream[$j];
333
334 $keyStream[$i] = $ksj;
335 $keyStream[$j] = $ksi;
336 $text[$k] = $text[$k] ^ chr($keyStream[($ksj + $ksi) & 255]);
337 }
338
339 return $text;
340 }
_setup()
Setup the self::ENGINE_INTERNAL $engine.
Definition: Base.php:1743
$i
Definition: disco.tpl.php:19
$text
Definition: errorreport.php:18

References $i, phpseclib\Crypt\Base\$mode, phpseclib\Crypt\RC4\$stream, $text, and phpseclib\Crypt\Base\_setup().

Referenced by phpseclib\Crypt\RC4\decrypt(), and phpseclib\Crypt\RC4\encrypt().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _decryptBlock()

phpseclib\Crypt\RC4::_decryptBlock (   $in)

Decrypts a block.

@access private

Parameters
string$in

Reimplemented from phpseclib\Crypt\Base.

Definition at line 267 of file RC4.php.

268 {
269 // RC4 does not utilize this method
270 }

◆ _encryptBlock()

phpseclib\Crypt\RC4::_encryptBlock (   $in)

Encrypts a block.

@access private

Parameters
string$in

Reimplemented from phpseclib\Crypt\Base.

Definition at line 256 of file RC4.php.

257 {
258 // RC4 does not utilize this method
259 }

◆ _setupKey()

phpseclib\Crypt\RC4::_setupKey ( )

Setup the key (expansion)

See also
\phpseclib\Crypt\Base::_setupKey() @access private

Reimplemented from phpseclib\Crypt\Base.

Definition at line 278 of file RC4.php.

279 {
281 $keyLength = strlen($key);
282 $keyStream = range(0, 255);
283 $j = 0;
284 for ($i = 0; $i < 256; $i++) {
285 $j = ($j + $keyStream[$i] + ord($key[$i % $keyLength])) & 255;
286 $temp = $keyStream[$i];
287 $keyStream[$i] = $keyStream[$j];
288 $keyStream[$j] = $temp;
289 }
290
291 $this->stream = array();
292 $this->stream[self::DECRYPT] = $this->stream[self::ENCRYPT] = array(
293 0, // index $i
294 0, // index $j
295 $keyStream
296 );
297 }
const DECRYPT
Definition: RC4.php:63
const ENCRYPT
#+ @access private
Definition: RC4.php:62

References $i, phpseclib\Crypt\RC4\$key, phpseclib\Crypt\RC4\DECRYPT, and phpseclib\Crypt\RC4\ENCRYPT.

◆ decrypt()

phpseclib\Crypt\RC4::decrypt (   $ciphertext)

Decrypts a message.

$this->decrypt($this->encrypt($plaintext)) == $this->encrypt($this->encrypt($plaintext)). At least if the continuous buffer is disabled.

See also
\phpseclib\Crypt\Base::encrypt()
self::_crypt() @access User interface
Parameters
string$ciphertext
Returns
string $plaintext

Reimplemented from phpseclib\Crypt\Base.

Definition at line 242 of file RC4.php.

243 {
244 if ($this->engine != Base::ENGINE_INTERNAL) {
245 return parent::decrypt($ciphertext);
246 }
247 return $this->_crypt($ciphertext, self::DECRYPT);
248 }
const ENGINE_INTERNAL
#+ @access private
Definition: Base.php:109
_crypt($text, $mode)
Encrypts or decrypts a message.
Definition: RC4.php:309

References phpseclib\Crypt\RC4\_crypt(), and phpseclib\Crypt\Base\ENGINE_INTERNAL.

+ Here is the call graph for this function:

◆ encrypt()

phpseclib\Crypt\RC4::encrypt (   $plaintext)

Encrypts a message.

See also
\phpseclib\Crypt\Base::decrypt()
self::_crypt() @access User interface
Parameters
string$plaintext
Returns
string $ciphertext

Reimplemented from phpseclib\Crypt\Base.

Definition at line 222 of file RC4.php.

223 {
224 if ($this->engine != Base::ENGINE_INTERNAL) {
225 return parent::encrypt($plaintext);
226 }
227 return $this->_crypt($plaintext, self::ENCRYPT);
228 }

References phpseclib\Crypt\RC4\_crypt(), and phpseclib\Crypt\Base\ENGINE_INTERNAL.

+ Here is the call graph for this function:

◆ isValidEngine()

phpseclib\Crypt\RC4::isValidEngine (   $engine)

Test for engine validity.

This is mainly just a wrapper to set things up for \phpseclib\Crypt\Base::isValidEngine()

See also
\phpseclib\Crypt\Base::__construct()
Parameters
int$engine@access public
Returns
bool

Reimplemented from phpseclib\Crypt\Base.

Definition at line 147 of file RC4.php.

148 {
149 switch ($engine) {
151 switch (strlen($this->key)) {
152 case 5:
153 $this->cipher_name_openssl = 'rc4-40';
154 break;
155 case 8:
156 $this->cipher_name_openssl = 'rc4-64';
157 break;
158 case 16:
159 $this->cipher_name_openssl = 'rc4';
160 break;
161 default:
162 return false;
163 }
164 }
165
166 return parent::isValidEngine($engine);
167 }
const ENGINE_OPENSSL
Base value for the mcrypt implementation $engine switch.
Definition: Base.php:117

References phpseclib\Crypt\Base\$engine, and phpseclib\Crypt\Base\ENGINE_OPENSSL.

◆ setIV()

phpseclib\Crypt\RC4::setIV (   $iv)

Dummy function.

Some protocols, such as WEP, prepend an "initialization vector" to the key, effectively creating a new key [1]. If you need to use an initialization vector in this manner, feel free to prepend it to the key, yourself, before calling setKey().

[1] WEP's initialization vectors (IV's) are used in a somewhat insecure way. Since, in that protocol, the IV's are relatively easy to predict, an attack described by Scott Fluhrer, Itsik Mantin, and Adi Shamir can be used to quickly guess at the rest of the key. The following links elaborate:

http://www.rsa.com/rsalabs/node.asp?id=2009 http://en.wikipedia.org/wiki/Related_key_attack

Parameters
string$iv
See also
self::setKey() @access User interface

Reimplemented from phpseclib\Crypt\Base.

Definition at line 188 of file RC4.php.

189 {
190 }

◆ setKeyLength()

phpseclib\Crypt\RC4::setKeyLength (   $length)

Sets the key length.

Keys can be between 1 and 256 bytes long.

@access public

Parameters
int$length

Reimplemented from phpseclib\Crypt\Base.

Definition at line 200 of file RC4.php.

201 {
202 if ($length < 8) {
203 $this->key_length = 1;
204 } elseif ($length > 2048) {
205 $this->key_length = 248;
206 } else {
207 $this->key_length = $length >> 3;
208 }
209
210 parent::setKeyLength($length);
211 }

Field Documentation

◆ $block_size

phpseclib\Crypt\RC4::$block_size = 0

Definition at line 76 of file RC4.php.

◆ $cipher_name_mcrypt

phpseclib\Crypt\RC4::$cipher_name_mcrypt = 'arcfour'

Definition at line 94 of file RC4.php.

◆ $key

phpseclib\Crypt\RC4::$key = "\0"

Definition at line 112 of file RC4.php.

Referenced by phpseclib\Crypt\RC4\_setupKey().

◆ $key_length

phpseclib\Crypt\RC4::$key_length = 128

Definition at line 85 of file RC4.php.

◆ $stream

phpseclib\Crypt\RC4::$stream

Definition at line 121 of file RC4.php.

Referenced by phpseclib\Crypt\RC4\_crypt().

◆ $use_inline_crypt

phpseclib\Crypt\RC4::$use_inline_crypt = false

Definition at line 103 of file RC4.php.

◆ DECRYPT

const phpseclib\Crypt\RC4::DECRYPT = 1

Definition at line 63 of file RC4.php.

Referenced by phpseclib\Crypt\RC4\_setupKey().

◆ ENCRYPT

const phpseclib\Crypt\RC4::ENCRYPT = 0

#+ @access private

See also
\phpseclib\Crypt\RC4::_crypt()

Definition at line 62 of file RC4.php.

Referenced by phpseclib\Crypt\RC4\_setupKey().


The documentation for this class was generated from the following file: