1--TEST--
2openssl_decrypt() with GCM cipher algorithm tests
3--SKIPIF--
4<?php
5if (!extension_loaded("openssl"))
6	die("skip");
7if (!in_array('aes-128-gcm', openssl_get_cipher_methods()))
8	die("skip: aes-128-gcm not available");
9?>
10--FILE--
11<?php
12require_once __DIR__ . "/cipher_tests.inc";
13$method = 'aes-128-gcm';
14$tests = openssl_get_cipher_tests($method);
15
16foreach ($tests as $idx => $test) {
17    echo "TEST $idx\n";
18    $pt = openssl_decrypt($test['ct'], $method, $test['key'], OPENSSL_RAW_DATA,
19        $test['iv'], $test['tag'], $test['aad']);
20    var_dump($test['pt'] === $pt);
21}
22
23// no IV
24var_dump(openssl_decrypt($test['ct'], $method, $test['key'], OPENSSL_RAW_DATA,
25	NULL, $test['tag'], $test['aad']));
26// failed because no AAD
27var_dump(openssl_decrypt($test['ct'], $method, $test['key'], OPENSSL_RAW_DATA,
28	$test['iv'], $test['tag']));
29// failed because wrong tag
30var_dump(openssl_decrypt($test['ct'], $method, $test['key'], OPENSSL_RAW_DATA,
31	$test['iv'], str_repeat('x', 16), $test['aad']));
32
33?>
34--EXPECTF--
35TEST 0
36bool(true)
37TEST 1
38bool(true)
39TEST 2
40bool(true)
41TEST 3
42bool(true)
43TEST 4
44bool(true)
45TEST 5
46bool(true)
47
48Warning: openssl_decrypt(): Setting of IV length for AEAD mode failed in %s on line %d
49bool(false)
50bool(false)
51bool(false)
52