note 108978 added to function.hash-hmac
| From: | martin dot papik at ipsec dot info | Date: | Sat, 09 Jun 2012 07:39:01 +0000 |
| Subject: | note 108978 added to function.hash-hmac | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-188508@lists.php.net to get a copy of this message | ||
Yet another OATH HOTP function. Has a 64 bit counter and is a lot shorter. Enjoy.
<?php
function oath_hotp ($secret, $ctr, $len=6) {
$binctr = pack ('NNC*', $ctr>>32, $ctr & 0xFFFFFFFF);
$hash = hash_hmac ("sha1", $binctr, $secret);
// This is where hashing stops and truncation begins
$ofs = 2*hexdec (substr ($hash, 39, 1));
$int = hexdec (substr ($hash, $ofs, 8)) & 0x7FFFFFFF;
$pin = substr ($int, -$len);
$pin = str_pad ($pin, $len, "0", STR_PAD_LEFT);
return $pin;
}
?>
----
Server IP: 113.20.13.217
Probable Submitter: 66.135.40.242
----
Manual Page -- http://www.php.net/manual/en/function.hash-hmac.php
Edit -- https://master.php.net/note/edit/108978
Del: integrated -- https://master.php.net/note/delete/108978/integrated
Del: useless -- https://master.php.net/note/delete/108978/useless
Del: bad code -- https://master.php.net/note/delete/108978/bad+code
Del: spam -- https://master.php.net/note/delete/108978/spam
Del: non-english -- https://master.php.net/note/delete/108978/non-english
Del: in docs -- https://master.php.net/note/delete/108978/in+docs
Del: other reasons-- https://master.php.net/note/delete/108978
Reject -- https://master.php.net/note/reject/108978
Search -- https://master.php.net/manage/user-notes.php