VectorTest::testVector2()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 1
Metric Value
cc 1
eloc 10
c 3
b 1
f 1
nc 1
nop 0
dl 0
loc 13
rs 9.4285
1
<?php
2
3
/*
4
 * The MIT License (MIT)
5
 *
6
 * Copyright (c) 2014-2015 Spomky-Labs
7
 *
8
 * This software may be modified and distributed under the terms
9
 * of the MIT license.  See the LICENSE file for details.
10
 */
11
12
namespace PBKDF2\tests;
13
14
use PBKDF2\PBKDF2;
15
16
/**
17
 * @see https://www.ietf.org/rfc/rfc6070.txt
18
 */
19
class VectorTest extends \PHPUnit_Framework_TestCase
20
{
21
    public function testVector1()
22
    {
23
        $algorithm = 'sha1';
24
        $password = 'password';
25
        $salt = 'salt';
26
        $count = 1;
27
        $dkLen = 0;
28
        $hex_expected = '0c60c80f961f0e71f3a9b524af6012062fe037a6';
29
        $raw_expected = pack('H*', $hex_expected);
30
31
        $this->assertSame($hex_expected, PBKDF2::deriveKey($algorithm, $password, $salt, $count, $dkLen));
32
        $this->assertSame($raw_expected, PBKDF2::deriveKey($algorithm, $password, $salt, $count, $dkLen, true));
33
    }
34
35
    public function testVector2()
36
    {
37
        $algorithm = 'sha1';
38
        $password = 'password';
39
        $salt = 'salt';
40
        $count = 2;
41
        $dkLen = 0;
42
        $hex_expected = 'ea6c014dc72d6f8ccd1ed92ace1d41f0d8de8957';
43
        $raw_expected = pack('H*', $hex_expected);
44
45
        $this->assertSame($hex_expected, PBKDF2::deriveKey($algorithm, $password, $salt, $count, $dkLen));
46
        $this->assertSame($raw_expected, PBKDF2::deriveKey($algorithm, $password, $salt, $count, $dkLen, true));
47
    }
48
49
    public function testVector3()
50
    {
51
        $algorithm = 'sha1';
52
        $password = 'password';
53
        $salt = 'salt';
54
        $count = 4096;
55
        $dkLen = 0;
56
        $hex_expected = '4b007901b765489abead49d926f721d065a429c1';
57
        $raw_expected = pack('H*', $hex_expected);
58
59
        $this->assertSame($hex_expected, PBKDF2::deriveKey($algorithm, $password, $salt, $count, $dkLen));
60
        $this->assertSame($raw_expected, PBKDF2::deriveKey($algorithm, $password, $salt, $count, $dkLen, true));
61
    }
62
63
    /*public function testVector4()
64
    {
65
        $algorithm = 'sha1';
66
        $password  = 'password';
67
        $salt      = 'salt';
68
        $count     = 16777216;
69
        $dkLen     = 0;
70
        $hex_expected  = 'eefe3d61cd4da4e4e9945b3d6ba2158c2634e984';
71
        $raw_expected  = pack('H*', $hex_expected);
72
73
        $this->assertSame($hex_expected, PBKDF2::deriveKey($algorithm, $password, $salt, $count, $dkLen));
74
        $this->assertSame($raw_expected, PBKDF2::deriveKey($algorithm, $password, $salt, $count, $dkLen, true));
75
    }*/
76
77
    public function testVector5()
78
    {
79
        $algorithm = 'sha1';
80
        $password = 'passwordPASSWORDpassword';
81
        $salt = 'saltSALTsaltSALTsaltSALTsaltSALTsalt';
82
        $count = 4096;
83
        $dkLen = 25;
84
        $hex_expected = '3d2eec4fe41c849b80c8d83662c0e44a8b291a964cf2f07038';
85
        $raw_expected = pack('H*', $hex_expected);
86
87
        $this->assertSame($hex_expected, PBKDF2::deriveKey($algorithm, $password, $salt, $count, $dkLen));
88
        $this->assertSame($raw_expected, PBKDF2::deriveKey($algorithm, $password, $salt, $count, $dkLen, true));
89
    }
90
91
    public function testVector6()
92
    {
93
        $algorithm = 'sha1';
94
        $password = "pass\x00word";
95
        $salt = "sa\x00lt";
96
        $count = 4096;
97
        $dkLen = 16;
98
        $hex_expected = '56fa6aa75548099dcc37d7f03425e0c3';
99
        $raw_expected = pack('H*', $hex_expected);
100
101
        $this->assertSame($hex_expected, PBKDF2::deriveKey($algorithm, $password, $salt, $count, $dkLen));
102
        $this->assertSame($raw_expected, PBKDF2::deriveKey($algorithm, $password, $salt, $count, $dkLen, true));
103
    }
104
}
105