cryptal  latest
Cryptography Abstraction Layer
fpoirotte\Cryptal\DefaultAlgorithms\Camellia Class Reference
+ Inheritance diagram for fpoirotte\Cryptal\DefaultAlgorithms\Camellia:

Public Member Functions

 __construct (CipherEnum $cipher, ModeEnum $mode, PaddingInterface $padding, $key, $tagLength=self::DEFAULT_TAG_LENGTH)
 
 decrypt ($iv, $data, $tag=null, $aad= '')
 
 encrypt ($iv, $data, &$tag=null, $aad= '')
 
 getBlockSize ()
 
 getCipher ()
 
 getIVSize ()
 
 getKey ()
 

Public Attributes

const SIGMA1 = "\xA0\x9E\x66\x7F\x3B\xCC\x90\x8B"
 Sigma1 constant (from the RFC)
 
const SIGMA2 = "\xB6\x7A\xE8\x58\x4C\xAA\x73\xB2"
 Sigma2 constant (from the RFC)
 
const SIGMA3 = "\xC6\xEF\x37\x2F\xE9\x4F\x82\xBE"
 Sigma3 constant (from the RFC)
 
const SIGMA4 = "\x54\xFF\x53\xA5\xF1\xD3\x6F\x1C"
 Sigma4 constant (from the RFC)
 
const SIGMA5 = "\x10\xE5\x27\xFA\xDE\x68\x2D\x1D"
 Sigma5 constant (from the RFC)
 
const SIGMA6 = "\xB0\x56\x88\xC2\xB3\xE6\xC1\xFD"
 Sigma6 constant (from the RFC)
 
- Public Attributes inherited from fpoirotte\Cryptal\Implementers\CryptoInterface
const DEFAULT_TAG_LENGTH = 16
 

Protected Member Functions

 f ($F_IN, $KE)
 
 scheduleKeys ($key)
 
 xcrypt ($m, array $k, array $ke, array $kw)
 

Static Protected Member Functions

static fl ($FL_IN, $KE)
 
static flinv ($FLINV_IN, $KE)
 
static rotateLeft ($value, $n)
 
static sbox ($n, $x)
 

Protected Attributes

 $cipher
 
 $k
 Subkeys used for encryption.
 
 $k2
 Subkeys used for decryption.
 
 $ke
 Subkeys used by the Feistel structure during encryption.
 
 $ke2
 Subkeys used by the Feistel structure during decryption.
 
 $key
 
 $keyLength
 Original key length in bits (128, 192 or 256)
 
 $kw
 Subkeys used for whitening during encryption.
 
 $kw2
 Subkeys used for whitening during decryption.
 

Static Protected Attributes

static $sbox1 = null
 Character string containing the whole sbox1 crypto-box.
 

Detailed Description

Camellia cipher (RFC 3713).

See also
https://tools.ietf.org/html/rfc3713

Definition at line 20 of file Camellia.php.

Constructor & Destructor Documentation

fpoirotte\Cryptal\DefaultAlgorithms\Camellia::__construct ( CipherEnum  $cipher,
ModeEnum  $mode,
PaddingInterface  $padding,
  $key,
  $tagLength = self::DEFAULT_TAG_LENGTH 
)

Construct a new encryption/decryption context.

Parameters
CipherEnum$cipherCipher algorithm to use.
ModeEnum$modeCryptography mode to apply to the cipher.
PaddingInterface$paddingPadding scheme to use.
string$keySecret key used for encryption/decryption.
int$tagLengthLength (in bytes) of the authentication tags to generate.
Note
The $tagLength parameter is unused unless the supplied mode supports Authenticated Encryption with Additional Data (AEAD).

Implements fpoirotte\Cryptal\Implementers\CryptoInterface.

Definition at line 67 of file Camellia.php.

References fpoirotte\Cryptal\DefaultAlgorithms\Camellia\scheduleKeys().

Member Function Documentation

fpoirotte\Cryptal\DefaultAlgorithms\Camellia::decrypt (   $iv,
  $data,
  $tag = null,
  $aad = '' 
)

Decrypt some data.

Parameters
string$ivInitialization Vector for the operation.
string$dataData to decrypt.
string$tagAuthentication tag.
string$aadAdditional authenticated data.
Return values
stringPlaintext (decrypted data).
Note
The $iv parameter is unused for some modes of operations (namely MODE_ECB). Still, this parameter is mandatory and an empty string may be passed for those modes.
An exception is thrown in case decryption fails, or the given authentication tag is incorrect (AEAD-only).
The $aad & $tag parameters are unused unless the required mode supports Authenticated Encryption with Additional Data (AEAD). MODE_GCM & MODE_EAX are known to support AEAD.

Implements fpoirotte\Cryptal\Implementers\CryptoInterface.

Definition at line 456 of file Camellia.php.

References fpoirotte\Cryptal\DefaultAlgorithms\Camellia\getBlockSize(), and fpoirotte\Cryptal\DefaultAlgorithms\Camellia\xcrypt().

fpoirotte\Cryptal\DefaultAlgorithms\Camellia::encrypt (   $iv,
  $data,
$tag = null,
  $aad = '' 
)

Encrypt some data.

Parameters
string$ivInitialization Vector for the operation.
string$dataData to encrypt.
string$tagVariable where the generated tag will be stored.
string$aadAdditional authenticated data.
Return values
stringCiphertext (encrypted data).
Note
The $iv parameter is unused for some modes of operations (namely MODE_ECB). Still, this parameter is mandatory and an empty string may be passed for those modes.
An exception is thrown in case encryption fails.
The $aad & $tag parameters are unused unless the required mode supports Authenticated Encryption with Additional Data (AEAD). MODE_GCM & MODE_EAX are known to support AEAD.

