You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
878 B

<?php declare(strict_types=1);
namespace BradyMcD\TAATP\Hash;
use BradyMcD\TAATP\HashInterface;
use ParagonIE\ConstantTime\Base32;
/** @SuppressWarnings(PHPMD.CamelCaseClassName)*/
class HMAC_SHA1 implements HashInterface
{
const DEFAULT_SECRET_SIZE = 32;
/** @SuppressWarnings(PHPMD.StaticAccess) */
public function hash(string $key, string $val): string
{
$key = Base32::decode($key);
return \hash_hmac("sha1", \hex2bin($val), $key, true);
}
public function hashNumeric(string $key, int $val): string
{
return $this->hash($key, \dechex($val));
}
public static function hashType(): string
{
return "SHA1";
}
/** @SuppressWarnings(PHPMD.StaticAccess) */
public static function keygen(): string
{
return Base32::encodeUpper(random_bytes(this::DEFAULT_SECRET_SIZE));
}
}
?>