Documentation

TripleDES extends DES
in package

Pure-PHP implementation of Triple DES.

Tags
author

Jim Wigginton terrafrost@php.net

access

public

Table of Contents

Constants

DECRYPT  = 1
Contains $keys[self::DECRYPT]
ENCRYPT  = 0
Contains $keys[self::ENCRYPT]
ENGINE_EVAL  = 2
Base value for the eval() implementation $engine switch
ENGINE_INTERNAL  = 1
Base value for the internal implementation $engine switch
ENGINE_LIBSODIUM  = 5
Base value for the libsodium implementation $engine switch
ENGINE_MAP  = [self::ENGINE_INTERNAL => 'PHP', self::ENGINE_EVAL => 'Eval', self::ENGINE_MCRYPT => 'mcrypt', self::ENGINE_OPENSSL => 'OpenSSL', self::ENGINE_LIBSODIUM => 'libsodium', self::ENGINE_OPENSSL_GCM => 'OpenSSL (GCM)']
Engine Reverse Map
ENGINE_MCRYPT  = 3
Base value for the mcrypt implementation $engine switch
ENGINE_OPENSSL  = 4
Base value for the openssl implementation $engine switch
ENGINE_OPENSSL_GCM  = 6
Base value for the openssl / gcm implementation $engine switch
MODE_3CBC  = -2
Encrypt / decrypt using inner chaining
MODE_CBC  = 2
Encrypt / decrypt using the Code Book Chaining mode.
MODE_CBC3  = self::MODE_CBC
Encrypt / decrypt using outer chaining
MODE_CFB  = 3
Encrypt / decrypt using the Cipher Feedback mode.
MODE_CFB8  = 38
Encrypt / decrypt using the Cipher Feedback mode (8bit)
MODE_CTR  = -1
Encrypt / decrypt using the Counter mode.
MODE_ECB  = 1
Encrypt / decrypt using the Electronic Code Book mode.
MODE_GCM  = 5
Encrypt / decrypt using Galois/Counter mode.
MODE_MAP  = ['ctr' => self::MODE_CTR, 'ecb' => self::MODE_ECB, 'cbc' => self::MODE_CBC, 'cfb' => self::MODE_CFB, 'cfb8' => self::MODE_CFB8, 'ofb' => self::MODE_OFB, 'gcm' => self::MODE_GCM, 'stream' => self::MODE_STREAM]
Mode Map
MODE_OFB  = 4
Encrypt / decrypt using the Output Feedback mode.
MODE_STREAM  = 6
Encrypt / decrypt using streaming mode.

Properties

$aad  : string
Additional authenticated data
$block_size  : int
Block Length of the cipher
$cfb_init_len  : int
Optimizing value while CFB-encrypting
$changed  : bool
Does internal cipher state need to be (re)initialized?
$cipher_name_mcrypt  : string
The mcrypt specific name of the cipher
$cipher_name_openssl  : string
The openssl specific name of the cipher
$cipher_name_openssl_ecb  : string
The openssl specific name of the cipher in ECB mode
$continuousBuffer  : bool
Continuous Buffer status
$debuffer  : array<string|int, mixed>
Decryption buffer for CTR, OFB and CFB modes
$decryptIV  : string
A "sliding" Initialization Vector
$des_rounds  : int
Switch for DES/3DES encryption
$enbuffer  : array<string|int, mixed>
Encryption buffer for CTR, OFB and CFB modes
$encryptIV  : string
A "sliding" Initialization Vector
$engine  : int
Holds which crypt engine internaly should be use, which will be determined automatically on __construct()
$explicit_key_length  : bool
Has the key length explicitly been set or should it be derived from the key, itself?
$inline_crypt  : callable
The name of the performance-optimized callback function
$invipmap  : array<string|int, mixed>
Inverse IP mapping helper table.
$ipmap  : array<string|int, mixed>
IP mapping helper table.
$iv  : string
The Initialization Vector
$key  : string
The Key
$key_length  : int
Key Length (in bytes)
$key_length_max  : string
max possible size of $key
$mode  : int
The Encryption Mode
$newtag  : string
Authentication Tag produced after a round of encryption
$nonce  : string
Nonce
$nonIVChanged  : bool
Does Eval engie need to be (re)initialized?
$oldtag  : string
Authentication Tag to be verified during decryption
$openssl_mode_names  : array<string|int, mixed>
The OpenSSL names of the cipher / modes
$poly1305Key  : string
Poly1305 Key
$sbox1  : array<string|int, mixed>
Pre-permuted S-box1
$sbox2  : array<string|int, mixed>
Pre-permuted S-box2
$sbox3  : array<string|int, mixed>
Pre-permuted S-box3
$sbox4  : array<string|int, mixed>
Pre-permuted S-box4
$sbox5  : array<string|int, mixed>
Pre-permuted S-box5
$sbox6  : array<string|int, mixed>
Pre-permuted S-box6
$sbox7  : array<string|int, mixed>
Pre-permuted S-box7
$sbox8  : array<string|int, mixed>
Pre-permuted S-box8
$shuffle  : array<string|int, mixed>
Shuffle table.
$usePoly1305  : bool
Poly1305 Flag
$dechanged  : bool
Does the demcrypt resource need to be (re)initialized?
$demcrypt  : resource
mcrypt resource for decryption
$des  : array<string|int, mixed>
The \phpseclib3\Crypt\DES objects
$ecb  : resource
mcrypt resource for CFB mode
$enchanged  : bool
Does the enmcrypt resource need to be (re)initialized?
$enmcrypt  : resource
mcrypt resource for encryption
$gcmField  : BinaryField
GCM Binary Field
$h  : Integer
Hash subkey for GHASH
$keys  : array<string|int, mixed>
The Key Schedule
$mode_3cbc  : bool
Internal flag whether using self::MODE_3CBC or not
$openssl_emulate_ctr  : bool
If OpenSSL can be used in ECB but not in CTR we can emulate CTR
$origIV  : string
The Original Initialization Vector
$paddable  : bool
Is the mode one that is paddable?
$padding  : bool
Padding status
$password_default_salt  : string
The default salt used by setPassword()
$poly1305Field  : PrimeField
Poly1305 Prime Field
$preferredEngine  : int
Holds the preferred crypt engine
$skip_key_adjustment  : bool
Don't truncate / null pad key

Methods

__construct()  : mixed
Default Constructor.
decrypt()  : string
Decrypts a message.
disableContinuousBuffer()  : mixed
Treat consecutive packets as if they are a discontinuous buffer.
disablePadding()  : mixed
Do not pad packets.
enableContinuousBuffer()  : mixed
Treat consecutive "packets" as if they are a continuous buffer.
enablePadding()  : mixed
Pad "packets".
enablePoly1305()  : mixed
Enables Poly1305 mode.
encrypt()  : string
Encrypts a message.
getBlockLength()  : int
Returns the current block length in bits
getBlockLengthInBytes()  : int
Returns the current block length in bytes
getEngine()  : mixed
Returns the engine currently being utilized
getKeyLength()  : int
Returns the current key length in bits
getTag()  : string
Get the authentication tag
isValidEngine()  : bool
Test for engine validity
setAAD()  : mixed
Sets additional authenticated data
setIV()  : mixed
Sets the initialization vector.
setKey()  : mixed
Sets the key.
setKeyLength()  : mixed
Sets the key length.
setNonce()  : mixed
Sets the nonce.
setPassword()  : bool
Sets the password.
setPoly1305Key()  : mixed
Enables Poly1305 mode.
setPreferredEngine()  : mixed
Sets the internal crypt engine
setTag()  : mixed
Sets the authentication tag
usesIV()  : bool
Returns whether or not the algorithm uses an IV
usesNonce()  : bool
Returns whether or not the algorithm uses a nonce
createInlineCryptFunction()  : string
Creates the performance-optimized function for en/decrypt()
decryptBlock()  : string
Decrypts a block
encryptBlock()  : string
Encrypts a block
getIV()  : string
Get the IV
isValidEngineHelper()  : bool
Test for engine validity
nullPad128()  : string
NULL pads a string to be a multiple of 128
openssl_translate_mode()  : string
phpseclib <-> OpenSSL Mode Mapper
pad()  : string
Pads a string
poly1305()  : string
Calculates Poly1305 MAC
safe_intval()  : int
Convert float to int
safe_intval_inline()  : string
eval()'able string for in-line float to int
setEngine()  : mixed
Sets the engine as appropriate
setup()  : mixed
Setup the self::ENGINE_INTERNAL $engine
setupInlineCrypt()  : mixed
Setup the performance-optimized function for de/encrypt()
setupKey()  : mixed
Creates the key schedule
unpad()  : string
Unpads a string.
ghash()  : string
Performs GHASH operation
len64()  : string
Returns the bit length of a string in a packed format
openssl_ctr_process()  : string
OpenSSL CTR Processor
openssl_ofb_process()  : string
OpenSSL OFB Processor
pkcs12helper()  : string
PKCS#12 KDF Helper Function
processBlock()  : string
Encrypts or decrypts a 64-bit block
setupGCM()  : mixed
Sets up GCM parameters

