1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace PHPassLib\Test\Hash;
13:
14: use PHPassLib\Hash\BSDiCrypt;
15:
16: 17: 18: 19: 20: 21: 22: 23:
24: class BSDiCryptTest extends \PHPUnit_Framework_TestCase
25: {
26:
27: 28: 29: 30: 31:
32: public function validTestVectorProvider()
33: {
34: $vectors = array (
35:
36: array ("U*U*U*U*", '_J9..CCCCXBrJUJV154M'),
37: array ("U*U***U", '_J9..CCCCXUhOBTXzaiE'),
38: array ("U*U***U*", '_J9..CCCC4gQ.mB/PffM'),
39: array ("*U*U*U*U", '_J9..XXXXvlzQGqpPPdk'),
40: array ("*U*U*U*U*", '_J9..XXXXsqM/YSSP..Y'),
41: array ("*U*U*U*U*U*U*U*U", '_J9..XXXXVL7qJCnku0I'),
42: array ("*U*U*U*U*U*U*U*U*", '_J9..XXXXAj8cFbP5scI'),
43: array ("ab1234567", '_J9..SDizh.vll5VED9g'),
44: array ("cr1234567", '_J9..SDizRjWQ/zePPHc'),
45: array ("zxyDPWgydbQjgq", '_J9..SDizxmRI1GjnQuE'),
46: array ("726 even", '_K9..SaltNrQgIYUAeoY'),
47: array ("", '_J9..SDSD5YGyRCr4W4c'),
48: );
49:
50: return $vectors;
51: }
52:
53: 54: 55: 56: 57:
58: public function invalidTestVectorProvider()
59: {
60: $vectors = array (
61: array ("", '_K1.!crsmZxOLzfJH8iw', '*0'),
62: array ("", '*0', '*1'),
63: array ("", '*1', '*0'),
64: );
65:
66: return $vectors;
67: }
68:
69: 70: 71: 72: 73: 74: 75: 76:
77: public function validTestVectorsProduceExpectedResults($password, $hash)
78: {
79: $config = substr($hash, 0, 9);
80: $this->assertEquals($hash, BSDiCrypt::hash($password, $config));
81: $this->assertTrue(BSDiCrypt::verify($password, $hash));
82: }
83:
84: 85: 86: 87: 88: 89: 90: 91:
92: public function invalidTestVectorsProduceExpectedResults($password, $hash, $errorString)
93: {
94: $config = substr($hash, 0, 9);
95: $this->assertEquals($errorString, BSDiCrypt::hash($password, $config));
96: $this->assertFalse(BSDiCrypt::verify($password, $hash));
97: }
98:
99: 100: 101:
102: public function genconfigAndParseconfigProduceMatchingResults()
103: {
104: $options = array (
105: 'rounds' => 5001,
106: 'salt' => 'CCC.',
107: );
108: $config = BSDiCrypt::genConfig($options);
109:
110: $this->assertEquals('_7C/.CCC.', $config);
111: $this->assertSame($options, BSDiCrypt::parseConfig($config));
112:
113: $options = array (
114: 'rounds' => 5000,
115: 'salt' => 'CCC.',
116: );
117: $config = BSDiCrypt::genConfig($options);
118: $options['rounds'] = 4999;
119:
120:
121: $this->assertEquals('_5C/.CCC.', $config, $config);
122: $this->assertSame($options, BSDiCrypt::parseConfig($config));
123: }
124:
125: }
126: