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

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 ()
 

Protected Member Functions

 basicXcrypt ($plain, $iv, $counter=0)
 
 block ($iv, $counter)
 

Static Protected Member Functions

static quarterRound (&$a, &$b, &$c, &$d)
 

Protected Attributes

 $cipher
 
 $key
 Secret key used to encrypt/decrypt data.
 
 $tagLength
 Tag length in bytes; 16 when AEAD is enabled, 0 otherwise.
 

Additional Inherited Members

- Public Attributes inherited from fpoirotte\Cryptal\Implementers\CryptoInterface
const DEFAULT_TAG_LENGTH = 16
 

Detailed Description

ChaCha20 block cipher, with optional AEAD (as per RFC 7539).

Note
When using AEAD, this class implements the construction defined in RFC 7539.
See also
http://cr.yp.to/chacha/chacha-20080128.pdf
https://tools.ietf.org/html/rfc7539

Definition at line 25 of file ChaCha20.php.

Constructor & Destructor Documentation

fpoirotte\Cryptal\DefaultAlgorithms\ChaCha20::__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 35 of file ChaCha20.php.

References fpoirotte\Cryptal\DefaultAlgorithms\ChaCha20\$key, fpoirotte\Cryptal\DefaultAlgorithms\ChaCha20\$tagLength, and fpoirotte\Cryptal\DefaultAlgorithms\ChaCha20\getIVSize().

Member Function Documentation

fpoirotte\Cryptal\DefaultAlgorithms\ChaCha20::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 157 of file ChaCha20.php.

References fpoirotte\Cryptal\Implementers\AbstractMac\mac().

fpoirotte\Cryptal\DefaultAlgorithms\ChaCha20::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 134 of file ChaCha20.php.

References fpoirotte\Cryptal\Implementers\AbstractMac\mac().

fpoirotte\Cryptal\DefaultAlgorithms\ChaCha20::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 189 of file ChaCha20.php.

fpoirotte\Cryptal\DefaultAlgorithms\ChaCha20::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 196 of file ChaCha20.php.

fpoirotte\Cryptal\DefaultAlgorithms\ChaCha20::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 184 of file ChaCha20.php.

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

fpoirotte\Cryptal\DefaultAlgorithms\ChaCha20::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 201 of file ChaCha20.php.

References fpoirotte\Cryptal\DefaultAlgorithms\ChaCha20\$key.


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