Commit | Line | Data |
---|---|---|
14d4f286 S |
1 | <?php |
2 | /** | |
3 | * To change this template, choose Tools | Templates | |
4 | * and open the template in the editor. | |
5 | * @version Build @@version@@ | |
6 | */ | |
7 | ||
8 | namespace CryptLib\Key\Derivation\PBKDF; | |
9 | ||
10 | use CryptLib\Hash\Hash; | |
11 | ||
12 | /** | |
13 | * Description of pbkdf2 | |
14 | * | |
15 | * @author ircmaxell | |
16 | */ | |
17 | class Schneier | |
18 | extends \CryptLib\Key\Derivation\AbstractDerivation | |
19 | implements \CryptLib\Key\Derivation\PBKDF | |
20 | { | |
21 | ||
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'); | |
26 | } | |
27 | $tmp = hash($this->hash, $password . $salt, true); | |
28 | for ($i = 2; $i <= $iterations; $i++) { | |
29 | $tmp = hash($this->hash, $tmp . $password . $salt, true); | |
30 | } | |
31 | return substr($tmp, 0, $length); | |
32 | } | |
33 | ||
34 | /** | |
35 | * Get the signature for this implementation | |
36 | * | |
37 | * This should include all information needed to build the same instance | |
38 | * later. | |
39 | * | |
40 | * @return string The signature for this instance | |
41 | */ | |
42 | public function getSignature() { | |
43 | return 'schneier-'.$this->hash; | |
44 | } | |
45 | ||
46 | } |