xref: /PHP-8.1/ext/openssl/tests/cipher_tests.inc (revision 750a74ed)
1<?php
2$php_openssl_cipher_tests = array(
3    'aes-128-ccm' => array(
4        array(
5            'key' => '404142434445464748494a4b4c4d4e4f',
6            'iv'  => '1011121314151617',
7            'aad' => '000102030405060708090a0b0c0d0e0f',
8            'tag' => '1fc64fbfaccd',
9            'pt'  => '202122232425262728292a2b2c2d2e2f',
10            'ct'  => 'd2a1f0e051ea5f62081a7792073d593d',
11        ),
12        array(
13            'key' => '404142434445464748494a4b4c4d4e4f',
14            'iv'  => '101112131415161718191a1b',
15            'aad' => '000102030405060708090a0b0c0d0e0f' .
16                     '10111213',
17            'tag' => '484392fbc1b09951',
18            'pt'  => '202122232425262728292a2b2c2d2e2f' .
19                     '3031323334353637',
20            'ct'  => 'e3b201a9f5b71a7a9b1ceaeccd97e70b' .
21                     '6176aad9a4428aa5',
22        ),
23    ),
24    'aes-256-ccm' => array(
25        array(
26            'key' => '1bde3251d41a8b5ea013c195ae128b21' .
27                     '8b3e0306376357077ef1c1c78548b92e',
28            'iv'  => '5b8e40746f6b98e00f1d13ff41',
29            'aad' => 'c17a32514eb6103f3249e076d4c871dc' .
30                     '97e04b286699e54491dc18f6d734d4c0',
31            'tag' => '2024931d73bca480c24a24ece6b6c2bf',
32            'pt'  => '53bd72a97089e312422bf72e242377b3' .
33                     'c6ee3e2075389b999c4ef7f28bd2b80a',
34            'ct'  => '9a5fcccdb4cf04e7293d2775cc76a488' .
35                     'f042382d949b43b7d6bb2b9864786726',
36        ),
37    ),
38    'aes-128-gcm' => array(
39        array(
40            'key' => '00000000000000000000000000000000',
41            'iv'  => '000000000000000000000000',
42            'tag' => '58e2fccefa7e3061367f1d57a4e7455a',
43            'pt'  => '',
44            'ct'  => '',
45        ),
46        array(
47            'key' => '00000000000000000000000000000000',
48            'iv'  => '000000000000000000000000',
49            'tag' => 'ab6e47d42cec13bdf53a67b21257bddf',
50            'pt'  => '00000000000000000000000000000000',
51            'ct'  => '0388dace60b6a392f328c2b971b2fe78',
52        ),
53        array(
54            'key' => 'feffe9928665731c6d6a8f9467308308',
55            'iv'  => 'cafebabefacedbaddecaf888',
56            'tag' => '4d5c2af327cd64a62cf35abd2ba6fab4',
57            'pt'  => 'd9313225f88406e5a55909c5aff5269a' .
58                     '86a7a9531534f7da2e4c303d8a318a72' .
59                     '1c3c0c95956809532fcf0e2449a6b525' .
60                     'b16aedf5aa0de657ba637b391aafd255',
61            'ct'  => '42831ec2217774244b7221b784d0d49c' .
62                     'e3aa212f2c02a4e035c17e2329aca12e' .
63                     '21d514b25466931c7d8f6a5aac84aa05' .
64                     '1ba30b396a0aac973d58e091473f5985',
65        ),
66        array(
67            'key' => 'feffe9928665731c6d6a8f9467308308',
68            'iv'  => 'cafebabefacedbaddecaf888',
69            'aad' => 'feedfacedeadbeeffeedfacedeadbeefabaddad2',
70            'tag' => '5bc94fbc3221a5db94fae95ae7121a47',
71            'pt'  => 'd9313225f88406e5a55909c5aff5269a' .
72                     '86a7a9531534f7da2e4c303d8a318a72' .
73                     '1c3c0c95956809532fcf0e2449a6b525' .
74                     'b16aedf5aa0de657ba637b39',
75            'ct'  => '42831ec2217774244b7221b784d0d49c' .
76                     'e3aa212f2c02a4e035c17e2329aca12e' .
77                     '21d514b25466931c7d8f6a5aac84aa05' .
78                     '1ba30b396a0aac973d58e091',
79        ),
80        array(
81            'key' => 'feffe9928665731c6d6a8f9467308308',
82            'iv'  => 'cafebabefacedbad',
83            'aad' => 'feedfacedeadbeeffeedfacedeadbeefabaddad2',
84            'tag' => '3612d2e79e3b0785561be14aaca2fccb',
85            'pt'  => 'd9313225f88406e5a55909c5aff5269a' .
86                     '86a7a9531534f7da2e4c303d8a318a72' .
87                     '1c3c0c95956809532fcf0e2449a6b525' .
88                     'b16aedf5aa0de657ba637b39',
89            'ct'  => '61353b4c2806934a777ff51fa22a4755' .
90                     '699b2a714fcdc6f83766e5f97b6c7423' .
91                     '73806900e49f24b22b097544d4896b42' .
92                     '4989b5e1ebac0f07c23f4598'
93        ),
94        array(
95            'key' => 'feffe9928665731c6d6a8f9467308308',
96            'iv'  => '9313225df88406e555909c5aff5269aa' .
97                     '6a7a9538534f7da1e4c303d2a318a728' .
98                     'c3c0c95156809539fcf0e2429a6b5254' .
99                     '16aedbf5a0de6a57a637b39b',
100            'aad' => 'feedfacedeadbeeffeedfacedeadbeefabaddad2',
101            'tag' => '619cc5aefffe0bfa462af43c1699d050',
102            'pt'  => 'd9313225f88406e5a55909c5aff5269a' .
103                     '86a7a9531534f7da2e4c303d8a318a72' .
104                     '1c3c0c95956809532fcf0e2449a6b525' .
105                     'b16aedf5aa0de657ba637b39',
106            'ct'  => '8ce24998625615b603a033aca13fb894' .
107                     'be9112a5c3a211a8ba262a3cca7e2ca7' .
108                     '01e4a9a4fba43c90ccdcb281d48c7c6f' .
109                     'd62875d2aca417034c34aee5',
110        ),
111    ),
112    // First few test vectors from RFC 7253.
113    'aes-128-ocb' => array(
114        array(
115            'key' => '000102030405060708090A0B0C0D0E0F',
116            'iv'  => 'BBAA99887766554433221100',
117            'aad' => '',
118            'pt'  => '',
119            'tag' => '785407BFFFC8AD9EDCC5520AC9111EE6',
120            'ct'  => '',
121        ),
122        array(
123            'key' => '000102030405060708090A0B0C0D0E0F',
124            'iv'  => 'BBAA99887766554433221101',
125            'aad' => '0001020304050607',
126            'pt'  => '0001020304050607',
127            'tag' => '5725BDA0D3B4EB3A257C9AF1F8F03009',
128            'ct'  => '6820B3657B6F615A',
129        ),
130        array(
131            'key' => '000102030405060708090A0B0C0D0E0F',
132            'iv'  => 'BBAA99887766554433221102',
133            'aad' => '0001020304050607',
134            'pt'  => '',
135            'tag' => '81017F8203F081277152FADE694A0A00',
136            'ct'  => '',
137        ),
138        array(
139            'key' => '000102030405060708090A0B0C0D0E0F',
140            'iv'  => 'BBAA99887766554433221103',
141            'aad' => '',
142            'pt'  => '0001020304050607',
143            'tag' => '14054CD1F35D82760B2CD00D2F99BFA9',
144            'ct'  => '45DD69F8F5AAE724',
145        ),
146        array(
147            'key' => '000102030405060708090A0B0C0D0E0F',
148            'iv'  => 'BBAA99887766554433221104',
149            'aad' => '000102030405060708090A0B0C0D0E0F',
150            'pt'  => '000102030405060708090A0B0C0D0E0F',
151            'tag' => '3AD7A4FF3835B8C5701C1CCEC8FC3358',
152            'ct'  => '571D535B60B277188BE5147170A9A22C',
153        ),
154        array(
155            'key' => '0F0E0D0C0B0A09080706050403020100',
156            'iv'  => 'BBAA9988776655443322110D',
157            'aad' => '000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F2021222324252627',
158            'pt'  => '000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F2021222324252627',
159            'tag' => 'D0C515F4D1CDD4FDAC4F02AA',
160            'ct'  => '1792A4E31E0755FB03E31B22116E6C2DDF9EFD6E33D536F1A0124B0A55BAE884ED93481529C76B6A',
161        ),
162    ),
163);
164
165function openssl_get_cipher_tests($method)
166{
167    global $php_openssl_cipher_tests;
168
169    $tests = array();
170
171    foreach ($php_openssl_cipher_tests[$method] as $instance) {
172        $test = array();
173        foreach ($instance as $field_name => $field_value) {
174            $test[$field_name] = pack("H*", $field_value);
175        }
176        if (!isset($test['aad'])) {
177            $test['aad'] = "";
178        }
179        $tests[] = $test;
180    }
181
182    return $tests;
183}
184