Crypt_RC4
[ class tree: Crypt_RC4 ] [ index: Crypt_RC4 ] [ all elements ]

Class: Crypt_RC4

Source Location: /lib/3rdParty/phpseclib/Crypt/RC4.php

Class Overview


Pure-PHP implementation of RC4.


Author(s):

Version:

  • 0.1.0

Methods



Class Details

[line 92]
Pure-PHP implementation of RC4.



Tags:

author:  Jim Wigginton <terrafrost@php.net>
version:  0.1.0
access:  public


[ Top ]


Class Methods


constructor Crypt_RC4 [line 171]

Crypt_RC4 Crypt_RC4( optional 0)

Default Constructor.

Determines whether or not the mcrypt extension should be used.




Tags:

access:  public


Parameters:

optional   0   Integer $mode

[ Top ]

destructor __destruct [line 459]

void __destruct( )

Class destructor.

Will be called, automatically, if you're using PHP5. If you're using PHP4, call it yourself. Only really needs to be called if mcrypt is being used.




Tags:

access:  public


[ Top ]

method decrypt [line 295]

void decrypt( String $ciphertext)

Decrypts a message.

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




Tags:

see:  Crypt_RC4::_crypt()
access:  public


Parameters:

String   $ciphertext  

[ Top ]

method disableContinuousBuffer [line 418]

void disableContinuousBuffer( )

Treat consecutive packets as if they are a discontinuous buffer.

The default behavior.




Tags:

see:  Crypt_RC4::enableContinuousBuffer()
access:  public


[ Top ]

method disablePadding [line 447]

void disablePadding( )

Dummy function.



Tags:

see:  Crypt_RC4::enablePadding()
access:  public


[ Top ]

method enableContinuousBuffer [line 405]

void enableContinuousBuffer( )

Treat consecutive "packets" as if they are a continuous buffer.

Say you have a 16-byte plaintext $plaintext. Using the default behavior, the two following code snippets will yield different outputs:

  1.     echo $rc4->encrypt(substr($plaintext08));
  2.     echo $rc4->encrypt(substr($plaintext88));
  1.     echo $rc4->encrypt($plaintext);

The solution is to enable the continuous buffer. Although this will resolve the above discrepancy, it creates another, as demonstrated with the following:

  1.     $rc4->encrypt(substr($plaintext08));
  2.     echo $rc4->decrypt($des->encrypt(substr($plaintext88)));
  1.     echo $rc4->decrypt($des->encrypt(substr($plaintext88)));

With the continuous buffer disabled, these would yield the same output. With it enabled, they yield different outputs. The reason is due to the fact that the initialization vector's change after every encryption / decryption round when the continuous buffer is enabled. When it's disabled, they remain constant.

Put another way, when the continuous buffer is enabled, the state of the Crypt_DES() object changes after each encryption / decryption round, whereas otherwise, it'd remain constant. For this reason, it's recommended that continuous buffers not be used. They do offer better security and are, in fact, sometimes required (SSH uses them), however, they are also less intuitive and more likely to cause you problems.




Tags:

see:  Crypt_RC4::disableContinuousBuffer()
access:  public


[ Top ]

method enablePadding [line 437]

void enablePadding( )

Dummy function.

Since RC4 is a stream cipher and not a block cipher, no padding is necessary. The only reason this function is included is so that you can switch between a block cipher and a stream cipher transparently.




Tags:

see:  Crypt_RC4::disablePadding()
access:  public


[ Top ]

method encrypt [line 280]

void encrypt( String $plaintext)

Encrypts a message.



Tags:

see:  Crypt_RC4::_crypt()
access:  public


Parameters:

String   $plaintext  

[ Top ]

method setIV [line 251]

void setIV( String $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, and 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




Tags:

see:  Crypt_RC4::setKey()
access:  public


Parameters:

String   $iv  

[ Top ]

method setKey [line 207]

void setKey( String $key)

Sets the key.

Keys can be between 1 and 256 bytes long. If they are longer then 256 bytes, the first 256 bytes will be used. If no key is explicitly set, it'll be assumed to be a single null byte.




Tags:

access:  public


Parameters:

String   $key  

[ Top ]

method setMCrypt [line 265]

void setMCrypt( [optional $algorithm_directory = ''], [optional $mode_directory = ''])

Sets MCrypt parameters. (optional)

If MCrypt is being used, empty strings will be used, unless otherwise specified.




Tags:



Parameters:

optional   $algorithm_directory   Integer $algorithm_directory
optional   $mode_directory   Integer $mode_directory

[ Top ]

method _closeMCrypt [line 471]

void _closeMCrypt( )

Properly close the MCrypt objects.



[ Top ]


Documentation generated on Thu, 28 Oct 2010 21:00:31 +0200 by phpDocumentor 1.4.1