[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/vendor/phpseclib/phpseclib/phpseclib/Crypt/ -> ChaCha20.php (summary)

Pure-PHP implementation of ChaCha20. PHP version 5

Author: Jim Wigginton
Copyright: 2019 Jim Wigginton
License: http://www.opensource.org/licenses/mit-license.html MIT License
Link: http://phpseclib.sourceforge.net
File Size: 799 lines (37 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

ChaCha20:: (10 methods):
  isValidEngineHelper()
  encrypt()
  decrypt()
  encrypt_with_libsodium()
  decrypt_with_libsodium()
  setNonce()
  setup()
  quarterRound()
  doubleRound()
  salsa20()


Class: ChaCha20  - X-Ref

Pure-PHP implementation of ChaCha20.

isValidEngineHelper($engine)   X-Ref
Test for engine validity

This is mainly just a wrapper to set things up for \phpseclib3\Crypt\Common\SymmetricKey::isValidEngine()

see: \phpseclib3\Crypt\Common\SymmetricKey::__construct()
return: bool
param: int $engine

encrypt($plaintext)   X-Ref
Encrypts a message.

see: \phpseclib3\Crypt\Common\SymmetricKey::decrypt()
see: self::crypt()
return: string $ciphertext
param: string $plaintext

decrypt($ciphertext)   X-Ref
Decrypts a message.

$this->decrypt($this->encrypt($plaintext)) == $this->encrypt($this->encrypt($plaintext)).
At least if the continuous buffer is disabled.

see: \phpseclib3\Crypt\Common\SymmetricKey::encrypt()
see: self::crypt()
return: string $plaintext
param: string $ciphertext

encrypt_with_libsodium($plaintext)   X-Ref
Encrypts a message with libsodium

see: self::encrypt()
return: string $text
param: string $plaintext

decrypt_with_libsodium($ciphertext)   X-Ref
Decrypts a message with libsodium

see: self::decrypt()
return: string $text
param: string $ciphertext

setNonce($nonce)   X-Ref
Sets the nonce.

param: string $nonce

setup()   X-Ref
Setup the self::ENGINE_INTERNAL $engine

(re)init, if necessary, the internal cipher $engine

_setup() will be called each time if $changed === true
typically this happens when using one or more of following public methods:

- setKey()

- setNonce()

- First run of encrypt() / decrypt() with no init-settings

see: self::setKey()
see: self::setNonce()
see: self::disableContinuousBuffer()

quarterRound(&$a, &$b, &$c, &$d)   X-Ref
The quarterround function

param: int $a
param: int $b
param: int $c
param: int $d

doubleRound(&$x0, &$x1, &$x2, &$x3, &$x4, &$x5, &$x6, &$x7, &$x8, &$x9, &$x10, &$x11, &$x12, &$x13, &$x14, &$x15)   X-Ref
The doubleround function

param: int $x0 (by reference)
param: int $x1 (by reference)
param: int $x2 (by reference)
param: int $x3 (by reference)
param: int $x4 (by reference)
param: int $x5 (by reference)
param: int $x6 (by reference)
param: int $x7 (by reference)
param: int $x8 (by reference)
param: int $x9 (by reference)
param: int $x10 (by reference)
param: int $x11 (by reference)
param: int $x12 (by reference)
param: int $x13 (by reference)
param: int $x14 (by reference)
param: int $x15 (by reference)

salsa20($x)   X-Ref
The Salsa20 hash function function

On my laptop this loop unrolled / function dereferenced version of parent::salsa20 encrypts 1mb of text in
0.65s vs the 0.85s that it takes with the parent method.

If we were free to assume that the host OS would always be 64-bits then the if condition in leftRotate could
be eliminated and we could knock this done to 0.60s.

For comparison purposes, RC4 takes 0.16s and AES in CTR mode with the Eval engine takes 0.48s.
AES in CTR mode with the PHP engine takes 1.19s. Salsa20 / ChaCha20 do not benefit as much from the Eval
approach due to the fact that there are a lot less variables to de-reference, fewer loops to unroll, etc

param: string $x