xref: /PHP-7.2/ext/openssl/tests/cipher_tests.inc (revision 0216630e)
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);
113
114function openssl_get_cipher_tests($method)
115{
116    global $php_openssl_cipher_tests;
117
118    $tests = array();
119
120    foreach ($php_openssl_cipher_tests[$method] as $instance) {
121        $test = array();
122        foreach ($instance as $field_name => $field_value) {
123            $test[$field_name] = pack("H*", $field_value);
124        }
125        if (!isset($test['aad'])) {
126            $test['aad'] = "";
127        }
128        $tests[] = $test;
129    }
130
131    return $tests;
132}
133