Constants

ENGINE_MAP

Engine Reverse Map

public mixed ENGINE_MAP = [self::ENGINE_INTERNAL => 'PHP', self::ENGINE_EVAL => 'Eval', self::ENGINE_MCRYPT => 'mcrypt', self::ENGINE_OPENSSL => 'OpenSSL', self::ENGINE_LIBSODIUM => 'libsodium', self::ENGINE_OPENSSL_GCM => 'OpenSSL (GCM)']
Tags
access

private

see
SymmetricKey::getEngine()

MODE_3CBC

Encrypt / decrypt using inner chaining

public mixed MODE_3CBC = -2

Inner chaining is used by SSH-1 and is generally considered to be less secure then outer chaining (self::MODE_CBC3).

MODE_CBC3

Encrypt / decrypt using outer chaining

public mixed MODE_CBC3 = self::MODE_CBC

Outer chaining is used by SSH-2 and when the mode is set to \phpseclib3\Crypt\Common\BlockCipher::MODE_CBC.

MODE_MAP

Mode Map

public mixed MODE_MAP = ['ctr' => self::MODE_CTR, 'ecb' => self::MODE_ECB, 'cbc' => self::MODE_CBC, 'cfb' => self::MODE_CFB, 'cfb8' => self::MODE_CFB8, 'ofb' => self::MODE_OFB, 'gcm' => self::MODE_GCM, 'stream' => self::MODE_STREAM]
Tags
access

private

see
SymmetricKey::__construct()

Properties

$aad

Additional authenticated data

protected string $aad = ''
Tags
access

private

$block_size

Block Length of the cipher

protected int $block_size = 8
Tags
see
SymmetricKey::block_size
access

private

$cfb_init_len

Optimizing value while CFB-encrypting

protected int $cfb_init_len = 750
Tags
see
SymmetricKey::cfb_init_len
access

private

$changed

Does internal cipher state need to be (re)initialized?

protected bool $changed = true
Tags
see
self::setKey()
see
self::setIV()
see
self::disableContinuousBuffer()
access

private

$cipher_name_mcrypt

The mcrypt specific name of the cipher

protected string $cipher_name_mcrypt = 'tripledes'
Tags
see
DES::cipher_name_mcrypt
see
SymmetricKey::cipher_name_mcrypt
access

private

$cipher_name_openssl_ecb

The openssl specific name of the cipher in ECB mode

protected string $cipher_name_openssl_ecb

If OpenSSL does not support the mode we're trying to use (CTR) it can still be emulated with ECB mode.

Tags
link
http://www.php.net/openssl-get-cipher-methods
access

private

$continuousBuffer

Continuous Buffer status

protected bool $continuousBuffer = false
Tags
see
self::enableContinuousBuffer()
access

private

$debuffer

Decryption buffer for CTR, OFB and CFB modes

protected array<string|int, mixed> $debuffer
Tags
see
self::decrypt()
see
self::clearBuffers()
access

private

$decryptIV

A "sliding" Initialization Vector

protected string $decryptIV
Tags
see
self::enableContinuousBuffer()
see
self::clearBuffers()
access

private

$des_rounds

Switch for DES/3DES encryption

protected int $des_rounds = 1

Used only if $engine == self::ENGINE_INTERNAL

Tags
see
self::setupKey()
see
self::processBlock()
access

private

$enbuffer

Encryption buffer for CTR, OFB and CFB modes

protected array<string|int, mixed> $enbuffer
Tags
see
self::encrypt()
see
self::clearBuffers()
access

private

$encryptIV

A "sliding" Initialization Vector

protected string $encryptIV
Tags
see
self::enableContinuousBuffer()
see
self::clearBuffers()
access

private

$engine

Holds which crypt engine internaly should be use, which will be determined automatically on __construct()

protected int $engine

Currently available $engines are:

  • self::ENGINE_LIBSODIUM (very fast, php-extension: libsodium, extension_loaded('libsodium') required)
  • self::ENGINE_OPENSSL_GCM (very fast, php-extension: openssl, extension_loaded('openssl') required)
  • self::ENGINE_OPENSSL (very fast, php-extension: openssl, extension_loaded('openssl') required)
  • self::ENGINE_MCRYPT (fast, php-extension: mcrypt, extension_loaded('mcrypt') required)
  • self::ENGINE_EVAL (medium, pure php-engine, no php-extension required)
  • self::ENGINE_INTERNAL (slower, pure php-engine, no php-extension required)
Tags
see
self::setEngine()
see
self::encrypt()
see
self::decrypt()
access

private

$explicit_key_length

Has the key length explicitly been set or should it be derived from the key, itself?

protected bool $explicit_key_length = false
Tags
see
self::setKeyLength()
access

private

$inline_crypt

The name of the performance-optimized callback function

protected callable $inline_crypt

Used by encrypt() / decrypt() only if $engine == self::ENGINE_INTERNAL

Tags
see
self::encrypt()
see
self::decrypt()
see
self::setupInlineCrypt()
access

private

$invipmap

Inverse IP mapping helper table.

protected static array<string|int, mixed> $invipmap = [0x0, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0, 0x8, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8, 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8, 0x4, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4, 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4, 0xc, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec, 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc, 0x2, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2, 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2, 0xa, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea, 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa, 0x6, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6, 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6, 0xe, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee, 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe, 0x1, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1, 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1, 0x9, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9, 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9, 0x5, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5, 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5, 0xd, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed, 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd, 0x3, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3, 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3, 0xb, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb, 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb, 0x7, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7, 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7, 0xf, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef, 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff]

Indexing this table with a byte value reverses the bit order.

Tags
access

private

$ipmap

IP mapping helper table.

protected static array<string|int, mixed> $ipmap = [0x0, 0x10, 0x1, 0x11, 0x20, 0x30, 0x21, 0x31, 0x2, 0x12, 0x3, 0x13, 0x22, 0x32, 0x23, 0x33, 0x40, 0x50, 0x41, 0x51, 0x60, 0x70, 0x61, 0x71, 0x42, 0x52, 0x43, 0x53, 0x62, 0x72, 0x63, 0x73, 0x4, 0x14, 0x5, 0x15, 0x24, 0x34, 0x25, 0x35, 0x6, 0x16, 0x7, 0x17, 0x26, 0x36, 0x27, 0x37, 0x44, 0x54, 0x45, 0x55, 0x64, 0x74, 0x65, 0x75, 0x46, 0x56, 0x47, 0x57, 0x66, 0x76, 0x67, 0x77, 0x80, 0x90, 0x81, 0x91, 0xa0, 0xb0, 0xa1, 0xb1, 0x82, 0x92, 0x83, 0x93, 0xa2, 0xb2, 0xa3, 0xb3, 0xc0, 0xd0, 0xc1, 0xd1, 0xe0, 0xf0, 0xe1, 0xf1, 0xc2, 0xd2, 0xc3, 0xd3, 0xe2, 0xf2, 0xe3, 0xf3, 0x84, 0x94, 0x85, 0x95, 0xa4, 0xb4, 0xa5, 0xb5, 0x86, 0x96, 0x87, 0x97, 0xa6, 0xb6, 0xa7, 0xb7, 0xc4, 0xd4, 0xc5, 0xd5, 0xe4, 0xf4, 0xe5, 0xf5, 0xc6, 0xd6, 0xc7, 0xd7, 0xe6, 0xf6, 0xe7, 0xf7, 0x8, 0x18, 0x9, 0x19, 0x28, 0x38, 0x29, 0x39, 0xa, 0x1a, 0xb, 0x1b, 0x2a, 0x3a, 0x2b, 0x3b, 0x48, 0x58, 0x49, 0x59, 0x68, 0x78, 0x69, 0x79, 0x4a, 0x5a, 0x4b, 0x5b, 0x6a, 0x7a, 0x6b, 0x7b, 0xc, 0x1c, 0xd, 0x1d, 0x2c, 0x3c, 0x2d, 0x3d, 0xe, 0x1e, 0xf, 0x1f, 0x2e, 0x3e, 0x2f, 0x3f, 0x4c, 0x5c, 0x4d, 0x5d, 0x6c, 0x7c, 0x6d, 0x7d, 0x4e, 0x5e, 0x4f, 0x5f, 0x6e, 0x7e, 0x6f, 0x7f, 0x88, 0x98, 0x89, 0x99, 0xa8, 0xb8, 0xa9, 0xb9, 0x8a, 0x9a, 0x8b, 0x9b, 0xaa, 0xba, 0xab, 0xbb, 0xc8, 0xd8, 0xc9, 0xd9, 0xe8, 0xf8, 0xe9, 0xf9, 0xca, 0xda, 0xcb, 0xdb, 0xea, 0xfa, 0xeb, 0xfb, 0x8c, 0x9c, 0x8d, 0x9d, 0xac, 0xbc, 0xad, 0xbd, 0x8e, 0x9e, 0x8f, 0x9f, 0xae, 0xbe, 0xaf, 0xbf, 0xcc, 0xdc, 0xcd, 0xdd, 0xec, 0xfc, 0xed, 0xfd, 0xce, 0xde, 0xcf, 0xdf, 0xee, 0xfe, 0xef, 0xff]

Indexing this table with each source byte performs the initial bit permutation.

Tags
access

private

$iv

The Initialization Vector

protected string $iv = false
Tags
see
self::setIV()
access

private

$key

The Key

protected string $key = false
Tags
see
self::setKey()
access

private

$key_length_max

max possible size of $key

protected string $key_length_max = 24
Tags
see
self::setKey()
see
DES::setKey()
access

private

$mode

The Encryption Mode

protected int $mode
Tags
see
self::__construct()
access

private

$newtag

Authentication Tag produced after a round of encryption

protected string $newtag = false
Tags
access

private

$nonce

Nonce

protected string $nonce = false

Only used with GCM. We could re-use setIV() but nonce's can be of a different length and toggling between GCM and other modes could be more complicated if we re-used setIV()

Tags
see
self::setNonce()
access

private

$nonIVChanged

Does Eval engie need to be (re)initialized?

protected bool $nonIVChanged = true
Tags
see
self::setup()
access

private

$oldtag

Authentication Tag to be verified during decryption

protected string $oldtag = false
Tags
access

private

$openssl_mode_names

The OpenSSL names of the cipher / modes

protected array<string|int, mixed> $openssl_mode_names = [self::MODE_ECB => 'des-ecb', self::MODE_CBC => 'des-cbc', self::MODE_CFB => 'des-cfb', self::MODE_OFB => 'des-ofb']
Tags
see
SymmetricKey::openssl_mode_names
access

private

$poly1305Key

Poly1305 Key

protected string $poly1305Key
Tags
see
self::setPoly1305Key()
see
self::poly1305()
access

private

$sbox1

Pre-permuted S-box1

protected static array<string|int, mixed> $sbox1 = [0x808200, 0x0, 0x8000, 0x808202, 0x808002, 0x8202, 0x2, 0x8000, 0x200, 0x808200, 0x808202, 0x200, 0x800202, 0x808002, 0x800000, 0x2, 0x202, 0x800200, 0x800200, 0x8200, 0x8200, 0x808000, 0x808000, 0x800202, 0x8002, 0x800002, 0x800002, 0x8002, 0x0, 0x202, 0x8202, 0x800000, 0x8000, 0x808202, 0x2, 0x808000, 0x808200, 0x800000, 0x800000, 0x200, 0x808002, 0x8000, 0x8200, 0x800002, 0x200, 0x2, 0x800202, 0x8202, 0x808202, 0x8002, 0x808000, 0x800202, 0x800002, 0x202, 0x8202, 0x808200, 0x202, 0x800200, 0x800200, 0x0, 0x8002, 0x8200, 0x0, 0x808002]

Each box ($sbox1-$sbox8) has been vectorized, then each value pre-permuted using the P table: concatenation can then be replaced by exclusive ORs.

Tags
access

private

$sbox2

Pre-permuted S-box2

protected static array<string|int, mixed> $sbox2 = [0x40084010, 0x40004000, 0x4000, 0x84010, 0x80000, 0x10, 0x40080010, 0x40004010, 0x40000010, 0x40084010, 0x40084000, 0x40000000, 0x40004000, 0x80000, 0x10, 0x40080010, 0x84000, 0x80010, 0x40004010, 0x0, 0x40000000, 0x4000, 0x84010, 0x40080000, 0x80010, 0x40000010, 0x0, 0x84000, 0x4010, 0x40084000, 0x40080000, 0x4010, 0x0, 0x84010, 0x40080010, 0x80000, 0x40004010, 0x40080000, 0x40084000, 0x4000, 0x40080000, 0x40004000, 0x10, 0x40084010, 0x84010, 0x10, 0x4000, 0x40000000, 0x4010, 0x40084000, 0x80000, 0x40000010, 0x80010, 0x40004010, 0x40000010, 0x80010, 0x84000, 0x0, 0x40004000, 0x4010, 0x40000000, 0x40080010, 0x40084010, 0x84000]
Tags
access

private

$sbox3

Pre-permuted S-box3

protected static array<string|int, mixed> $sbox3 = [0x104, 0x4010100, 0x0, 0x4010004, 0x4000100, 0x0, 0x10104, 0x4000100, 0x10004, 0x4000004, 0x4000004, 0x10000, 0x4010104, 0x10004, 0x4010000, 0x104, 0x4000000, 0x4, 0x4010100, 0x100, 0x10100, 0x4010000, 0x4010004, 0x10104, 0x4000104, 0x10100, 0x10000, 0x4000104, 0x4, 0x4010104, 0x100, 0x4000000, 0x4010100, 0x4000000, 0x10004, 0x104, 0x10000, 0x4010100, 0x4000100, 0x0, 0x100, 0x10004, 0x4010104, 0x4000100, 0x4000004, 0x100, 0x0, 0x4010004, 0x4000104, 0x10000, 0x4000000, 0x4010104, 0x4, 0x10104, 0x10100, 0x4000004, 0x4010000, 0x4000104, 0x104, 0x4010000, 0x10104, 0x4, 0x4010004, 0x10100]
Tags
access

private

$sbox4

Pre-permuted S-box4

protected static array<string|int, mixed> $sbox4 = [0x80401000, 0x80001040, 0x80001040, 0x40, 0x401040, 0x80400040, 0x80400000, 0x80001000, 0x0, 0x401000, 0x401000, 0x80401040, 0x80000040, 0x0, 0x400040, 0x80400000, 0x80000000, 0x1000, 0x400000, 0x80401000, 0x40, 0x400000, 0x80001000, 0x1040, 0x80400040, 0x80000000, 0x1040, 0x400040, 0x1000, 0x401040, 0x80401040, 0x80000040, 0x400040, 0x80400000, 0x401000, 0x80401040, 0x80000040, 0x0, 0x0, 0x401000, 0x1040, 0x400040, 0x80400040, 0x80000000, 0x80401000, 0x80001040, 0x80001040, 0x40, 0x80401040, 0x80000040, 0x80000000, 0x1000, 0x80400000, 0x80001000, 0x401040, 0x80400040, 0x80001000, 0x1040, 0x400000, 0x80401000, 0x40, 0x400000, 0x1000, 0x401040]
Tags
access

private

$sbox5

Pre-permuted S-box5

protected static array<string|int, mixed> $sbox5 = [0x80, 0x1040080, 0x1040000, 0x21000080, 0x40000, 0x80, 0x20000000, 0x1040000, 0x20040080, 0x40000, 0x1000080, 0x20040080, 0x21000080, 0x21040000, 0x40080, 0x20000000, 0x1000000, 0x20040000, 0x20040000, 0x0, 0x20000080, 0x21040080, 0x21040080, 0x1000080, 0x21040000, 0x20000080, 0x0, 0x21000000, 0x1040080, 0x1000000, 0x21000000, 0x40080, 0x40000, 0x21000080, 0x80, 0x1000000, 0x20000000, 0x1040000, 0x21000080, 0x20040080, 0x1000080, 0x20000000, 0x21040000, 0x1040080, 0x20040080, 0x80, 0x1000000, 0x21040000, 0x21040080, 0x40080, 0x21000000, 0x21040080, 0x1040000, 0x0, 0x20040000, 0x21000000, 0x40080, 0x1000080, 0x20000080, 0x40000, 0x0, 0x20040000, 0x1040080, 0x20000080]
Tags
access

private

$sbox6

Pre-permuted S-box6

protected static array<string|int, mixed> $sbox6 = [0x10000008, 0x10200000, 0x2000, 0x10202008, 0x10200000, 0x8, 0x10202008, 0x200000, 0x10002000, 0x202008, 0x200000, 0x10000008, 0x200008, 0x10002000, 0x10000000, 0x2008, 0x0, 0x200008, 0x10002008, 0x2000, 0x202000, 0x10002008, 0x8, 0x10200008, 0x10200008, 0x0, 0x202008, 0x10202000, 0x2008, 0x202000, 0x10202000, 0x10000000, 0x10002000, 0x8, 0x10200008, 0x202000, 0x10202008, 0x200000, 0x2008, 0x10000008, 0x200000, 0x10002000, 0x10000000, 0x2008, 0x10000008, 0x10202008, 0x202000, 0x10200000, 0x202008, 0x10202000, 0x0, 0x10200008, 0x8, 0x2000, 0x10200000, 0x202008, 0x2000, 0x200008, 0x10002008, 0x0, 0x10202000, 0x10000000, 0x200008, 0x10002008]
Tags
access

private

$sbox7

Pre-permuted S-box7

protected static array<string|int, mixed> $sbox7 = [0x100000, 0x2100001, 0x2000401, 0x0, 0x400, 0x2000401, 0x100401, 0x2100400, 0x2100401, 0x100000, 0x0, 0x2000001, 0x1, 0x2000000, 0x2100001, 0x401, 0x2000400, 0x100401, 0x100001, 0x2000400, 0x2000001, 0x2100000, 0x2100400, 0x100001, 0x2100000, 0x400, 0x401, 0x2100401, 0x100400, 0x1, 0x2000000, 0x100400, 0x2000000, 0x100400, 0x100000, 0x2000401, 0x2000401, 0x2100001, 0x2100001, 0x1, 0x100001, 0x2000000, 0x2000400, 0x100000, 0x2100400, 0x401, 0x100401, 0x2100400, 0x401, 0x2000001, 0x2100401, 0x2100000, 0x100400, 0x0, 0x1, 0x2100401, 0x0, 0x100401, 0x2100000, 0x400, 0x2000001, 0x2000400, 0x400, 0x100001]
Tags
access

private

$sbox8

Pre-permuted S-box8

protected static array<string|int, mixed> $sbox8 = [0x8000820, 0x800, 0x20000, 0x8020820, 0x8000000, 0x8000820, 0x20, 0x8000000, 0x20020, 0x8020000, 0x8020820, 0x20800, 0x8020800, 0x20820, 0x800, 0x20, 0x8020000, 0x8000020, 0x8000800, 0x820, 0x20800, 0x20020, 0x8020020, 0x8020800, 0x820, 0x0, 0x0, 0x8020020, 0x8000020, 0x8000800, 0x20820, 0x20000, 0x20820, 0x20000, 0x8020800, 0x800, 0x20, 0x8020020, 0x800, 0x20820, 0x8000800, 0x20, 0x8000020, 0x8020000, 0x8020020, 0x8000000, 0x20000, 0x8000820, 0x0, 0x8020820, 0x20020, 0x8000020, 0x8020000, 0x8000800, 0x8000820, 0x0, 0x8020820, 0x20800, 0x20800, 0x820, 0x820, 0x20020, 0x8000000, 0x8020800]
Tags
access

private

$shuffle

Shuffle table.

