1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace PHPassLib\Test\Hash;
13:
14: use PHPassLib\Hash\PBKDF2;
15:
16: 17: 18: 19: 20: 21: 22: 23:
24: class PBKDF2Test extends \PHPUnit_Framework_TestCase
25: {
26:
27: 28: 29: 30: 31:
32: public function validTestVectorProvider()
33: {
34: $vectors = array (
35:
36: array ("password", '$pbkdf2$1212$OB.dtnSEXZK8U5cgxU/GYQ$y5LKPOplRmok7CZp/aqVDVg8zGI'),
37: array ("password", '$pbkdf2-sha256$1212$4vjV83LKPjQzk31VI4E0Vw$hsYF68OiOUPdDZ1Fg.fJPeq1h/gXXY7acBp9/6c.tmQ'),
38: array ("password", '$pbkdf2-sha512$1212$RHY0Fr3IDMSVO/RSZyb5ow$eNLfBK.eVozomMr.1gYa17k9B7KIK25NOEshvhrSX.esqY3s.FvWZViXz4KoLlQI.BzY/YTNJOiKc5gBYFYGww'),
39: );
40:
41: return $vectors;
42: }
43:
44: 45: 46: 47: 48:
49: public function invalidTestVectorProvider()
50: {
51: $vectors = array (
52: array ("", '$pbkdf2$01212$THDqatpidANpadlLeTeOEg$HV3oi1k5C5LQCgG1BMOL.BX4YZc', '*0'),
53: array ("", '*0', '*1'),
54: array ("", '*1', '*0'),
55: );
56:
57: return $vectors;
58: }
59:
60: 61: 62: 63: 64: 65: 66: 67:
68: public function validTestVectorsProduceExpectedResults($password, $hash)
69: {
70: $this->assertEquals($hash, PBKDF2::hash($password, $hash));
71: $this->assertTrue(PBKDF2::verify($password, $hash));
72: }
73:
74: 75: 76: 77: 78: 79: 80: 81:
82: public function invalidTestVectorsProduceExpectedResults($password, $hash, $errorString)
83: {
84: $this->assertEquals($errorString, PBKDF2::hash($password, $hash));
85: $this->assertFalse(PBKDF2::verify($password, $hash));
86: }
87:
88: 89: 90:
91: public function genconfigAndParseconfigProduceMatchingResults()
92: {
93: $options = array (
94: 'digest' => 'sha256',
95: 'rounds' => '1212',
96: 'salt' => '4vjV83LKPjQzk31VI4E0Vw.',
97: );
98: $config = PBKDF2::genConfig($options);
99: $options['saltSize'] = 17;
100:
101: $this->assertEquals('$pbkdf2-sha256$1212$4vjV83LKPjQzk31VI4E0Vw.', $config);
102: $this->assertSame($options, PBKDF2::parseConfig($config));
103: }
104:
105: }
106: