1--TEST-- 2openssl_encrypt() 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 $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, '', $tag, '')); 26 27// Failing to retrieve tag (must be at most 16 bytes) 28var_dump(openssl_encrypt('data', $method, 'password', 0, str_repeat('x', 12), $tag, '', 20)); 29 30// Failing when no tag supplied 31var_dump(openssl_encrypt('data', $method, 'password', 0, str_repeat('x', 12))); 32?> 33--EXPECTF-- 34TEST 0 35bool(true) 36bool(true) 37TEST 1 38bool(true) 39bool(true) 40TEST 2 41bool(true) 42bool(true) 43TEST 3 44bool(true) 45bool(true) 46TEST 4 47bool(true) 48bool(true) 49TEST 5 50bool(true) 51bool(true) 52 53Warning: openssl_encrypt(): Setting of IV length for AEAD mode failed in %s on line %d 54bool(false) 55 56Warning: openssl_encrypt(): Setting tag length for AEAD cipher failed in %s on line %d 57bool(false) 58 59Warning: openssl_encrypt(): A tag should be provided when using AEAD mode in %s on line %d 60bool(false) 61