mirror of
https://github.com/Yubico/yubikey-ksm.git
synced 2024-12-12 03:08:54 +01:00
implementing openssl decrypt block found in https://github.com/Yubico/yubikey-ksm/issues/24
This commit is contained in:
parent
c1cb3e1dd8
commit
a31bfb9211
@ -33,7 +33,9 @@ function yubi_hex2bin($h)
|
|||||||
if (!is_string($h)) return null;
|
if (!is_string($h)) return null;
|
||||||
$r = '';
|
$r = '';
|
||||||
for ($a = 0; $a < strlen($h); $a += 2) {
|
for ($a = 0; $a < strlen($h); $a += 2) {
|
||||||
$r.=chr(hexdec($h{$a}.$h{($a+1)}));
|
$r .= chr(hexdec($h{
|
||||||
|
$a} . $h{
|
||||||
|
($a + 1)}));
|
||||||
}
|
}
|
||||||
return $r;
|
return $r;
|
||||||
}
|
}
|
||||||
@ -45,12 +47,19 @@ function modhex2hex($m)
|
|||||||
|
|
||||||
function aes128ecb_decrypt($key, $in)
|
function aes128ecb_decrypt($key, $in)
|
||||||
{
|
{
|
||||||
|
if (extension_loaded('openssl') && function_exists('openssl_decrypt') && in_array('aes-128-ecb', openssl_get_cipher_methods())) {
|
||||||
|
$result = openssl_decrypt(yubi_hex2bin($in), 'aes-128-ecb', yubi_hex2bin($key), OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING);
|
||||||
|
if ($result !== false)
|
||||||
|
$result = bin2hex($result);
|
||||||
|
else
|
||||||
|
$result = '';
|
||||||
|
} else {
|
||||||
$td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', 'ecb', '');
|
$td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', 'ecb', '');
|
||||||
$iv = yubi_hex2bin('00000000000000000000000000000000');
|
$iv = yubi_hex2bin('00000000000000000000000000000000');
|
||||||
mcrypt_generic_init($td, yubi_hex2bin($key), $iv);
|
mcrypt_generic_init($td, yubi_hex2bin($key), $iv);
|
||||||
$result = bin2hex(mdecrypt_generic($td, yubi_hex2bin($in)));
|
$result = bin2hex(mdecrypt_generic($td, yubi_hex2bin($in)));
|
||||||
mcrypt_generic_deinit($td);
|
mcrypt_generic_deinit($td);
|
||||||
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,9 +81,8 @@ function calculate_crc($token)
|
|||||||
return $crc;
|
return $crc;
|
||||||
}
|
}
|
||||||
|
|
||||||
function crc_is_good($token) {
|
function crc_is_good($token)
|
||||||
|
{
|
||||||
$crc = calculate_crc($token);
|
$crc = calculate_crc($token);
|
||||||
return $crc == 0xf0b8;
|
return $crc == 0xf0b8;
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
||||||
|
Loading…
Reference in New Issue
Block a user