1--TEST--
2openssl_decrypt() with OCB cipher algorithm tests
3--EXTENSIONS--
4openssl
5--SKIPIF--
6<?php
7if (!in_array('aes-128-ocb', openssl_get_cipher_methods()))
8	die("skip: aes-128-ocb not available");
9?>
10--FILE--
11<?php
12require_once __DIR__ . "/cipher_tests.inc";
13$method = 'aes-128-ocb';
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	'', $test['tag'], $test['aad']));
26
27// IV too long
28var_dump(openssl_decrypt($test['ct'], $method, $test['key'], OPENSSL_RAW_DATA,
29	str_repeat('x', 32), $test['tag'], $test['aad']));
30
31// failed because no AAD
32var_dump(openssl_decrypt($test['ct'], $method, $test['key'], OPENSSL_RAW_DATA,
33	$test['iv'], $test['tag']));
34
35// failed because wrong tag
36var_dump(openssl_decrypt($test['ct'], $method, $test['key'], OPENSSL_RAW_DATA,
37	$test['iv'], str_repeat('x', 16), $test['aad']));
38
39?>
40--EXPECTF--
41TEST 0
42bool(true)
43TEST 1
44bool(true)
45TEST 2
46bool(true)
47TEST 3
48bool(true)
49TEST 4
50bool(true)
51TEST 5
52bool(true)
53
54Warning: openssl_decrypt(): Setting of IV length for AEAD mode failed in %s on line %d
55bool(false)
56
57Warning: openssl_decrypt(): Setting of IV length for AEAD mode failed in %s on line %d
58bool(false)
59bool(false)
60bool(false)
61