xref: /php-src/ext/openssl/tests/cipher_tests.inc (revision 14079688)
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    'chacha20-poly1305' => array(
164        array(
165            'key' => '808182838485868788898a8b8c8d8e8f' .
166                     '909192939495969798999a9b9c9d9e9f',
167            'iv'  => '070000004041424344454647',
168            'aad' => '50515253c0c1c2c3c4c5c6c7',
169            'tag' => '1ae10b594f09e26a7e902ecbd0600691',
170            'pt'  => '4c616469657320616e642047656e746c' .
171                     '656d656e206f662074686520636c6173' .
172                     '73206f66202739393a20496620492063' .
173                     '6f756c64206f6666657220796f75206f' .
174                     '6e6c79206f6e652074697020666f7220' .
175                     '746865206675747572652c2073756e73' .
176                     '637265656e20776f756c642062652069' .
177                     '742e',
178            'ct'  => 'd31a8d34648e60db7b86afbc53ef7ec2' .
179                     'a4aded51296e08fea9e2b5a736ee62d6' .
180                     '3dbea45e8ca9671282fafb69da92728b' .
181                     '1a71de0a9e060b2905d6a5b67ecd3b36' .
182                     '92ddbd7f2d778b8c9803aee328091b58' .
183                     'fab324e4fad675945585808b4831d7bc' .
184                     '3ff4def08e4b7a9de576d26586cec64b' .
185                     '6116',
186        ),
187        array(
188            'key' => '1c9240a5eb55d38af333888604f6b5f0' .
189                     '473917c1402b80099dca5cbc207075c0',
190            'iv'  => '000000000102030405060708',
191            'aad' => 'f33388860000000000004e91',
192            'tag' => 'eead9d67890cbb22392336fea1851f38',
193            'pt'  => '496e7465726e65742d44726166747320' .
194                     '61726520647261667420646f63756d65' .
195                     '6e74732076616c696420666f72206120' .
196                     '6d6178696d756d206f6620736978206d' .
197                     '6f6e74687320616e64206d6179206265' .
198                     '20757064617465642c207265706c6163' .
199                     '65642c206f72206f62736f6c65746564' .
200                     '206279206f7468657220646f63756d65' .
201                     '6e747320617420616e792074696d652e' .
202                     '20497420697320696e617070726f7072' .
203                     '6961746520746f2075736520496e7465' .
204                     '726e65742d4472616674732061732072' .
205                     '65666572656e6365206d617465726961' .
206                     '6c206f7220746f206369746520746865' .
207                     '6d206f74686572207468616e20617320' .
208                     '2fe2809c776f726b20696e2070726f67' .
209                     '726573732e2fe2809d',
210            'ct'  => '64a0861575861af460f062c79be643bd' .
211                     '5e805cfd345cf389f108670ac76c8cb2' .
212                     '4c6cfc18755d43eea09ee94e382d26b0' .
213                     'bdb7b73c321b0100d4f03b7f355894cf' .
214                     '332f830e710b97ce98c8a84abd0b9481' .
215                     '14ad176e008d33bd60f982b1ff37c855' .
216                     '9797a06ef4f0ef61c186324e2b350638' .
217                     '3606907b6a7c02b0f9f6157b53c867e4' .
218                     'b9166c767b804d46a59b5216cde7a4e9' .
219                     '9040c5a40433225ee282a1b0a06c523e' .
220                     'af4534d7f83fa1155b0047718cbc546a' .
221                     '0d072b04b3564eea1b422273f548271a' .
222                     '0bb2316053fa76991955ebd63159434e' .
223                     'cebb4e466dae5a1073a6727627097a10' .
224                     '49e617d91d361094fa68f0ff77987130' .
225                     '305beaba2eda04df997b714d6c6f2c29' .
226                     'a6ad5cb4022b02709b',
227        ),
228    ),
229);
230
231function openssl_get_cipher_tests($method)
232{
233    global $php_openssl_cipher_tests;
234
235    $tests = array();
236
237    foreach ($php_openssl_cipher_tests[$method] as $instance) {
238        $test = array();
239        foreach ($instance as $field_name => $field_value) {
240            $test[$field_name] = pack("H*", $field_value);
241        }
242        if (!isset($test['aad'])) {
243            $test['aad'] = "";
244        }
245        $tests[] = $test;
246    }
247
248    return $tests;
249}
250