DLEncryption_Three

Encryption class based of AES.  Originally written by Marcin F.  Wiœniowski (marcin.w.nosp@m.isniowski@mfw.nosp@m..pl).

Summary
DLEncryption_ThreeEncryption class based of AES.
Private Data
$Sbox(array) Sbox is pre-computed multiplicative inverse in GF(2^8) used in SubBytes and KeyExpansion.
$Rcon(array) Rcon is Round Constant used for the Key Expansion [1st col is 2^(r-1) in GF(2^8)].
Inherit Methods
DecryptDecrypt the given data using the given key.
EncryptEncrypt the given data using the given key.
Algorithm Specific Methods
CipherEncrypt ‘input’ with Rijndael algorithm.
KeyExpansionPerforms key expansion on cipher key to generate a key schedule.
AESEncryptCtrEncrypt a text using AES encryption in Counter mode of operation ~ see http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf
AESDecryptCtrDecrypt a text encrypted by AES in counter mode of operation.
UrsUnsigned right shift function, since PHP has neither >>> operator nor unsigned ints.

Private Data

$Sbox

private $Sbox

(array) Sbox is pre-computed multiplicative inverse in GF(2^8) used in SubBytes and KeyExpansion.

$Rcon

private $Rcon

(array) Rcon is Round Constant used for the Key Expansion [1st col is 2^(r-1) in GF(2^8)].

Inherit Methods

Decrypt

public function Decrypt($key,
$data)

Decrypt the given data using the given key.

See

DLEncryption->Decrypt

Encrypt

public function Encrypt($key,
$data)

Encrypt the given data using the given key.

See

DLEncryption->Encrypt

Algorithm Specific Methods

Cipher

private function Cipher($input,
$w)

Encrypt ‘input’ with Rijndael algorithm.

Parameters

$input(array) Message as byte-array (16 bytes).
$w(string) Key schedule as 2D byte-array (Nr+1 x Nb bytes) ~ generated from the cipher key by KeyExpansion.

Returns

(array) Ciphertext as byte-array (16 bytes).

KeyExpansion

private function KeyExpansion($key)

Performs key expansion on cipher key to generate a key schedule.

Parameters

$key(array) Cipher key byte-array (16 bytes).

Returns

(array) Key schedule as 2D byte-array (Nr+1 x Nb bytes).

AESEncryptCtr

private function AESEncryptCtr($plaintext,
$password,
$nBits)

Encrypt a text using AES encryption in Counter mode of operation ~ see http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf

Unicode multi-byte character safe.

Parameters

$plaintext(string) Source text to be encrypted.
$password(string) The password to use to generate a key.
$nBits(numeric) Number of bits to be used in the key (128, 192, or 256).

Returns

(string) Encrypted text.

AESDecryptCtr

private function AESDecryptCtr($ciphertext,
$password,
$nBits)

Decrypt a text encrypted by AES in counter mode of operation.

Parameters

$ciphertext(string) Source text to be decrypted.
$password(string) The password to use to generate a key.
$nBits(numeric) Number of bits to be used in the key (128, 192, or 256).

Returns

(string) Decrypted text.

Urs

private function Urs($a,
$b)

Unsigned right shift function, since PHP has neither >>> operator nor unsigned ints.

Parameters

$a(numeric) Number to be shifted (32-bit integer).
$b(numeric) Number of bits to shift a to the right (0..31).

Returns

(numeric) A right-shifted and zero-filled by b bits.

private $Sbox
(array) Sbox is pre-computed multiplicative inverse in GF(2^8) used in SubBytes and KeyExpansion.
private $Rcon
(array) Rcon is Round Constant used for the Key Expansion [1st col is 2^(r-1) in GF(2^8)].
public function Decrypt($key,
$data)
Decrypt the given data using the given key.
public function Encrypt($key,
$data)
Encrypt the given data using the given key.
private function Cipher($input,
$w)
Encrypt ‘input’ with Rijndael algorithm.
private function KeyExpansion($key)
Performs key expansion on cipher key to generate a key schedule.
private function AESEncryptCtr($plaintext,
$password,
$nBits)
Encrypt a text using AES encryption in Counter mode of operation ~ see http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf
private function AESDecryptCtr($ciphertext,
$password,
$nBits)
Decrypt a text encrypted by AES in counter mode of operation.
private function Urs($a,
$b)
Unsigned right shift function, since PHP has neither >>> operator nor unsigned ints.
abstract public function Decrypt($key,
$data)
Decrypt the given data using the given key.
abstract public function Encrypt($key,
$data)
Encrypt the given data using the given key.