34 'algo' => $this->config[
'algo'],
35 'rounds' => $this->config[
'cost'],
36 'length' => $this->config[
'length']
45 return isset( $this->config[
'use-hash-extension'] ) ?
46 $this->config[
'use-hash-extension'] : function_exists(
'hash_pbkdf2' );
49 public function crypt( $password ) {
56 $this->params[
'algo'],
58 base64_decode( $this->
args[0] ),
59 (
int)$this->params[
'rounds'],
60 (
int)$this->params[
'length'],
63 if ( !is_string(
$hash ) ) {
67 $hashLenHash = hash( $this->params[
'algo'],
'',
true );
68 if ( !is_string( $hashLenHash ) ) {
71 $hashLen = strlen( $hashLenHash );
72 $blockCount = ceil( $this->params[
'length'] / $hashLen );
75 $salt = base64_decode( $this->
args[0] );
76 for ( $i = 1; $i <= $blockCount; ++$i ) {
77 $roundTotal = $lastRound = hash_hmac(
78 $this->params[
'algo'],
79 $salt . pack(
'N', $i ),
84 for ( $j = 1; $j < $this->params[
'rounds']; ++$j ) {
85 $lastRound = hash_hmac( $this->params[
'algo'], $lastRound, $password,
true );
86 $roundTotal ^= $lastRound;
92 $hash = substr(
$hash, 0, $this->params[
'length'] );
95 $this->hash = base64_encode(
$hash );