|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* The MIT License (MIT) |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (c) 2014-2016 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 AESKW\Tests; |
|
13
|
|
|
|
|
14
|
|
|
use AESKW\A192KW; |
|
15
|
|
|
use PHPUnit\Framework\TestCase; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* These tests come from the RFCRFC5649Test. |
|
19
|
|
|
* |
|
20
|
|
|
* @see https://tools.ietf.org/html/rfc5649#section-6 |
|
21
|
|
|
*/ |
|
22
|
|
|
final class RFC5649Test extends TestCase |
|
23
|
|
|
{ |
|
24
|
|
|
public function testWrap20BytesKeyDataWith192BitKEK() |
|
25
|
|
|
{ |
|
26
|
|
|
$kek = hex2bin('5840df6e29b02af1ab493b705bf16ea1ae8338f4dcc176a8'); |
|
27
|
|
|
$key = hex2bin('c37b7e6492584340bed12207808941155068f738'); |
|
28
|
|
|
|
|
29
|
|
|
$wrapped = A192KW::wrap($kek, $key, true); |
|
30
|
|
|
$this->assertEquals(hex2bin('138bdeaa9b8fa7fc61f97742e72248ee5ae6ae5360d1ae6a5f54f373fa543b6a'), $wrapped); |
|
31
|
|
|
$unwrapped = A192KW::unwrap($kek, $wrapped, true); |
|
32
|
|
|
$this->assertEquals($key, $unwrapped); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function testWrap7BytesKeyDataWith192BitKEK() |
|
36
|
|
|
{ |
|
37
|
|
|
$kek = hex2bin('5840df6e29b02af1ab493b705bf16ea1ae8338f4dcc176a8'); |
|
38
|
|
|
$key = hex2bin('466f7250617369'); |
|
39
|
|
|
|
|
40
|
|
|
$wrapped = A192KW::wrap($kek, $key, true); |
|
41
|
|
|
$this->assertEquals(hex2bin('afbeb0f07dfbf5419200f2ccb50bb24f'), $wrapped); |
|
42
|
|
|
$unwrapped = A192KW::unwrap($kek, $wrapped, true); |
|
43
|
|
|
$this->assertEquals($key, $unwrapped); |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|