1--TEST-- 2openssl_encrypt() with CCM cipher algorithm tests 3--SKIPIF-- 4<?php 5if (!extension_loaded("openssl")) 6 die("skip"); 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$method = 'aes-256-ccm'; 14$tests = openssl_get_cipher_tests($method); 15 16foreach ($tests as $idx => $test) { 17 echo "TEST $idx\n"; 18 $ct = openssl_encrypt($test['pt'], $method, $test['key'], OPENSSL_RAW_DATA, 19 $test['iv'], $tag, $test['aad'], strlen($test['tag'])); 20 var_dump($test['ct'] === $ct); 21 var_dump($test['tag'] === $tag); 22} 23 24// Empty IV error 25var_dump(openssl_encrypt('data', $method, 'password', 0, NULL, $tag, '')); 26 27// Test setting different IV length and unlimeted tag 28var_dump(openssl_encrypt('data', $method, 'password', 0, str_repeat('x', 10), $tag, '', 1024)); 29var_dump(strlen($tag)); 30?> 31--EXPECTF-- 32TEST 0 33bool(true) 34bool(true) 35 36Warning: openssl_encrypt(): Setting of IV length for AEAD mode failed in %s on line %d 37bool(false) 38string(8) "p/lvgA==" 39int(1024) 40