49 public function crypt( $password ) {
50 if ( count( $this->args ) == 0 ) {
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 );