Subversion Repositories oidplus

Compare Revisions

Regard whitespace Rev 1103 → Rev 1104

/trunk/includes/functions.inc.php
217,14 → 217,6
return array($out_html, $out_js, $out_css);
}
 
function hash_supported_natively($algo) {
if (version_compare(PHP_VERSION, '5.1.2') >= 0) {
return in_array($algo, hash_algos());
} else {
return false;
}
}
 
function sha3_512($password, $raw_output=false) {
if (hash_supported_natively('sha3-512')) {
return hash('sha3-512', $password, $raw_output);
233,16 → 225,6
}
}
 
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 sha3_512_hmac($message, $key, $raw_output=false) {
// RFC 2104 HMAC
if (hash_hmac_supported_natively('sha3-512')) {
252,10 → 234,6
}
}
 
function hash_pbkdf2_supported_natively($algo) {
return hash_supported_natively($algo);
}
 
function sha3_512_pbkdf2($password, $salt, $iterations, $length=0, $binary=false) {
if (hash_pbkdf2_supported_natively('sha3-512')) {
return hash_pbkdf2('sha3-512', $password, $salt, $iterations, $length, $binary);
/trunk/vendor/danielmarschall/php_utils/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
 
/*