44 public function crypt( $password ) {
45 if ( count( $this->args ) == 0 ) {
49 if ( function_exists(
'hash_pbkdf2' ) ) {
51 $this->params[
'algo'],
53 base64_decode( $this->args[0] ),
54 (
int)$this->params[
'rounds'],
55 (
int)$this->params[
'length'],
58 if ( !is_string(
$hash ) ) {
62 $hashLenHash = hash( $this->params[
'algo'],
'',
true );
63 if ( !is_string( $hashLenHash ) ) {
66 $hashLen = strlen( $hashLenHash );
67 $blockCount = ceil( $this->params[
'length'] / $hashLen );
70 $salt = base64_decode( $this->args[0] );
71 for ( $i = 1; $i <= $blockCount; ++$i ) {
72 $roundTotal = $lastRound = hash_hmac(
73 $this->params[
'algo'],
74 $salt . pack(
'N', $i ),
79 for ( $j = 1; $j < $this->params[
'rounds']; ++$j ) {
80 $lastRound = hash_hmac( $this->params[
'algo'], $lastRound, $password,
true );
81 $roundTotal ^= $lastRound;
87 $hash = substr(
$hash, 0, $this->params[
'length'] );
90 $this->hash = base64_encode(
$hash );