Moodle PHP Documentation 4.3
Moodle 4.3.5 (Build: 20240610) (7dcfaa79f78)
Crypt_Blowfish

Functions

 __construct ($cipher)
 Constructor.
 
 __construct ($key, array $opts=array())
 Constructor.
 
 __construct ($pass, $key_length, array $opts=array())
 Constructor.
 
 __get ($name)
 
 __toString ()
 
 _binxor ($l, $r)
 Workaround for XOR on certain systems.
 
 _decipher (&$Xl, &$Xr)
 Deciphers a single 64-bit block.
 
 _encipher (&$Xl, &$Xr)
 Enciphers a single 64-bit block.
 
 _pad ($text, $ignore=false)
 Pad text to match blocksize length.
 
 _unpad ($text)
 Unpad text from blocksize boundary.
 
 decrypt ($text)
 Decrypts a string.
 
 decrypt ($text, $iv)
 
 encrypt ($text)
 Encrypts a string.
 
 encrypt ($text, $iv)
 
 setIv ($iv=null)
 Sets the initialization vector (required for CBC mode).
 
 setKey ($key, $iv=null)
 Sets the secret key.
 
static supported ()
 Is this driver supported on this system?
 

Variables

Horde_Crypt_Blowfish_Base $_crypt
 Blowfish crypt driver.
 
string $_key
 The derived key.
 
array $_P
 P-Array contains 18 32-bit subkeys.
 
array $_S
 Array of four S-Blocks each containing 256 32-bit entries.
 
return in_array('bf-ecb', $ciphers) &&in_array('bf-cbc' $ciphers
 
integer $iterations
 Number of iterations to use.
 
string $iv = null
 Initialization vector.
 
string $key
 Encryption key.
 
string $salt
 Salt.
 
const BLOCKSIZE = 8
 
return false
 
**See the enclosed file LICENSE for license information(LGPL). If you *did not receive this file see http
 
*See the enclosed file LICENSE for license information(LGPL). If you *did not receive this file see http
 
*See the enclosed file LICENSE for license information(LGPL). If you *did not receive this file see http
 
*See the enclosed file LICENSE for license information(LGPL). If you *did not receive this file see http
 
**See the enclosed file LICENSE for license information(LGPL). If you *did not receive this file see http
 
const IGNORE_MCRYPT = 2
 
const IV_LENGTH = 8
 
const MAXKEYSIZE = 56
 

Detailed Description

Function Documentation

◆ __construct() [1/3]

__construct ( $key)

Constructor.

Parameters
string$cipherEither 'ecb' or 'cbc'.
string$keyEncrpytion key.

◆ __construct() [2/3]

__construct ( $key,
array $opts = array() )

Constructor.

Parameters
string$keyEncryption key.
array$optsAdditional options:
  • cipher: (string) Either 'ecb' or 'cbc'.
  • ignore: (integer) A mask of drivers to ignore (IGNORE_* constants).
  • iv: (string) IV to use.

◆ __construct() [3/3]

__construct ( $pass,
$key_length,
array $opts = array() )

Constructor.

Parameters
string$passThe password.
string$key_lengthLength of the derived key (in bytes).
array$optsAdditional options:
  • algo: (string) Hash algorithm.
  • i_count: (integer) Iteration count.
  • salt: (string) The salt to use.

◆ _binxor()

_binxor ( $l,
$r )
protected

Workaround for XOR on certain systems.

Parameters
integer | float$l
integer | float$r
Return values
float

◆ _decipher()

_decipher ( & $Xl,
& $Xr )
protected

Deciphers a single 64-bit block.

Parameters
int&$Xl
int&$Xr

◆ _encipher()

_encipher ( & $Xl,
& $Xr )
protected

Enciphers a single 64-bit block.

Parameters
int&$Xl
int&$Xr

◆ _pad()

_pad ( $text,
$ignore = false )
protected

Pad text to match blocksize length.

Parameters
string$textUnpadded text.
boolean$ignoreDon't pad if already at blocksize length.
Return values
stringPadded text.

◆ _unpad()

_unpad ( $text)
protected

Unpad text from blocksize boundary.

Parameters
string$textPadded text.
Return values
stringUnpadded text.

◆ decrypt()

decrypt ( $text)
abstract

Decrypts a string.

Parameters
string$textThe string to decrypt.
Return values
stringThe plaintext.
Exceptions
Horde_Crypt_Blowfish_Exception
Parameters
string$textThe string to encrypt.
Return values
stringThe ciphertext.
Exceptions
Horde_Crypt_Blowfish_Exception

◆ encrypt()

encrypt ( $text)
abstract

Encrypts a string.

Parameters
string$textThe string to encrypt.
Return values
stringThe ciphertext.
Exceptions
Horde_Crypt_Blowfish_Exception

◆ setIv()

setIv ( $iv = null)

Sets the initialization vector (required for CBC mode).

Parameters
string$ivInitialization vector.

◆ setKey()

setKey ( $key,
$iv = null )

Sets the secret key.

The key must be non-zero, and less than or equal to MAXKEYSIZE characters (bytes) in length.

Parameters
string$keyKey must be non-empty and less than MAXKEYSIZE bytes in length.
string$ivThe initialization vector to use. Only needed for 'cbc' cipher. If null, an IV is automatically generated.
Exceptions
Horde_Crypt_Blowfish_Exception

◆ supported()

static supported ( )
static

Is this driver supported on this system?

Return values
booleanTrue if supported.

Variable Documentation

◆ $_P

array $_P
protected
Initial value:
= array(
0x243F6A88, 0x85A308D3, 0x13198A2E, 0x03707344,
0xA4093822, 0x299F31D0, 0x082EFA98, 0xEC4E6C89,
0x452821E6, 0x38D01377, 0xBE5466CF, 0x34E90C6C,
0xC0AC29B7, 0xC97C50DD, 0x3F84D5B5, 0xB5470917,
0x9216D5D9, 0x8979FB1B
)

P-Array contains 18 32-bit subkeys.