<?php
function hash_tiger_rev($algo, $data, $raw_output = false) {
$len = intval(substr($algo, 5, 3)); $times = substr($algo, 9, 1); $revhash = implode("", array_map("strrev",
str_split(hash('tiger192,'.$times, $data, true), 8)));
if ($len < 192) $revhash = substr($revhash, 0, $len >> 3);
return $raw_output? $revhash: bin2hex($revhash);
}
function hash_hmac_tiger_rev($algo, $data, $key, $raw_output = false) {
if (strlen($key) > 64) $key = hash_tiger_rev($algo, $key);
$key = str_pad($key, 64, chr(0));
$o_pad = str_repeat("\\", 64) ^ $key; $i_pad = str_repeat("6", 64) ^ $key; return hash_tiger_rev($algo, $o_pad .
hash_tiger_rev($algo, $i_pad . $data, true), $raw_output);
}
function hash_hmac_new($algo, $data, $key, $raw_output = false) {
if (phpversion() > '5.4' || !preg_match('/^tiger(128|160|192),(3|4)$/', $algo))
return hash_hmac($algo, $data, $key, $raw_output);
else
return hash_hmac_tiger_rev($algo, $data, $key, $raw_output);
}
function hash_hmac_old($algo, $data, $key, $raw_output = false) {
if (phpversion() < '5.4' || !preg_match('/^tiger(128|160|192),(3|4)$/', $algo))
return hash_hmac($algo, $data, $key, $raw_output);
else
return hash_hmac_tiger_rev($algo, $data, $key, $raw_output);
}
$algo = 'tiger160,4'; $pwd = 'foo'; $key = 'bar';
echo hash_hmac($algo, $pwd, $key), "<br>";
echo hash_hmac_tiger_rev($algo, $pwd, $key), "<br>";
echo "<br>";
echo hash_hmac_old($algo, $pwd, $key), "<br>";
echo hash_hmac_new($algo, $pwd, $key), "<br>";
?>