Passed
Pull Request — master (#14)
by Florent
06:01 queued 02:47
created

One64BitBlockTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 44
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AESKW\Tests;
6
7
use AESKW\A128KW;
8
use AESKW\A192KW;
9
use AESKW\A256KW;
10
use PHPUnit\Framework\TestCase;
11
12
/**
13
 * These tests come from the RFC3394.
14
 *
15
 * @see https://www.ietf.org/rfc/rfc3394.txt#4
16
 *
17
 * @internal
18
 */
19
final class One64BitBlockTest extends TestCase
20
{
21
    /**
22
     * @test
23
     */
24
    public function wrap64BitsKeyDataWith128BitKEK(): void
25
    {
26
        $kek = hex2bin('000102030405060708090A0B0C0D0E0F');
27
        $data = hex2bin('0011223344556677');
28
29
        $wrapped = A128KW::wrap($kek, $data);
30
        static::assertSame(hex2bin('F4740052E82A225174CE86FBD7B805E7'), $wrapped);
31
        $unwrapped = A128KW::unwrap($kek, $wrapped);
32
        static::assertSame($data, $unwrapped);
33
    }
34
35
    /**
36
     * @test
37
     */
38
    public function wrap64BitsKeyDataWith192BitKEK(): void
39
    {
40
        $kek = hex2bin('000102030405060708090A0B0C0D0E0F1011121314151617');
41
        $data = hex2bin('0011223344556677');
42
43
        $wrapped = A192KW::wrap($kek, $data);
44
        static::assertSame(hex2bin('DFE8FD5D1A3786A7351D385096CCFB29'), $wrapped);
45
        $unwrapped = A192KW::unwrap($kek, $wrapped);
46
        static::assertSame($data, $unwrapped);
47
    }
48
49
    /**
50
     * @test
51
     */
52
    public function wrap64BitsKeyDataWith256BitKEK(): void
53
    {
54
        $kek = hex2bin('000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F');
55
        $data = hex2bin('0011223344556677');
56
57
        $wrapped = A256KW::wrap($kek, $data);
58
        static::assertSame(hex2bin('794314D454E3FDE1F661BD9F31FBFA31'), $wrapped);
59
        $unwrapped = A256KW::unwrap($kek, $wrapped);
60
        static::assertSame($data, $unwrapped);
61
    }
62
}
63