Subversion Repositories php_utils

Compare Revisions

Regard whitespace Rev 66 → Rev 67

/trunk/vts_crypt.inc.php
143,8 → 143,7
if ($ver == '1') {
if ($mode == 'sp') {
$payload = $str_salt.$str_password;
$algo_supported_natively = in_array($algo, hash_algos());
if (!$algo_supported_natively && str_starts_with($algo, 'sha3-') && method_exists('\bb\Sha3\Sha3', 'hash')) {
if (!hash_supported_natively($algo) && str_starts_with($algo, 'sha3-') && method_exists('\bb\Sha3\Sha3', 'hash')) {
$bits = explode('-',$algo)[1];
$bin_hash = \bb\Sha3\Sha3::hash($payload, $bits, true);
} else {
152,8 → 151,7
}
} else if ($mode == 'ps') {
$payload = $str_password.$str_salt;
$algo_supported_natively = in_array($algo, hash_algos());
if (!$algo_supported_natively && str_starts_with($algo, 'sha3-') && method_exists('\bb\Sha3\Sha3', 'hash')) {
if (!hash_supported_natively($algo) && str_starts_with($algo, 'sha3-') && method_exists('\bb\Sha3\Sha3', 'hash')) {
$bits = explode('-',$algo)[1];
$bin_hash = \bb\Sha3\Sha3::hash($payload, $bits, true);
} else {
161,8 → 159,7
}
} else if ($mode == 'sps') {
$payload = $str_salt.$str_password.$str_salt;
$algo_supported_natively = in_array($algo, hash_algos());
if (!$algo_supported_natively && str_starts_with($algo, 'sha3-') && method_exists('\bb\Sha3\Sha3', 'hash')) {
if (!hash_supported_natively($algo) && str_starts_with($algo, 'sha3-') && method_exists('\bb\Sha3\Sha3', 'hash')) {
$bits = explode('-',$algo)[1];
$bin_hash = \bb\Sha3\Sha3::hash($payload, $bits, true);
} else {
169,12 → 166,7
$bin_hash = hash($algo, $payload, true);
}
} else if ($mode == 'hmac') {
if (version_compare(PHP_VERSION, '7.2.0') >= 0) {
$algo_supported_natively = in_array($algo, hash_hmac_algos());
} else {
$algo_supported_natively = in_array($algo, hash_algos());
}
if (!$algo_supported_natively && str_starts_with($algo, 'sha3-') && method_exists('\bb\Sha3\Sha3', 'hash_hmac')) {
if (!hash_hmac_supported_natively($algo) && str_starts_with($algo, 'sha3-') && method_exists('\bb\Sha3\Sha3', 'hash_hmac')) {
$bits = explode('-',$algo)[1];
$bin_hash = \bb\Sha3\Sha3::hash_hmac($str_password, $str_salt, $bits, true);
} else {
181,8 → 173,7
$bin_hash = hash_hmac($algo, $str_password, $str_salt, true);
}
} else if ($mode == 'pbkdf2') {
$algo_supported_natively = in_array($algo, hash_algos());
if (!$algo_supported_natively && str_starts_with($algo, 'sha3-') && method_exists('\bb\Sha3\Sha3', 'hash_pbkdf2')) {
if (!hash_pbkdf2_supported_natively($algo) && str_starts_with($algo, 'sha3-') && method_exists('\bb\Sha3\Sha3', 'hash_pbkdf2')) {
if ($iterations == 0) {
$iterations = 2000; // because userland implementations are much slower, we must choose a small value...
}
387,6 → 378,28
return $x;
}
 
function hash_supported_natively($algo) {
if (version_compare(PHP_VERSION, '5.1.2') >= 0) {
return in_array($algo, hash_algos());
} else {
return false;
}
}
 
function hash_hmac_supported_natively($algo): bool {
if (version_compare(PHP_VERSION, '7.2.0') >= 0) {
return in_array($algo, hash_hmac_algos());
} else if (version_compare(PHP_VERSION, '5.1.2') >= 0) {
return in_array($algo, hash_algos());
} else {
return false;
}
}
 
function hash_pbkdf2_supported_natively($algo) {
return hash_supported_natively($algo);
}
 
// --- Part 5: Selftest
 
/*