1--TEST-- 2openssl_decrypt() 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 $pt = openssl_decrypt($test['ct'], $method, $test['key'], OPENSSL_RAW_DATA, 20 $test['iv'], $test['tag'], $test['aad']); 21 var_dump($test['pt'] === $pt); 22 } 23} 24 25// no IV 26var_dump(openssl_decrypt($test['ct'], $method, $test['key'], OPENSSL_RAW_DATA, 27 '', $test['tag'], $test['aad'])); 28// failed because no AAD 29var_dump(openssl_decrypt($test['ct'], $method, $test['key'], OPENSSL_RAW_DATA, 30 $test['iv'], $test['tag'])); 31// failed because wrong tag 32var_dump(openssl_decrypt($test['ct'], $method, $test['key'], OPENSSL_RAW_DATA, 33 $test['iv'], str_repeat('x', 10), $test['aad'])); 34 35?> 36--EXPECTF-- 37aes-128-ccm - TEST 0 38bool(true) 39aes-128-ccm - TEST 1 40bool(true) 41aes-256-ccm - TEST 0 42bool(true) 43 44Warning: openssl_decrypt(): Setting of IV length for AEAD mode failed in %s on line %d 45bool(false) 46bool(false) 47bool(false) 48