CI_Encryption::hkdf PHP Method

hkdf() public method

HKDF
public hkdf ( $key, $digest = 'sha512', $salt = NULL, $length = NULL, $info = '' ) : string
$key Input key
$digest A SHA-2 hashing algorithm
$salt Optional salt
$length Output length (defaults to the selected digest size)
$info Optional context/application-specific info
return string A pseudo-random key
    public function hkdf($key, $digest = 'sha512', $salt = NULL, $length = NULL, $info = '')
    {
        if (!isset($this->_digests[$digest])) {
            return FALSE;
        }
        if (empty($length) or !is_int($length)) {
            $length = $this->_digests[$digest];
        } elseif ($length > 255 * $this->_digests[$digest]) {
            return FALSE;
        }
        self::strlen($salt) or $salt = str_repeat("", $this->_digests[$digest]);
        $prk = hash_hmac($digest, $key, $salt, TRUE);
        $key = '';
        for ($key_block = '', $block_index = 1; self::strlen($key) < $length; $block_index++) {
            $key_block = hash_hmac($digest, $key_block . $info . chr($block_index), $prk, TRUE);
            $key .= $key_block;
        }
        return self::substr($key, 0, $length);
    }