|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* The MIT License (MIT) |
|
7
|
|
|
* |
|
8
|
|
|
* Copyright (c) 2014-2018 Spomky-Labs |
|
9
|
|
|
* |
|
10
|
|
|
* This software may be modified and distributed under the terms |
|
11
|
|
|
* of the MIT license. See the LICENSE file for details. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace AESKW\Tests; |
|
15
|
|
|
|
|
16
|
|
|
use AESKW\A128KW; |
|
17
|
|
|
use AESKW\A192KW; |
|
18
|
|
|
use AESKW\A256KW; |
|
19
|
|
|
use PHPUnit\Framework\TestCase; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* These tests come from the RFC3394. |
|
23
|
|
|
* |
|
24
|
|
|
* @see https://www.ietf.org/rfc/rfc3394.txt#4 |
|
25
|
|
|
*/ |
|
26
|
|
|
final class One64BitBlockTest extends TestCase |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* @test |
|
30
|
|
|
*/ |
|
31
|
|
|
public function wrap64BitsKeyDataWith128BitKEK() |
|
32
|
|
|
{ |
|
33
|
|
|
$kek = hex2bin('000102030405060708090A0B0C0D0E0F'); |
|
34
|
|
|
$data = hex2bin('0011223344556677'); |
|
35
|
|
|
|
|
36
|
|
|
$wrapped = A128KW::wrap($kek, $data); |
|
37
|
|
|
static::assertEquals(hex2bin('F4740052E82A225174CE86FBD7B805E7'), $wrapped); |
|
38
|
|
|
$unwrapped = A128KW::unwrap($kek, $wrapped); |
|
39
|
|
|
static::assertEquals($data, $unwrapped); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @test |
|
44
|
|
|
*/ |
|
45
|
|
|
public function wrap64BitsKeyDataWith192BitKEK() |
|
46
|
|
|
{ |
|
47
|
|
|
$kek = hex2bin('000102030405060708090A0B0C0D0E0F1011121314151617'); |
|
48
|
|
|
$data = hex2bin('0011223344556677'); |
|
49
|
|
|
|
|
50
|
|
|
$wrapped = A192KW::wrap($kek, $data); |
|
51
|
|
|
static::assertEquals(hex2bin('DFE8FD5D1A3786A7351D385096CCFB29'), $wrapped); |
|
52
|
|
|
$unwrapped = A192KW::unwrap($kek, $wrapped); |
|
53
|
|
|
static::assertEquals($data, $unwrapped); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @test |
|
58
|
|
|
*/ |
|
59
|
|
|
public function wrap64BitsKeyDataWith256BitKEK() |
|
60
|
|
|
{ |
|
61
|
|
|
$kek = hex2bin('000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F'); |
|
62
|
|
|
$data = hex2bin('0011223344556677'); |
|
63
|
|
|
|
|
64
|
|
|
$wrapped = A256KW::wrap($kek, $data); |
|
65
|
|
|
static::assertEquals(hex2bin('794314D454E3FDE1F661BD9F31FBFA31'), $wrapped); |
|
66
|
|
|
$unwrapped = A256KW::unwrap($kek, $wrapped); |
|
67
|
|
|
static::assertEquals($data, $unwrapped); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|