3 * To change this template, choose Tools | Templates
4 * and open the template in the editor.
5 * @version Build @@version@@
8 namespace CryptLib\Key\Derivation\PBKDF
;
10 use CryptLib\Hash\Hash
;
13 * Description of pbkdf2
18 extends \CryptLib\Key\Derivation\AbstractDerivation
19 implements \CryptLib\Key\Derivation\PBKDF
22 public function derive($password, $salt, $iterations, $length) {
23 $size = Hash
::getHashSize($this->hash
);
24 if ($length > $size) {
25 throw new \
InvalidArgumentException('Length is too long for hash');
27 $tmp = hash($this->hash
, $password . $salt, true);
28 for ($i = 2; $i <= $iterations; $i++
) {
29 $tmp = hash($this->hash
, $tmp . $password . $salt, true);
31 return substr($tmp, 0, $length);
35 * Get the signature for this implementation
37 * This should include all information needed to build the same instance
40 * @return string The signature for this instance
42 public function getSignature() {
43 return 'schneier-'.$this->hash
;