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\A192KW; |
17
|
|
|
use PHPUnit\Framework\TestCase; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* These tests come from the RFCRFC5649Test. |
21
|
|
|
* |
22
|
|
|
* @see https://tools.ietf.org/html/rfc5649#section-6 |
23
|
|
|
*/ |
24
|
|
|
final class RFC5649Test extends TestCase |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @test |
28
|
|
|
*/ |
29
|
|
|
public function wrap20BytesKeyDataWith192BitKEK() |
30
|
|
|
{ |
31
|
|
|
$kek = hex2bin('5840df6e29b02af1ab493b705bf16ea1ae8338f4dcc176a8'); |
32
|
|
|
$key = hex2bin('c37b7e6492584340bed12207808941155068f738'); |
33
|
|
|
|
34
|
|
|
$wrapped = A192KW::wrap($kek, $key, true); |
35
|
|
|
static::assertEquals(hex2bin('138bdeaa9b8fa7fc61f97742e72248ee5ae6ae5360d1ae6a5f54f373fa543b6a'), $wrapped); |
36
|
|
|
$unwrapped = A192KW::unwrap($kek, $wrapped, true); |
37
|
|
|
static::assertEquals($key, $unwrapped); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @test |
42
|
|
|
*/ |
43
|
|
|
public function wrap7BytesKeyDataWith192BitKEK() |
44
|
|
|
{ |
45
|
|
|
$kek = hex2bin('5840df6e29b02af1ab493b705bf16ea1ae8338f4dcc176a8'); |
46
|
|
|
$key = hex2bin('466f7250617369'); |
47
|
|
|
|
48
|
|
|
$wrapped = A192KW::wrap($kek, $key, true); |
49
|
|
|
static::assertEquals(hex2bin('afbeb0f07dfbf5419200f2ccb50bb24f'), $wrapped); |
50
|
|
|
$unwrapped = A192KW::unwrap($kek, $wrapped, true); |
51
|
|
|
static::assertEquals($key, $unwrapped); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|