Packageindex Classtrees Modulegroups Elementlist Report XML Files

Crypt_Xtea

Crypt_Xtea

Crypt_Xtea

public class Crypt_Xtea extends PEAR

Class that implements the xTEA encryption algorithm.
This enables you to encrypt data without requiring mcrypt. From the C source: ----------------------------------------- The Tiny Encryption Algorithm (TEA) by David Wheeler and Roger Needham of the Cambridge Computer Laboratory. Placed in the Public Domain by David Wheeler and Roger Needham. **** ANSI C VERSION (New Variant) **** Notes: TEA is a Feistel cipher with XOR and and addition as the non-linear mixing functions. Takes 64 bits of data in v[0] and v[1]. Returns 64 bits of data in w[0] and w[1]. Takes 128 bits of key in k[0] - k[3]. TEA can be operated in any of the modes of DES. Cipher Block Chaining is, for example, simple to implement. n is the number of iterations. 32 is ample, 16 is sufficient, as few as eight may be OK. The algorithm achieves good dispersion after six iterations. The iteration count can be made variable if required. Note this is optimised for 32-bit CPUs with fast shift capabilities. It can very easily be ported to assembly language on most CPUs. delta is chosen to be the real part of (the golden ratio Sqrt(5/4) - 1/2 ~ 0.618034 multiplied by 2^32). This version has been amended to foil two weaknesses identified by David A. Wagner (daw@cs.berkeley.edu): 1) effective key length of old-variant TEA was 126 not 128 bits 2) a related key attack was possible although impractical. void encipher(unsigned long *const v,unsigned long *const w, const unsigned long *const k) { register unsigned long y=v[0],z=v[1],sum=0,delta=0x9E3779B9,n=32; while(n-->0) { y+= (z5) + z ^ sum + k[sum&3]; sum += delta; z+= (y5) + y ^ sum + k[sum>>11 & 3]; } w[0]=y; w[1]=z; } void decipher(unsigned long *const v,unsigned long *const w, const unsigned long *const k) { register unsigned long y=v[0],z=v[1],sum=0xC6EF3720, delta=0x9E3779B9,n=32; # sum = delta>11 & 3]; sum -= delta; y-= (z5) + z ^ sum + k[sum&3]; } w[0]=y; w[1]=z; } -----------------------------------------

AuthorsJeroen Derks <jeroen@derks.it>
Version$Revision: 1.13 $

 

Public Method Summary

void Crypt_Xtea()
Constructor, sets the number of iterations.
void setIter(integer $n_iter)
Set the number of iterations to use.
integer getIter()
Get the number of iterations to use.
string encrypt(string $data, string $key)
Encrypt a string using a specific key.
string decrypt(string $enc_data, string $key)
Decrypt an encrypted string using a specific key.

Private Method Summary

void _encipherLong(integer $y, integer $z, array &$w, array &$k)
Encipher a single long (32-bit) value.
void _decipherLong(integer $y, integer $z, array &$w, array &$k)
Decipher a single long (32-bit) value.
integer _resize(string &$data, integer $size, [ boolean $nonull ])
Resize data string to a multiple of specified size.
string _hex2bin(string $str)
Convert a hexadecimal string to a binary string (e.g. convert "616263" to "abc").
integer _str2long(integer $start, string &$data, array &$data_long)
Convert string to array of long.
string _long2str(long $l)
Convert long to character string.
void _rshift( $integer, $n)
Handle proper unsigned right shift, dealing with PHP's signed shift.
void _add( $i1, $i2)
Handle proper unsigned add, dealing with PHP's signed add.

Private Field Summary

integer $n_iter
Number of iterations.

Public Method Details

Crypt_Xtea

public void Crypt_Xtea()

 

Returns void

See Also setIter()
Author(s) Jeroen Derks <jeroen@derks.it>

setIter

public void setIter(integer $n_iter)

 

Parameter
integer $n_iter
Number of iterations to use.
Returns void

See Also $n_iter, getIter()
Author(s) Jeroen Derks <jeroen@derks.it>

getIter

public integer getIter()

 

Returns integer

Number of iterations to use.

See Also $n_iter, setIter()
Author(s) Jeroen Derks <jeroen@derks.it>

encrypt

public string encrypt(string $data, string $key)

 

Parameter
string $data
Data to encrypt.
string $key
Key to encrypt data with (binary string).
Returns string

Binary encrypted character string.

See Also decrypt(), _encipherLong(), _resize(), _str2long()
Author(s) Jeroen Derks <jeroen@derks.it>

decrypt

public string decrypt(string $enc_data, string $key)

 

Parameter
string $enc_data
Encrypted data to decrypt.
string $key
Key to decrypt encrypted data with (binary string).
Returns string

Binary decrypted character string.

See Also _encipherLong(), encrypt(), _resize(), _str2long()
Author(s) Jeroen Derks <jeroen@derks.it>

Private Method Details

_encipherLong

private void _encipherLong(integer $y, integer $z, array &$w, array &$k)

 

Parameter
integer $y
32 bits of data.
integer $z
32 bits of data.
array &$w
Placeholder for enciphered 64 bits (in w[0] and w[1]).
array &$k
Key 128 bits (in k[0]-k[3]).
Returns void

See Also $n_iter, _add(), _rshift(), _decipherLong()
Author(s) Jeroen Derks <jeroen@derks.it>

_decipherLong

private void _decipherLong(integer $y, integer $z, array &$w, array &$k)

 

Parameter
integer $y
32 bits of enciphered data.
integer $z
32 bits of enciphered data.
array &$w
Placeholder for deciphered 64 bits (in w[0] and w[1]).
array &$k
Key 128 bits (in k[0]-k[3]).
Returns void

See Also $n_iter, _add(), _rshift(), _decipherLong()
Author(s) Jeroen Derks <jeroen@derks.it>

_resize

private integer _resize(string &$data, integer $size, [ boolean $nonull ])

 

Parameter
string &$data
Data string to resize to specified size.
integer $size
Size in bytes to align data to.
boolean $nonull = >>false<<
Set to true if padded bytes should not be zero.
Returns integer

Length of supplied data string.

Author(s) Jeroen Derks <jeroen@derks.it>

_hex2bin

private string _hex2bin(string $str)

 

Parameter
string $str
Hexadecimal string to convert to binary string.
Returns string

Binary string.

Author(s) Jeroen Derks <jeroen@derks.it>

_str2long

private integer _str2long(integer $start, string &$data, array &$data_long)

 

Parameter
integer $start
Index into $data_long for output.
string &$data
Input string.
array &$data_long
Output array of long.
Returns integer

Index from which to optionally continue.

Author(s) Jeroen Derks <jeroen@derks.it>

_long2str

private string _long2str(long $l)

 

Parameter
long $l
Long to convert to character string.
Returns string

Character string.

Author(s) Jeroen Derks <jeroen@derks.it>

_rshift

private void _rshift( $integer, $n)

 

Parameter
$integer
Warning: documentation is missing.
$n
Warning: documentation is missing.
Returns void

Since 2004/Sep/06
Author(s) Jeroen Derks <jeroen@derks.it>

_add

private void _add( $i1, $i2)

 

Parameter
$i1
Warning: documentation is missing.
$i2
Warning: documentation is missing.
Returns void

Since 2004/Sep/06
Author(s) Jeroen Derks <jeroen@derks.it>

Private Field Details

$n_iter

private integer $n_iter

>><<

See Also setIter(), getIter()


Packageindex Classtrees Modulegroups Elementlist Report XML Files
Generated on Thu, 25 May 2006 15:31:25 +0200 by PHPDoc v1.5 www.phpdoc.de