protected static array<string|int, mixed> $shuffle = ["\x00\x00\x00\x00\x00\x00\x00\x00", "\x00\x00\x00\x00\x00\x00\x00\xff", "\x00\x00\x00\x00\x00\x00\xff\x00", "\x00\x00\x00\x00\x00\x00\xff\xff", "\x00\x00\x00\x00\x00\xff\x00\x00", "\x00\x00\x00\x00\x00\xff\x00\xff", "\x00\x00\x00\x00\x00\xff\xff\x00", "\x00\x00\x00\x00\x00\xff\xff\xff", "\x00\x00\x00\x00\xff\x00\x00\x00", "\x00\x00\x00\x00\xff\x00\x00\xff", "\x00\x00\x00\x00\xff\x00\xff\x00", "\x00\x00\x00\x00\xff\x00\xff\xff", "\x00\x00\x00\x00\xff\xff\x00\x00", "\x00\x00\x00\x00\xff\xff\x00\xff", "\x00\x00\x00\x00\xff\xff\xff\x00", "\x00\x00\x00\x00\xff\xff\xff\xff", "\x00\x00\x00\xff\x00\x00\x00\x00", "\x00\x00\x00\xff\x00\x00\x00\xff", "\x00\x00\x00\xff\x00\x00\xff\x00", "\x00\x00\x00\xff\x00\x00\xff\xff", "\x00\x00\x00\xff\x00\xff\x00\x00", "\x00\x00\x00\xff\x00\xff\x00\xff", "\x00\x00\x00\xff\x00\xff\xff\x00", "\x00\x00\x00\xff\x00\xff\xff\xff", "\x00\x00\x00\xff\xff\x00\x00\x00", "\x00\x00\x00\xff\xff\x00\x00\xff", "\x00\x00\x00\xff\xff\x00\xff\x00", "\x00\x00\x00\xff\xff\x00\xff\xff", "\x00\x00\x00\xff\xff\xff\x00\x00", "\x00\x00\x00\xff\xff\xff\x00\xff", "\x00\x00\x00\xff\xff\xff\xff\x00", "\x00\x00\x00\xff\xff\xff\xff\xff", "\x00\x00\xff\x00\x00\x00\x00\x00", "\x00\x00\xff\x00\x00\x00\x00\xff", "\x00\x00\xff\x00\x00\x00\xff\x00", "\x00\x00\xff\x00\x00\x00\xff\xff", "\x00\x00\xff\x00\x00\xff\x00\x00", "\x00\x00\xff\x00\x00\xff\x00\xff", "\x00\x00\xff\x00\x00\xff\xff\x00", "\x00\x00\xff\x00\x00\xff\xff\xff", "\x00\x00\xff\x00\xff\x00\x00\x00", "\x00\x00\xff\x00\xff\x00\x00\xff", "\x00\x00\xff\x00\xff\x00\xff\x00", "\x00\x00\xff\x00\xff\x00\xff\xff", "\x00\x00\xff\x00\xff\xff\x00\x00", "\x00\x00\xff\x00\xff\xff\x00\xff", "\x00\x00\xff\x00\xff\xff\xff\x00", "\x00\x00\xff\x00\xff\xff\xff\xff", "\x00\x00\xff\xff\x00\x00\x00\x00", "\x00\x00\xff\xff\x00\x00\x00\xff", "\x00\x00\xff\xff\x00\x00\xff\x00", "\x00\x00\xff\xff\x00\x00\xff\xff", "\x00\x00\xff\xff\x00\xff\x00\x00", "\x00\x00\xff\xff\x00\xff\x00\xff", "\x00\x00\xff\xff\x00\xff\xff\x00", "\x00\x00\xff\xff\x00\xff\xff\xff", "\x00\x00\xff\xff\xff\x00\x00\x00", "\x00\x00\xff\xff\xff\x00\x00\xff", "\x00\x00\xff\xff\xff\x00\xff\x00", "\x00\x00\xff\xff\xff\x00\xff\xff", "\x00\x00\xff\xff\xff\xff\x00\x00", "\x00\x00\xff\xff\xff\xff\x00\xff", "\x00\x00\xff\xff\xff\xff\xff\x00", "\x00\x00\xff\xff\xff\xff\xff\xff", "\x00\xff\x00\x00\x00\x00\x00\x00", "\x00\xff\x00\x00\x00\x00\x00\xff", "\x00\xff\x00\x00\x00\x00\xff\x00", "\x00\xff\x00\x00\x00\x00\xff\xff", "\x00\xff\x00\x00\x00\xff\x00\x00", "\x00\xff\x00\x00\x00\xff\x00\xff", "\x00\xff\x00\x00\x00\xff\xff\x00", "\x00\xff\x00\x00\x00\xff\xff\xff", "\x00\xff\x00\x00\xff\x00\x00\x00", "\x00\xff\x00\x00\xff\x00\x00\xff", "\x00\xff\x00\x00\xff\x00\xff\x00", "\x00\xff\x00\x00\xff\x00\xff\xff", "\x00\xff\x00\x00\xff\xff\x00\x00", "\x00\xff\x00\x00\xff\xff\x00\xff", "\x00\xff\x00\x00\xff\xff\xff\x00", "\x00\xff\x00\x00\xff\xff\xff\xff", "\x00\xff\x00\xff\x00\x00\x00\x00", "\x00\xff\x00\xff\x00\x00\x00\xff", "\x00\xff\x00\xff\x00\x00\xff\x00", "\x00\xff\x00\xff\x00\x00\xff\xff", "\x00\xff\x00\xff\x00\xff\x00\x00", "\x00\xff\x00\xff\x00\xff\x00\xff", "\x00\xff\x00\xff\x00\xff\xff\x00", "\x00\xff\x00\xff\x00\xff\xff\xff", "\x00\xff\x00\xff\xff\x00\x00\x00", "\x00\xff\x00\xff\xff\x00\x00\xff", "\x00\xff\x00\xff\xff\x00\xff\x00", "\x00\xff\x00\xff\xff\x00\xff\xff", "\x00\xff\x00\xff\xff\xff\x00\x00", "\x00\xff\x00\xff\xff\xff\x00\xff", "\x00\xff\x00\xff\xff\xff\xff\x00", "\x00\xff\x00\xff\xff\xff\xff\xff", "\x00\xff\xff\x00\x00\x00\x00\x00", "\x00\xff\xff\x00\x00\x00\x00\xff", "\x00\xff\xff\x00\x00\x00\xff\x00", "\x00\xff\xff\x00\x00\x00\xff\xff", "\x00\xff\xff\x00\x00\xff\x00\x00", "\x00\xff\xff\x00\x00\xff\x00\xff", "\x00\xff\xff\x00\x00\xff\xff\x00", "\x00\xff\xff\x00\x00\xff\xff\xff", "\x00\xff\xff\x00\xff\x00\x00\x00", "\x00\xff\xff\x00\xff\x00\x00\xff", "\x00\xff\xff\x00\xff\x00\xff\x00", "\x00\xff\xff\x00\xff\x00\xff\xff", "\x00\xff\xff\x00\xff\xff\x00\x00", "\x00\xff\xff\x00\xff\xff\x00\xff", "\x00\xff\xff\x00\xff\xff\xff\x00", "\x00\xff\xff\x00\xff\xff\xff\xff", "\x00\xff\xff\xff\x00\x00\x00\x00", "\x00\xff\xff\xff\x00\x00\x00\xff", "\x00\xff\xff\xff\x00\x00\xff\x00", "\x00\xff\xff\xff\x00\x00\xff\xff", "\x00\xff\xff\xff\x00\xff\x00\x00", "\x00\xff\xff\xff\x00\xff\x00\xff", "\x00\xff\xff\xff\x00\xff\xff\x00", "\x00\xff\xff\xff\x00\xff\xff\xff", "\x00\xff\xff\xff\xff\x00\x00\x00", "\x00\xff\xff\xff\xff\x00\x00\xff", "\x00\xff\xff\xff\xff\x00\xff\x00", "\x00\xff\xff\xff\xff\x00\xff\xff", "\x00\xff\xff\xff\xff\xff\x00\x00", "\x00\xff\xff\xff\xff\xff\x00\xff", "\x00\xff\xff\xff\xff\xff\xff\x00", "\x00\xff\xff\xff\xff\xff\xff\xff", "\xff\x00\x00\x00\x00\x00\x00\x00", "\xff\x00\x00\x00\x00\x00\x00\xff", "\xff\x00\x00\x00\x00\x00\xff\x00", "\xff\x00\x00\x00\x00\x00\xff\xff", "\xff\x00\x00\x00\x00\xff\x00\x00", "\xff\x00\x00\x00\x00\xff\x00\xff", "\xff\x00\x00\x00\x00\xff\xff\x00", "\xff\x00\x00\x00\x00\xff\xff\xff", "\xff\x00\x00\x00\xff\x00\x00\x00", "\xff\x00\x00\x00\xff\x00\x00\xff", "\xff\x00\x00\x00\xff\x00\xff\x00", "\xff\x00\x00\x00\xff\x00\xff\xff", "\xff\x00\x00\x00\xff\xff\x00\x00", "\xff\x00\x00\x00\xff\xff\x00\xff", "\xff\x00\x00\x00\xff\xff\xff\x00", "\xff\x00\x00\x00\xff\xff\xff\xff", "\xff\x00\x00\xff\x00\x00\x00\x00", "\xff\x00\x00\xff\x00\x00\x00\xff", "\xff\x00\x00\xff\x00\x00\xff\x00", "\xff\x00\x00\xff\x00\x00\xff\xff", "\xff\x00\x00\xff\x00\xff\x00\x00", "\xff\x00\x00\xff\x00\xff\x00\xff", "\xff\x00\x00\xff\x00\xff\xff\x00", "\xff\x00\x00\xff\x00\xff\xff\xff", "\xff\x00\x00\xff\xff\x00\x00\x00", "\xff\x00\x00\xff\xff\x00\x00\xff", "\xff\x00\x00\xff\xff\x00\xff\x00", "\xff\x00\x00\xff\xff\x00\xff\xff", "\xff\x00\x00\xff\xff\xff\x00\x00", "\xff\x00\x00\xff\xff\xff\x00\xff", "\xff\x00\x00\xff\xff\xff\xff\x00", "\xff\x00\x00\xff\xff\xff\xff\xff", "\xff\x00\xff\x00\x00\x00\x00\x00", "\xff\x00\xff\x00\x00\x00\x00\xff", "\xff\x00\xff\x00\x00\x00\xff\x00", "\xff\x00\xff\x00\x00\x00\xff\xff", "\xff\x00\xff\x00\x00\xff\x00\x00", "\xff\x00\xff\x00\x00\xff\x00\xff", "\xff\x00\xff\x00\x00\xff\xff\x00", "\xff\x00\xff\x00\x00\xff\xff\xff", "\xff\x00\xff\x00\xff\x00\x00\x00", "\xff\x00\xff\x00\xff\x00\x00\xff", "\xff\x00\xff\x00\xff\x00\xff\x00", "\xff\x00\xff\x00\xff\x00\xff\xff", "\xff\x00\xff\x00\xff\xff\x00\x00", "\xff\x00\xff\x00\xff\xff\x00\xff", "\xff\x00\xff\x00\xff\xff\xff\x00", "\xff\x00\xff\x00\xff\xff\xff\xff", "\xff\x00\xff\xff\x00\x00\x00\x00", "\xff\x00\xff\xff\x00\x00\x00\xff", "\xff\x00\xff\xff\x00\x00\xff\x00", "\xff\x00\xff\xff\x00\x00\xff\xff", "\xff\x00\xff\xff\x00\xff\x00\x00", "\xff\x00\xff\xff\x00\xff\x00\xff", "\xff\x00\xff\xff\x00\xff\xff\x00", "\xff\x00\xff\xff\x00\xff\xff\xff", "\xff\x00\xff\xff\xff\x00\x00\x00", "\xff\x00\xff\xff\xff\x00\x00\xff", "\xff\x00\xff\xff\xff\x00\xff\x00", "\xff\x00\xff\xff\xff\x00\xff\xff", "\xff\x00\xff\xff\xff\xff\x00\x00", "\xff\x00\xff\xff\xff\xff\x00\xff", "\xff\x00\xff\xff\xff\xff\xff\x00", "\xff\x00\xff\xff\xff\xff\xff\xff", "\xff\xff\x00\x00\x00\x00\x00\x00", "\xff\xff\x00\x00\x00\x00\x00\xff", "\xff\xff\x00\x00\x00\x00\xff\x00", "\xff\xff\x00\x00\x00\x00\xff\xff", "\xff\xff\x00\x00\x00\xff\x00\x00", "\xff\xff\x00\x00\x00\xff\x00\xff", "\xff\xff\x00\x00\x00\xff\xff\x00", "\xff\xff\x00\x00\x00\xff\xff\xff", "\xff\xff\x00\x00\xff\x00\x00\x00", "\xff\xff\x00\x00\xff\x00\x00\xff", "\xff\xff\x00\x00\xff\x00\xff\x00", "\xff\xff\x00\x00\xff\x00\xff\xff", "\xff\xff\x00\x00\xff\xff\x00\x00", "\xff\xff\x00\x00\xff\xff\x00\xff", "\xff\xff\x00\x00\xff\xff\xff\x00", "\xff\xff\x00\x00\xff\xff\xff\xff", "\xff\xff\x00\xff\x00\x00\x00\x00", "\xff\xff\x00\xff\x00\x00\x00\xff", "\xff\xff\x00\xff\x00\x00\xff\x00", "\xff\xff\x00\xff\x00\x00\xff\xff", "\xff\xff\x00\xff\x00\xff\x00\x00", "\xff\xff\x00\xff\x00\xff\x00\xff", "\xff\xff\x00\xff\x00\xff\xff\x00", "\xff\xff\x00\xff\x00\xff\xff\xff", "\xff\xff\x00\xff\xff\x00\x00\x00", "\xff\xff\x00\xff\xff\x00\x00\xff", "\xff\xff\x00\xff\xff\x00\xff\x00", "\xff\xff\x00\xff\xff\x00\xff\xff", "\xff\xff\x00\xff\xff\xff\x00\x00", "\xff\xff\x00\xff\xff\xff\x00\xff", "\xff\xff\x00\xff\xff\xff\xff\x00", "\xff\xff\x00\xff\xff\xff\xff\xff", "\xff\xff\xff\x00\x00\x00\x00\x00", "\xff\xff\xff\x00\x00\x00\x00\xff", "\xff\xff\xff\x00\x00\x00\xff\x00", "\xff\xff\xff\x00\x00\x00\xff\xff", "\xff\xff\xff\x00\x00\xff\x00\x00", "\xff\xff\xff\x00\x00\xff\x00\xff", "\xff\xff\xff\x00\x00\xff\xff\x00", "\xff\xff\xff\x00\x00\xff\xff\xff", "\xff\xff\xff\x00\xff\x00\x00\x00", "\xff\xff\xff\x00\xff\x00\x00\xff", "\xff\xff\xff\x00\xff\x00\xff\x00", "\xff\xff\xff\x00\xff\x00\xff\xff", "\xff\xff\xff\x00\xff\xff\x00\x00", "\xff\xff\xff\x00\xff\xff\x00\xff", "\xff\xff\xff\x00\xff\xff\xff\x00", "\xff\xff\xff\x00\xff\xff\xff\xff", "\xff\xff\xff\xff\x00\x00\x00\x00", "\xff\xff\xff\xff\x00\x00\x00\xff", "\xff\xff\xff\xff\x00\x00\xff\x00", "\xff\xff\xff\xff\x00\x00\xff\xff", "\xff\xff\xff\xff\x00\xff\x00\x00", "\xff\xff\xff\xff\x00\xff\x00\xff", "\xff\xff\xff\xff\x00\xff\xff\x00", "\xff\xff\xff\xff\x00\xff\xff\xff", "\xff\xff\xff\xff\xff\x00\x00\x00", "\xff\xff\xff\xff\xff\x00\x00\xff", "\xff\xff\xff\xff\xff\x00\xff\x00", "\xff\xff\xff\xff\xff\x00\xff\xff", "\xff\xff\xff\xff\xff\xff\x00\x00", "\xff\xff\xff\xff\xff\xff\x00\xff", "\xff\xff\xff\xff\xff\xff\xff\x00", "\xff\xff\xff\xff\xff\xff\xff\xff"]

