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