\phpseclib\CryptHash

Pure-PHP implementations of keyed-hash message authentication codes (HMACs) and various cryptographic hashing functions.

Summary

Methods
Properties
Constants
__construct()
setKey()
_computeKey()
getHash()
setHash()
hash()
getLength()
_md5()
_sha1()
_md2()
_sha256()
_sha512()
_rightRotate()
_rightShift()
_not()
_add()
_string_shift()
$hashParam
$b
$l
$hash
$key
$computedKey
$opad
$ipad
$engine
MODE_INTERNAL
MODE_MHASH
MODE_HASH
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Constants

MODE_INTERNAL

MODE_INTERNAL

Toggles the internal implementation

MODE_MHASH

MODE_MHASH

Toggles the mhash() implementation, which has been deprecated on PHP 5.3.0+.

MODE_HASH

MODE_HASH

Toggles the hash() implementation, which works on PHP 5.1.2+.

Properties

$hashParam

$hashParam : integer

Hash Parameter

Type

integer

$b

$b : integer

Byte-length of compression blocks / key (Internal HMAC)

Type

integer

$l

$l : integer

Byte-length of hash output (Internal HMAC)

Type

integer

$hash

$hash : string

Hash Algorithm

Type

string

$key

$key : string

Key

Type

string

$computedKey

$computedKey : string

Computed Key

Type

string

$opad

$opad : string

Outer XOR (Internal HMAC)

Type

string

$ipad

$ipad : string

Inner XOR (Internal HMAC)

Type

string

$engine

$engine : string

Engine

Type

string

Methods

__construct()

__construct(string  $hash = 'sha1') : \phpseclib\Crypt\Hash

Default Constructor.

Parameters

string $hash

Returns

\phpseclib\Crypt\Hash

setKey()

setKey(string  $key = false) 

Sets the key for HMACs

Keys can be of any length.

Parameters

string $key

getHash()

getHash() : string

Gets the hash function.

As set by the constructor or by the setHash() method.

Returns

string

setHash()

setHash(string  $hash) 

Sets the hash function.

Parameters

string $hash

hash()

hash(string  $text) : string

Compute the HMAC.

Parameters

string $text

Returns

string

getLength()

getLength() : integer

Returns the hash length (in bytes)

Returns

integer

_md5()

_md5(string  $m) 

Wrapper for MD5

Parameters

string $m

_sha1()

_sha1(string  $m) 

Wrapper for SHA1

Parameters

string $m

_md2()

_md2(string  $m) 

Pure-PHP implementation of MD2

See RFC1319.

Parameters

string $m

_sha512()

_sha512(string  $m) 

Pure-PHP implementation of SHA384 and SHA512

Parameters

string $m

_rightRotate()

_rightRotate(integer  $int, integer  $amt) : integer

Right Rotate

Parameters

integer $int
integer $amt

Returns

integer

_rightShift()

_rightShift(integer  $int, integer  $amt) : integer

Right Shift

Parameters

integer $int
integer $amt

Returns

integer

_not()

_not(integer  $int) : integer

Not

Parameters

integer $int

Returns

integer

_add()

_add() : integer

Add

_sha256() adds multiple unsigned 32-bit integers. Since PHP doesn't support unsigned integers and since the possibility of overflow exists, care has to be taken. BigInteger could be used but this should be faster.

Returns

integer

_string_shift()

_string_shift(string  $string, integer  $index = 1) : string

String Shift

Inspired by array_shift

Parameters

string $string
integer $index

Returns

string