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\Symmetric\Generator; | |
9 | ||
10 | use CryptLib\Random\Factory as RandomFactory; | |
11 | use CryptLib\Key\Factory as KeyFactory; | |
12 | use CryptLib\Key\Symmetric\Raw as Raw; | |
13 | ||
14 | /** | |
15 | * Description of mtrand | |
16 | * | |
17 | * @author ircmaxell | |
18 | */ | |
19 | class Internal implements \CryptLib\Key\Generator { | |
20 | ||
21 | protected $kdf = null; | |
22 | ||
23 | protected $random = null; | |
24 | ||
25 | public static function test() { | |
26 | return true; | |
27 | } | |
28 | ||
29 | public function __construct(array $options = array()) { | |
30 | $options += array('kdf' => null, 'random' => null); | |
31 | if (is_null($options['kdf'])) { | |
32 | $factory = new KeyFactory(); | |
33 | $options['kdf'] = $factory->getKdf('kdf3'); | |
34 | } | |
35 | $this->kdf = $options['kdf']; | |
36 | if (is_null($options['random'])) { | |
37 | $options['random'] = new RandomFactory(); | |
38 | } | |
39 | $this->random = $options['random']; | |
40 | } | |
41 | ||
42 | public function __toString() { | |
43 | } | |
44 | ||
45 | public function generate( | |
46 | \CryptLib\Core\Strength $strength, | |
47 | $size, | |
48 | $passphrase = '' | |
49 | ) { | |
50 | $generator = $this->random->getGenerator($strength); | |
51 | $seed = $generator->generate($size); | |
52 | $key = $this->kdf->derive($seed, $size, $passphrase); | |
53 | return new Raw(substr($key, 0, $size)); | |
54 | } | |
55 | ||
56 | public function getType() { | |
57 | return static::TYPE_SYMMETRIC; | |
58 | } | |
59 | } |