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

Class: Crypt_TripleDES

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

Class Overview


Pure-PHP implementation of Triple DES.


Author(s):

Version:

  • 0.1.0

Methods



Class Details

[line 81]
Pure-PHP implementation of Triple DES.



Tags:

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


[ Top ]


Class Methods


constructor Crypt_TripleDES [line 197]

Crypt_TripleDES Crypt_TripleDES( [optional $mode = CRYPT_DES_MODE_CBC])

Default Constructor.

Determines whether or not the mcrypt extension should be used. $mode should only, at present, be CRYPT_DES_MODE_ECB or CRYPT_DES_MODE_CBC. If not explictly set, CRYPT_DES_MODE_CBC will be used.




Tags:

access:  public


Parameters:

optional   $mode   Integer $mode

[ Top ]

method decrypt [line 456]

void decrypt( String $ciphertext)

Decrypts a message.



Tags:

access:  public


Parameters:

String   $ciphertext  

[ Top ]

method disableContinuousBuffer [line 592]

void disableContinuousBuffer( )

Treat consecutive packets as if they are a discontinuous buffer.

The default behavior.




Tags:

see:  Crypt_TripleDES::enableContinuousBuffer()
access:  public


[ Top ]

method disablePadding [line 630]

void disablePadding( )

Do not pad packets.



Tags:

see:  Crypt_TripleDES::enablePadding()
access:  public


[ Top ]

method enableContinuousBuffer [line 574]

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 $des->encrypt(substr($plaintext08));
  2.     echo $des->encrypt(substr($plaintext88));
  1.     echo $des->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.     $des->encrypt(substr($plaintext08));
  2.     echo $des->decrypt($des->encrypt(substr($plaintext88)));
  1.     echo $des->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_TripleDES::disableContinuousBuffer()
access:  public


[ Top ]

method enablePadding [line 619]

void enablePadding( )

Pad "packets".

DES works by encrypting eight bytes at a time. If you ever need to encrypt or decrypt something that's not a multiple of eight, it becomes necessary to pad the input so that it's length is a multiple of eight.

Padding is enabled by default. Sometimes, however, it is undesirable to pad strings. Such is the case in SSH1, where "packets" are padded with random bytes before being encrypted. Unpad these packets and you risk stripping away characters that shouldn't be stripped away. (SSH knows how many bytes are added because the length is transmitted separately)




Tags:

see:  Crypt_TripleDES::disablePadding()
access:  public


[ Top ]

method encrypt [line 364]

void encrypt( String $plaintext)

Encrypts a message.



Tags:

access:  public


Parameters:

String   $plaintext  

[ Top ]

method setIV [line 309]

void setIV( String $iv)

Sets the initialization vector. (optional)

SetIV is not required when CRYPT_DES_MODE_ECB is being used. If not explictly set, it'll be assumed to be all zero's.




Tags:

access:  public


Parameters:

String   $iv  

[ Top ]

method setKey [line 280]

void setKey( String $key)

Sets the key.

Keys can be of any length. Triple DES, itself, can use 128-bit (eg. strlen($key) == 16) or 192-bit (eg. strlen($key) == 24) keys. This function pads and truncates $key as appropriate.

DES also requires that every eighth bit be a parity bit, however, we'll ignore that.

If the key is not explicitly set, it'll be assumed to be all zero's.




Tags:

access:  public


Parameters:

String   $key  

[ Top ]

method _generate_xor [line 332]

void _generate_xor( Integer $length, &$iv, String $iv)

Generate CTR XOR encryption key

Encrypt the output of this and XOR it against the ciphertext / plaintext to get the plaintext / ciphertext in CTR mode.




Tags:

see:  Crypt_DES::decrypt()
see:  Crypt_DES::encrypt()
access:  public


Parameters:

Integer   $length  
String   $iv  
   &$iv  

[ Top ]


Documentation generated on Mon, 25 Apr 2011 16:10:49 +0200 by phpDocumentor 1.4.1