Subversion Repositories php_utils

Rev

Rev 75 | Rev 90 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 75 Rev 76
Line 476... Line 476...
476
 
476
 
477
// --- Part 4: Functions which include a fallback to a pure-PHP sha3 implementation (requires https://github.com/danielmarschall/php-sha3 )
477
// --- Part 4: Functions which include a fallback to a pure-PHP sha3 implementation (requires https://github.com/danielmarschall/php-sha3 )
478
 
478
 
479
function hash_ex($algo, $data, $binary=false, $options=array()) {
479
function hash_ex($algo, $data, $binary=false, $options=array()) {
480
        if (!hash_supported_natively($algo) && str_starts_with($algo, 'sha3-') && method_exists('\bb\Sha3\Sha3', 'hash')) {
480
        if (!hash_supported_natively($algo) && str_starts_with($algo, 'sha3-') && method_exists('\bb\Sha3\Sha3', 'hash')) {
481
                $bits = explode('-',$algo)[1];
481
                $bits = (int)explode('-',$algo)[1];
482
                $hash = \bb\Sha3\Sha3::hash($data, $bits, $binary);
482
                $hash = \bb\Sha3\Sha3::hash($data, $bits, $binary);
483
        } else {
483
        } else {
484
                $hash = hash($algo, $data, $binary);
484
                $hash = hash($algo, $data, $binary);
485
        }
485
        }
486
        return $hash;
486
        return $hash;
487
}
487
}
488
 
488
 
489
function hash_hmac_ex($algo, $data, $key, $binary=false) {
489
function hash_hmac_ex($algo, $data, $key, $binary=false) {
490
        if (!hash_hmac_supported_natively($algo) && str_starts_with($algo, 'sha3-') && method_exists('\bb\Sha3\Sha3', 'hash_hmac')) {
490
        if (!hash_hmac_supported_natively($algo) && str_starts_with($algo, 'sha3-') && method_exists('\bb\Sha3\Sha3', 'hash_hmac')) {
491
                $bits = explode('-',$algo)[1];
491
                $bits = (int)explode('-',$algo)[1];
492
                $hash = \bb\Sha3\Sha3::hash_hmac($data, $key, $bits, $binary);
492
                $hash = \bb\Sha3\Sha3::hash_hmac($data, $key, $bits, $binary);
493
        } else {
493
        } else {
494
                $hash = hash_hmac($algo, $data, $key, $binary);
494
                $hash = hash_hmac($algo, $data, $key, $binary);
495
        }
495
        }
496
        return $hash;
496
        return $hash;
Line 499... Line 499...
499
function hash_pbkdf2_ex($algo, $password, $salt, &$iterations=0, $length=0, $binary=false) {
499
function hash_pbkdf2_ex($algo, $password, $salt, &$iterations=0, $length=0, $binary=false) {
500
        if (!hash_pbkdf2_supported_natively($algo) && str_starts_with($algo, 'sha3-') && method_exists('\bb\Sha3\Sha3', 'hash_pbkdf2')) {
500
        if (!hash_pbkdf2_supported_natively($algo) && str_starts_with($algo, 'sha3-') && method_exists('\bb\Sha3\Sha3', 'hash_pbkdf2')) {
501
                if ($iterations == 0/*default*/) {
501
                if ($iterations == 0/*default*/) {
502
                        $iterations = _vts_password_default_iterations($algo, true);
502
                        $iterations = _vts_password_default_iterations($algo, true);
503
                }
503
                }
504
                $bits = explode('-',$algo)[1];
504
                $bits = (int)explode('-',$algo)[1];
505
                $hash = \bb\Sha3\Sha3::hash_pbkdf2($password, $salt, $iterations, $bits, $length, $binary);
505
                $hash = \bb\Sha3\Sha3::hash_pbkdf2($password, $salt, $iterations, $bits, $length, $binary);
506
        } else {
506
        } else {
507
                if ($iterations == 0/*default*/) {
507
                if ($iterations == 0/*default*/) {
508
                        $iterations = _vts_password_default_iterations($algo, false);
508
                        $iterations = _vts_password_default_iterations($algo, false);
509
                }
509
                }