For each byte value index, the entry holds an 8-byte string with each byte containing all bits in the same state as the corresponding bit in the index value.

Tags
see
self::processBlock()
see
self::setupKey()
access

private

$usePoly1305

Poly1305 Flag

protected bool $usePoly1305 = false
Tags
see
self::setPoly1305Key()
see
self::enablePoly1305()
access

private

$dechanged

Does the demcrypt resource need to be (re)initialized?

private bool $dechanged = true
Tags
see
Twofish::setKey()
see
Twofish::setIV()
access

private

$demcrypt

mcrypt resource for decryption

private resource $demcrypt

The mcrypt resource can be recreated every time something needs to be created or it can be created just once. Since mcrypt operates in continuous mode, by default, it'll need to be recreated when in non-continuous mode.

Tags
see
self::decrypt()
access

private

$des

The \phpseclib3\Crypt\DES objects

private array<string|int, mixed> $des

Used only if $mode_3cbc === true

Tags
access

private

$ecb

mcrypt resource for CFB mode

private resource $ecb

mcrypt's CFB mode, in (and only in) buffered context, is broken, so phpseclib implements the CFB mode by it self, even when the mcrypt php extension is available.

In order to do the CFB-mode work (fast) phpseclib use a separate ECB-mode mcrypt resource.

Tags
link
http://phpseclib.sourceforge.net/cfb-demo.phps
see
self::encrypt()
see
self::decrypt()
see
self::setupMcrypt()
access

private

$enchanged

Does the enmcrypt resource need to be (re)initialized?

private bool $enchanged = true
Tags
see
Twofish::setKey()
see
Twofish::setIV()
access

private

$enmcrypt

mcrypt resource for encryption

private resource $enmcrypt

The mcrypt resource can be recreated every time something needs to be created or it can be created just once. Since mcrypt operates in continuous mode, by default, it'll need to be recreated when in non-continuous mode.

Tags
see
self::encrypt()
access

private

$gcmField

GCM Binary Field

private static BinaryField $gcmField
Tags
see
self::__construct()
see
self::ghash()
access

private

$h

Hash subkey for GHASH

private Integer $h
Tags
see
self::setupGCM()
see
self::ghash()
access

private

$keys

The Key Schedule

private array<string|int, mixed> $keys
Tags
see
self::setupKey()
access

private

$mode_3cbc

Internal flag whether using self::MODE_3CBC or not

private bool $mode_3cbc
Tags
access

private

$openssl_emulate_ctr

If OpenSSL can be used in ECB but not in CTR we can emulate CTR

private bool $openssl_emulate_ctr = false
Tags
see
self::openssl_ctr_process()
access

private

$origIV

The Original Initialization Vector

private string $origIV = false

GCM uses the nonce to build the IV but we want to be able to distinguish between nonce-derived IV's and user-set IV's

Tags
see
self::setIV()
access

private

$paddable

Is the mode one that is paddable?

private bool $paddable = false
Tags
see
self::__construct()
access

private

$padding

Padding status

private bool $padding = true
Tags
see
self::enablePadding()
access

private

$password_default_salt

The default salt used by setPassword()

private string $password_default_salt = 'phpseclib/salt'
Tags
see
self::setPassword()
access

private

$poly1305Field

Poly1305 Prime Field

private static PrimeField $poly1305Field
Tags
see
self::enablePoly1305()
see
self::poly1305()
access

private

$preferredEngine

Holds the preferred crypt engine

private int $preferredEngine
Tags
see
self::setEngine()
see
self::setPreferredEngine()
access

private

$skip_key_adjustment

Don't truncate / null pad key

private bool $skip_key_adjustment = false
Tags
see
self::clearBuffers()
access

private

Methods

__construct()

Default Constructor.

public __construct(string $mode) : mixed

Determines whether or not the mcrypt or OpenSSL extensions should be used.

$mode could be:

  • ecb

  • cbc

  • ctr

  • cfb

  • ofb

  • 3cbc

  • cbc3 (same as cbc)

Parameters
$mode : string
Tags
see
DES::__construct()
see
SymmetricKey::__construct()
access

public

decrypt()

Decrypts a message.

public decrypt(string $ciphertext) : string
Parameters
$ciphertext : string
Tags
see
SymmetricKey::decrypt()
access

public

Return values
string

$plaintext

disableContinuousBuffer()

Treat consecutive packets as if they are a discontinuous buffer.

public disableContinuousBuffer() : mixed

The default behavior.

Tags
see
SymmetricKey::disableContinuousBuffer()
see
self::enableContinuousBuffer()
access

public

disablePadding()

Do not pad packets.

public disablePadding() : mixed
Tags
see
self::enablePadding()
access

public

enableContinuousBuffer()

Treat consecutive "packets" as if they are a continuous buffer.

public enableContinuousBuffer() : mixed

Say you have a 16-byte plaintext $plaintext. Using the default behavior, the two following code snippets will yield different outputs:

echo $des->encrypt(substr($plaintext, 0, 8)); echo $des->encrypt(substr($plaintext, 8, 8)); echo $des->encrypt($plaintext);

The solution is to enable the continuous buffer. Although this will resolve the above discrepancy, it creates another, as demonstrated with the following:

$des->encrypt(substr($plaintext, 0, 8)); echo $des->decrypt($des->encrypt(substr($plaintext, 8, 8))); echo $des->decrypt($des->encrypt(substr($plaintext, 8, 8)));

With the continuous buffer disabled, these would yield the same output. With it enabled, they yield different outputs. The reason is due to the fact that the initialization vector's change after every encryption / decryption round when the continuous buffer is enabled. When it's disabled, they remain constant.

Put another way, when the continuous buffer is enabled, the state of the \phpseclib3\Crypt\DES() object changes after each encryption / decryption round, whereas otherwise, it'd remain constant. For this reason, it's recommended that continuous buffers not be used. They do offer better security and are, in fact, sometimes required (SSH uses them), however, they are also less intuitive and more likely to cause you problems.

Tags
see
SymmetricKey::enableContinuousBuffer()
see
self::disableContinuousBuffer()
access

public

enablePadding()

Pad "packets".

public enablePadding() : mixed

Block ciphers working by encrypting between their specified [$this->]block_size at a time If you ever need to encrypt or decrypt something that isn't of the proper length, it becomes necessary to pad the input so that it is of the proper length.

Padding is enabled by default. Sometimes, however, it is undesirable to pad strings. Such is the case in SSH, where "packets" are padded with random bytes before being encrypted. Unpad these packets and you risk stripping away characters that shouldn't be stripped away. (SSH knows how many bytes are added because the length is transmitted separately)

Tags
see
self::disablePadding()
access

public

enablePoly1305()

Enables Poly1305 mode.

public enablePoly1305() : mixed

Once enabled Poly1305 cannot be disabled.

Tags
access

public

throws
BadMethodCallException

if Poly1305 is enabled whilst in GCM mode

encrypt()

Encrypts a message.

public encrypt(string $plaintext) : string
Parameters
$plaintext : string
Tags
see
SymmetricKey::encrypt()
access

public

Return values
string

$cipertext

getBlockLength()

Returns the current block length in bits

public getBlockLength() : int
Tags
access

public

Return values
int

getBlockLengthInBytes()

Returns the current block length in bytes

public getBlockLengthInBytes() : int
Tags
access

public

Return values
int

getEngine()

Returns the engine currently being utilized

public getEngine() : mixed
Tags
see
self::setEngine()
access

public

getKeyLength()

Returns the current key length in bits

public getKeyLength() : int
Tags
access

public

Return values
int

getTag()

Get the authentication tag

public getTag([int $length = 16 ]) : string

Only used in GCM or Poly1305 mode

Parameters
$length : int = 16

optional

Tags
see
self::encrypt()
access

public

throws
LengthException

if $length isn't of a sufficient length

throws
RuntimeException

if GCM mode isn't being used

Return values
string

isValidEngine()

Test for engine validity

public isValidEngine(string $engine) : bool
Parameters
$engine : string
Tags
see
self::__construct()
access

public

Return values
bool

setAAD()

Sets additional authenticated data

public setAAD(string $aad) : mixed

setAAD() is only used by gcm or in poly1305 mode

Parameters
$aad : string
Tags
access

public

throws
BadMethodCallException

if mode isn't GCM or if poly1305 isn't being utilized

setIV()

Sets the initialization vector.

public setIV(string $iv) : mixed

SetIV is not required when \phpseclib3\Crypt\Common\SymmetricKey::MODE_ECB is being used.

Parameters
$iv : string
Tags
see
SymmetricKey::setIV()
access

public

setKey()

Sets the key.

public setKey(string $key) : mixed

Triple DES can use 128-bit (eg. strlen($key) == 16) or 192-bit (eg. strlen($key) == 24) keys.

DES also requires that every eighth bit be a parity bit, however, we'll ignore that.

Parameters
$key : string
Tags
access

public

see
DES::setKey()
see
SymmetricKey::setKey()
throws
LengthException

if the key length is invalid

setKeyLength()

Sets the key length.

public setKeyLength(int $length) : mixed

Valid key lengths are 128 and 192 bits.

If you want to use a 64-bit key use DES.php

Parameters
$length : int
Tags
see

\phpseclib3\Crypt\Common\SymmetricKey:setKeyLength()

access

public

throws
LengthException

if the key length is invalid

setNonce()

Sets the nonce.

public setNonce(string $nonce) : mixed

setNonce() is only required when gcm is used

Parameters
$nonce : string
Tags
access

public

throws
BadMethodCallException

if an nonce is provided when one shouldn't be

setPassword()

Sets the password.

public setPassword(string $password[, string $method = 'pbkdf2' ], array<string|int, string> ...$func_args) : bool

Depending on what $method is set to, setPassword()'s (optional) parameters are as follows: pbkdf2 or pbkdf1: $hash, $salt, $count, $dkLen

    Where $hash (default = sha1) currently supports the following hashes: see: Crypt/Hash.php
Parameters
$password : string
$method : string = 'pbkdf2'
$func_args : array<string|int, string>
Tags
see

Crypt/Hash.php

throws
LengthException

if pbkdf1 is being used and the derived key length exceeds the hash length

access

public

Return values
bool

setPoly1305Key()

Enables Poly1305 mode.

public setPoly1305Key([string $key = null ]) : mixed

Once enabled Poly1305 cannot be disabled. If $key is not passed then an attempt to call createPoly1305Key will be made.

Parameters
$key : string = null

optional

Tags
access

public

throws
LengthException

if the key isn't long enough

throws
BadMethodCallException

if Poly1305 is enabled whilst in GCM mode

setTag()

Sets the authentication tag

public setTag(string $tag) : mixed

Only used in GCM mode

Parameters
$tag : string
Tags
see
self::decrypt()
access

public

throws
LengthException

if $length isn't of a sufficient length

throws
RuntimeException

if GCM mode isn't being used

usesIV()

Returns whether or not the algorithm uses an IV

public usesIV() : bool
Tags
access

public

Return values
bool

usesNonce()

Returns whether or not the algorithm uses a nonce

public usesNonce() : bool
Tags
access

public

Return values
bool

createInlineCryptFunction()

Creates the performance-optimized function for en/decrypt()

protected createInlineCryptFunction(array<string|int, mixed> $cipher_code) : string

Internally for phpseclib developers:

