$block_size) return false; if (substr($str, (-1 * $padding_size)) !== str_repeat(chr($padding_size), $padding_size)) return false; return substr($str, 0, strlen($str) - $padding_size); } /** * @brief HKDF function compatible with defuse/php-encryption * @return string */ protected static function _defuseCompatibleHKDF($key, $info) { $salt = str_repeat("\x00", self::ENCRYPTION_MAC_SIZE); $prk = hash_hmac(self::ENCRYPTION_MAC_ALGO, $key, $salt, true); $t = $last_block = ''; for ($block_index = 1; strlen($t) < self::ENCRYPTION_KEY_SIZE; $block_index++) { $t .= $last_block = hash_hmac(self::ENCRYPTION_MAC_ALGO, ($last_block . $info . chr($block_index)), $prk, true); } return substr($t, 0, self::ENCRYPTION_KEY_SIZE); } }