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

author Jim Wigginton
version 0.1.0
access public
package Crypt_Hash

 Methods

Default Constructor.

Crypt_Hash(\optional $hash) : \Crypt_Hash

access public

Parameters

$hash

\optional

String $hash

Returns

Add

_add() : String

_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. Math_BigInteger() could be used but this should be faster.

see \global\_sha256()
access private

Returns

String

Pure-PHP implementation of MD2

_md2($m) 

See RFC1319.

access private

Parameters

$m

Wrapper for MD5

_md5($m) 

access private

Parameters

$m

Not

_not(Integer $int) : Integer

access private
see \global\_sha256()

Parameters

$int

Integer

Returns

Integer

Right Rotate

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

access private
see \global\_sha256()

Parameters

$int

Integer

$amt

Integer

Returns

Integer

Right Shift

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

access private
see \global\_sha256()

Parameters

$int

Integer

$amt

Integer

Returns

Integer

Wrapper for SHA1

_sha1($m) 

access private

Parameters

$m

Pure-PHP implementation of SHA256

_sha256($m) 

See SHA-256 (a SHA-2 variant) pseudocode - Wikipedia.

access private

Parameters

$m

Pure-PHP implementation of SHA384 and SHA512

_sha512($m) 

access private

Parameters

$m

String Shift

_string_shift(String $string, \optional $index) : String

Inspired by array_shift

access private

Parameters

$string

String

$index

\optional

Integer $index

Returns

String

Returns the hash length (in bytes)

getLength() : Integer

access public

Returns

Integer

Compute the HMAC.

hash(String $text) : String

access public

Parameters

$text

String

Returns

String

Sets the hash function.

setHash(String $hash) 

access public

Parameters

$hash

String

Sets the key for HMACs

setKey(String $key) 

Keys can be of any length.

access public

Parameters

$key

String

 Properties

 

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

$b : Integer

see \global\Crypt_Hash::setAlgorithm()
access private
 

Hash Algorithm

$hash : String

see \global\Crypt_Hash::setHash()
access private
 

Inner XOR (Internal HMAC)

$ipad : String

see \global\Crypt_Hash::setKey()
access private
 

Key

$key : String

see \global\Crypt_Hash::setKey()
access private
 

Byte-length of hash output (Internal HMAC)

$l : Integer

see \global\Crypt_Hash::setHash()
access private
 

Outer XOR (Internal HMAC)

$opad : String

see \global\Crypt_Hash::setKey()
access private