_createInlineCryptFunction():

  • merge the $cipher_code [setup'ed by _setupInlineCrypt()] with the current [$this->]mode of operation code

  • create the $inline function, which called by encrypt() / decrypt() as its replacement to speed up the en/decryption operations.

  • return the name of the created $inline callback function

  • used to speed up en/decryption

The main reason why can speed up things [up to 50%] this way are:

  • using variables more effective then regular. (ie no use of expensive arrays but integers $k_0, $k_1 ... or even, for example, the pure $key[] values hardcoded)

  • avoiding 1000's of function calls of ie _encryptBlock() but inlining the crypt operations. in the mode of operation for() loop.

  • full loop unroll the (sometimes key-dependent) rounds avoiding this way ++$i counters and runtime-if's etc...

The basic code architectur of the generated $inline en/decrypt() lambda function, in pseudo php, is:

+----------------------------------------------------------------------------------------------+ | callback $inline = create_function: | | lambda_function_0001_crypt_ECB($action, $text) | | { | | INSERT PHP CODE OF: | | $cipher_code['init_crypt']; // general init code. | | // ie: $sbox'es declarations used for | | // encrypt and decrypt'ing. | | | | switch ($action) { | | case 'encrypt': | | INSERT PHP CODE OF: | | $cipher_code['init_encrypt']; // encrypt sepcific init code. | | ie: specified $key or $box | | declarations for encrypt'ing. | | | | foreach ($ciphertext) { | | $in = $block_size of $ciphertext; | | | | INSERT PHP CODE OF: | | $cipher_code['encrypt_block']; // encrypt's (string) $in, which is always: | | // strlen($in) == $this->block_size | | // here comes the cipher algorithm in action | | // for encryption. | | // $cipher_code['encrypt_block'] has to | | // encrypt the content of the $in variable | | | | $plaintext .= $in; | | } | | return $plaintext; | | | | case 'decrypt': | | INSERT PHP CODE OF: | | $cipher_code['init_decrypt']; // decrypt sepcific init code | | ie: specified $key or $box | | declarations for decrypt'ing. | | foreach ($plaintext) { | | $in = $block_size of $plaintext; | | | | INSERT PHP CODE OF: | | $cipher_code['decrypt_block']; // decrypt's (string) $in, which is always | | // strlen($in) == $this->block_size | | // here comes the cipher algorithm in action | | // for decryption. | | // $cipher_code['decrypt_block'] has to | | // decrypt the content of the $in variable | | $ciphertext .= $in; | | } | | return $ciphertext; | | } | | } | +----------------------------------------------------------------------------------------------+

See also the \phpseclib3\Crypt*::_setupInlineCrypt()'s for productive inline $cipher_code's how they works.

Structure of: $cipher_code = [ 'init_crypt' => (string) '', // optional 'init_encrypt' => (string) '', // optional 'init_decrypt' => (string) '', // optional 'encrypt_block' => (string) '', // required 'decrypt_block' => (string) '' // required ];

Parameters
$cipher_code : array<string|int, mixed>
Tags
see
self::setupInlineCrypt()
see
self::encrypt()
see
self::decrypt()
access

private

Return values
string

(the name of the created callback function)

getIV()

Get the IV

protected getIV(string $iv) : string

mcrypt requires an IV even if ECB is used

Parameters
$iv : string
Tags
see
self::encrypt()
see
self::decrypt()
access

private

Return values
string

isValidEngineHelper()

Test for engine validity

protected isValidEngineHelper(int $engine) : bool

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

Parameters
$engine : int
Tags
see
SymmetricKey::__construct()
access

protected

Return values
bool

nullPad128()

NULL pads a string to be a multiple of 128

protected static nullPad128(string $str) : string
Parameters
$str : string
Tags
see
self::decrypt()
see
self::encrypt()
see
self::setupGCM()
access

private

Return values
string

openssl_translate_mode()

phpseclib <-> OpenSSL Mode Mapper

protected openssl_translate_mode() : string

May need to be overwritten by classes extending this one in some cases

Tags
access

private

Return values
string

pad()

Pads a string

protected pad(string $text) : string

Pads a string using the RSA PKCS padding standards so that its length is a multiple of the blocksize. $this->block_size - (strlen($text) % $this->block_size) bytes are added, each of which is equal to chr($this->block_size - (strlen($text) % $this->block_size)

If padding is disabled and $text is not a multiple of the blocksize, the string will be padded regardless and padding will, hence forth, be enabled.

Parameters
$text : string
Tags
see
self::unpad()
throws
LengthException

if padding is disabled and the plaintext's length is not a multiple of the block size

access

private

Return values
string

poly1305()

Calculates Poly1305 MAC

protected poly1305(string $text) : string

On my system ChaCha20, with libsodium, takes 0.5s. With this custom Poly1305 implementation it takes 1.2s.

Parameters
$text : string
Tags
see
self::decrypt()
see
self::encrypt()
access

private

Return values
string

safe_intval()

Convert float to int

protected static safe_intval(string $x) : int

On ARM CPUs converting floats to ints doesn't always work

Parameters
$x : string
Tags
access

private

Return values
int

safe_intval_inline()

eval()'able string for in-line float to int

protected static safe_intval_inline() : string
Tags
access

private

Return values
string

setEngine()

Sets the engine as appropriate

protected setEngine() : mixed
Tags
see
self::__construct()
access

private

setup()

Setup the self::ENGINE_INTERNAL $engine

protected setup() : mixed

(re)init, if necessary, the internal cipher $engine and flush all $buffers Used (only) if $engine == self::ENGINE_INTERNAL

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

  • setKey()

  • setIV()

  • disableContinuousBuffer()

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

Tags
see
self::setKey()
see
self::setIV()
see
self::disableContinuousBuffer()
access

private

setupInlineCrypt()

Setup the performance-optimized function for de/encrypt()

protected setupInlineCrypt() : mixed
Tags
see
SymmetricKey::setupInlineCrypt()
access

private

unpad()

Unpads a string.

protected unpad(string $text) : string

If padding is enabled and the reported padding length is invalid the encryption key will be assumed to be wrong and false will be returned.

Parameters
$text : string
Tags
see
self::pad()
throws
LengthException

if the ciphertext's length is not a multiple of the block size

access

private

Return values
string

ghash()

Performs GHASH operation

private ghash(string $x) : string

See https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf#page=20 for more info

Parameters
$x : string
Tags
see
self::decrypt()
see
self::encrypt()
access

private

Return values
string

len64()

Returns the bit length of a string in a packed format

private static len64(string $str) : string
Parameters
$str : string
Tags
see
self::decrypt()
see
self::encrypt()
see
self::setupGCM()
access

private

Return values
string

openssl_ctr_process()

OpenSSL CTR Processor

private openssl_ctr_process(string $plaintext, string &$encryptIV, array<string|int, mixed> &$buffer) : string

PHP's OpenSSL bindings do not operate in continuous mode so we'll wrap around it. Since the keystream for CTR is the same for both encrypting and decrypting this function is re-used by both SymmetricKey::encrypt() and SymmetricKey::decrypt(). Also, OpenSSL doesn't implement CTR for all of it's symmetric ciphers so this function will emulate CTR with ECB when necessary.

Parameters
$plaintext : string
$encryptIV : string
$buffer : array<string|int, mixed>
Tags
see
self::encrypt()
see
self::decrypt()
access

private

Return values
string

openssl_ofb_process()

OpenSSL OFB Processor

private openssl_ofb_process(string $plaintext, string &$encryptIV, array<string|int, mixed> &$buffer) : string

PHP's OpenSSL bindings do not operate in continuous mode so we'll wrap around it. Since the keystream for OFB is the same for both encrypting and decrypting this function is re-used by both SymmetricKey::encrypt() and SymmetricKey::decrypt().

Parameters
$plaintext : string
$encryptIV : string
$buffer : array<string|int, mixed>
Tags
see
self::encrypt()
see
self::decrypt()
access

private

Return values
string

pkcs12helper()

PKCS#12 KDF Helper Function

private static pkcs12helper(int $n, Hash $hashObj, string $i, string $d, int $count) : string

As discussed here:

Parameters
$n : int
$hashObj : Hash
$i : string
$d : string
$count : int
Tags
see
self::setPassword()
access

private

Return values
string

$a

processBlock()

Encrypts or decrypts a 64-bit block

private processBlock(string $block, int $mode) : string

$mode should be either self::ENCRYPT or self::DECRYPT. See Feistel.png to get a general idea of what this function does.

Parameters
$block : string
$mode : int
Tags
see
self::encryptBlock()
see
self::decryptBlock()
access

private

Return values
string

setupGCM()

Sets up GCM parameters

private setupGCM() : mixed

See steps 1-2 of https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf#page=23 for more info

Tags
access

private


        
On this page

Search results