Implements fpoirotte\Cryptal\Implementers\CryptoInterface.

Definition at line 442 of file Camellia.php.

References fpoirotte\Cryptal\DefaultAlgorithms\Camellia\getBlockSize(), and fpoirotte\Cryptal\DefaultAlgorithms\Camellia\xcrypt().

fpoirotte\Cryptal\DefaultAlgorithms\Camellia::f (   $F_IN,
  $KE 
)
protected

F-function (per RFC 3713)

Parameters
string$F_IN64-bit input data for the function
string$KE64-bit subkey
Return values
string64-bit output data

Definition at line 311 of file Camellia.php.

static fpoirotte\Cryptal\DefaultAlgorithms\Camellia::fl (   $FL_IN,
  $KE 
)
staticprotected

Feistel function (per RFC 3713)

Parameters
string$FL_IN64-bit input data for the function
string$KE64-bit subkey
Return values
string64-bit output data
Note
This method does the opposite of the flinv() method.

Definition at line 350 of file Camellia.php.

References fpoirotte\Cryptal\DefaultAlgorithms\Camellia\$k2.

static fpoirotte\Cryptal\DefaultAlgorithms\Camellia::flinv (   $FLINV_IN,
  $KE 
)
staticprotected

Inverse Feistel function (per RFC 3713)

Parameters
string$FLINV_IN64-bit input data for the function
string$KE64-bit subkey
Return values
string64-bit output data
Note
This method does the opposite of the fl() method.

Definition at line 377 of file Camellia.php.

References fpoirotte\Cryptal\DefaultAlgorithms\Camellia\$k2.

fpoirotte\Cryptal\DefaultAlgorithms\Camellia::getBlockSize ( )

Get the block size, in bytes.

Return values
intRequired size for each block. Might be zero in case the given cipher/mode combination does not use blocks.

Implements fpoirotte\Cryptal\Implementers\CryptoInterface.

Definition at line 475 of file Camellia.php.

Referenced by fpoirotte\Cryptal\DefaultAlgorithms\Camellia\decrypt(), and fpoirotte\Cryptal\DefaultAlgorithms\Camellia\encrypt().

fpoirotte\Cryptal\DefaultAlgorithms\Camellia::getCipher ( )

Get the cipher used by this particular instance.

Return values
CipherEnumCipher in use by this instance.

Implements fpoirotte\Cryptal\Implementers\CryptoInterface.

Definition at line 480 of file Camellia.php.

fpoirotte\Cryptal\DefaultAlgorithms\Camellia::getIVSize ( )

Get the size of the Initialization Vector, in bytes.

Return values
intRequired size for the Initialization Vector. Might be zero in case the given cipher/mode combination does not require an initialization vector.

Implements fpoirotte\Cryptal\Implementers\CryptoInterface.

Definition at line 470 of file Camellia.php.

fpoirotte\Cryptal\DefaultAlgorithms\Camellia::getKey ( )

Get the key used by this particular instance.

Return values
stringKey in use by this instance.

Implements fpoirotte\Cryptal\Implementers\CryptoInterface.

Definition at line 485 of file Camellia.php.

static fpoirotte\Cryptal\DefaultAlgorithms\Camellia::rotateLeft (   $value,
  $n 
)
staticprotected

Perform a left rotation operation.

Parameters
string$valueBig-endian string whose bits will be left-rotated
int$nNumber of bits to rotate to the left
Return values
stringThe result from rotating $n bits from $value

Definition at line 126 of file Camellia.php.

static fpoirotte\Cryptal\DefaultAlgorithms\Camellia::sbox (   $n,
  $x 
)
staticprotected

Retrieve the sbox value at a given index.

Parameters
int$nA number between 1 and 4 indicating the sbox from which the resulting value will be taken.
string$xA single character indicating the index in the sbox whose value should be returned.
Return values
stringA single character: the value for the given sbox and index.

Definition at line 286 of file Camellia.php.

fpoirotte\Cryptal\DefaultAlgorithms\Camellia::scheduleKeys (   $key)
protected

Perform key scheduling.

Parameters
string$keyThe key to schedule.
Returns
This method does not return any value. Instead, several intermediate values are stored into the instance so that encryption/decryption operations may then take place.

Definition at line 147 of file Camellia.php.

References fpoirotte\Cryptal\DefaultAlgorithms\Camellia\$k, fpoirotte\Cryptal\DefaultAlgorithms\Camellia\$k2, fpoirotte\Cryptal\DefaultAlgorithms\Camellia\$ke, fpoirotte\Cryptal\DefaultAlgorithms\Camellia\$ke2, fpoirotte\Cryptal\DefaultAlgorithms\Camellia\$kw, and fpoirotte\Cryptal\DefaultAlgorithms\Camellia\$kw2.

Referenced by fpoirotte\Cryptal\DefaultAlgorithms\Camellia\__construct().

fpoirotte\Cryptal\DefaultAlgorithms\Camellia::xcrypt (   $m,
array  $k,
array  $ke,
array  $kw 
)
protected

Internal encryption/decryption routine.

Parameters
string$mA block of data to encrypt or decrypt.
array$kSubkeys used for the operation
array$keSubkeys used by the Feistel structure
array$kwSubkeys used for whitening
Return values
stringEncrypted/decrypted block
Note
Whether this method is actually encrypting/decrypting data is determined purely by the values of $k, $ke and $kw.

Definition at line 411 of file Camellia.php.

Referenced by fpoirotte\Cryptal\DefaultAlgorithms\Camellia\decrypt(), and fpoirotte\Cryptal\DefaultAlgorithms\Camellia\encrypt().


The documentation for this class was generated from the following file: