PHP Class ParagonIE\Halite\Util

Various useful utilities, used within Halite and available for general use This library makes heavy use of return-type declarations, which are a PHP 7 only feature. Read more about them here:
Datei anzeigen Open project: paragonie/halite Class Usage Examples

Public Methods

Method Description
hash ( string $input, integer $length = Sodium\CRYPTO_GENERICHASH_BYTES ) : string Wrapper around \Sodium\crypto_generichash()
hkdfBlake2b ( string $ikm, integer $length, string $info = '', string $salt = '' ) : string Use a derivative of HKDF to derive multiple keys from one.
keyed_hash ( string $input, string $key, integer $length = Sodium\CRYPTO_GENERICHASH_BYTES ) : string Wrapper around \Sodium\crypto_generichash()
raw_hash ( string $input, integer $length = Sodium\CRYPTO_GENERICHASH_BYTES ) : string Wrapper around \Sodium\crypto_generichash()
raw_keyed_hash ( string $input, string $key, integer $length = Sodium\CRYPTO_GENERICHASH_BYTES ) : string Wrapper around \Sodium\crypto_generichash()
safeStrcpy ( string $string ) : string PHP 7 uses interned strings. We don't want altering this one to alter the original string.
safeStrlen ( string $str ) : integer Safe string length
safeSubstr ( string $str, integer $start, integer $length = null ) : string Safe substring
xorStrings ( string $left, string $right ) : string Calculate A xor B, given two binary strings of the same length.

Private Methods

Method Description
__construct ( ) Don't allow this to be instantiated.

Method Details

hash() public static method

Returns hexadecimal characters.
public static hash ( string $input, integer $length = Sodium\CRYPTO_GENERICHASH_BYTES ) : string
$input string
$length integer
return string

hkdfBlake2b() public static method

http://tools.ietf.org/html/rfc5869 This is a variant from hash_hkdf() and instead uses BLAKE2b provided by libsodium. Important: instead of a true HKDF (from HMAC) construct, this uses the \Sodium\crypto_generichash() key parameter. This is *probably* okay.
public static hkdfBlake2b ( string $ikm, integer $length, string $info = '', string $salt = '' ) : string
$ikm string Initial Keying Material
$length integer How many bytes?
$info string What sort of key are we deriving?
$salt string
return string

keyed_hash() public static method

Expects a key (binary string). Returns hexadecimal characters.
public static keyed_hash ( string $input, string $key, integer $length = Sodium\CRYPTO_GENERICHASH_BYTES ) : string
$input string
$key string
$length integer
return string

raw_hash() public static method

Returns raw binary.
public static raw_hash ( string $input, integer $length = Sodium\CRYPTO_GENERICHASH_BYTES ) : string
$input string
$length integer
return string

raw_keyed_hash() public static method

Expects a key (binary string). Returns raw binary.
public static raw_keyed_hash ( string $input, string $key, integer $length = Sodium\CRYPTO_GENERICHASH_BYTES ) : string
$input string
$key string
$length integer
return string

safeStrcpy() public static method

PHP 7 uses interned strings. We don't want altering this one to alter the original string.
public static safeStrcpy ( string $string ) : string
$string string
return string

safeStrlen() public static method

Safe string length
public static safeStrlen ( string $str ) : integer
$str string
return integer

safeSubstr() public static method

Safe substring
public static safeSubstr ( string $str, integer $start, integer $length = null ) : string
$str string
$start integer
$length integer
return string

xorStrings() public static method

Uses pack() and unpack() to avoid cache-timing leaks caused by chr().
public static xorStrings ( string $left, string $right ) : string
$left string
$right string
return string