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

Class: Crypt_Xtea

Source Location: /Crypt_Xtea-1.1.0/Xtea.php

Class Overview

PEAR
   |
   --Crypt_Xtea

Class that implements the xTEA encryption algorithm.


Author(s):

Version:

  • $Revision: 1.14 $

Methods


Inherited Variables

Inherited Methods


Class Details

[line 124]
Class that implements the xTEA encryption algorithm.

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+= (z<<4 ^ z>>5) + z ^ sum + k[sum&3]; sum += delta; z+= (y<<4 ^ y>>5) + 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<<5, in general sum = delta * n
while(n-->0) { z-= (y<<4 ^ y>>5) + y ^ sum + k[sum>>11 & 3]; sum -= delta; y-= (z<<4 ^ z>>5) + z ^ sum + k[sum&3]; }

w[0]=y; w[1]=z; }

-----------------------------------------

  • Author: Jeroen Derks <jeroen@derks.it>
  • Version: $Revision: 1.14 $
  • TODO: Add CFB.
  • Access: public


[ Top ]


Method Detail

Crypt_Xtea (Constructor)   [line 145]

Crypt_Xtea Crypt_Xtea( )

Constructor, sets the number of iterations.

[ Top ]

decrypt   [line 268]

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

Decrypt an encrypted string using a specific key.

Parameters:

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

[ Top ]

encrypt   [line 199]

string encrypt( string $data, string $key)

Encrypt a string using a specific key.

Parameters:

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

[ Top ]

getIter   [line 179]

integer getIter( )

Get the number of iterations to use.

[ Top ]

setIter   [line 162]

void setIter( integer $n_iter)

Set the number of iterations to use.

Parameters:

integer   $n_iter   —  Number of iterations to use.

[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:17:11 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.