openssl_decrypt_ccm.phpt 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. --TEST--
  2. openssl_decrypt() with CCM cipher algorithm tests
  3. --EXTENSIONS--
  4. openssl
  5. --SKIPIF--
  6. <?php
  7. if (!in_array('aes-256-ccm', openssl_get_cipher_methods()))
  8. die("skip: aes-256-ccm not available");
  9. ?>
  10. --FILE--
  11. <?php
  12. require_once __DIR__ . "/cipher_tests.inc";
  13. $methods = ['aes-128-ccm', 'aes-256-ccm'];
  14. foreach ($methods as $method) {
  15. $tests = openssl_get_cipher_tests($method);
  16. foreach ($tests as $idx => $test) {
  17. echo "$method - 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
  24. var_dump(openssl_decrypt($test['ct'], $method, $test['key'], OPENSSL_RAW_DATA,
  25. '', $test['tag'], $test['aad']));
  26. // failed because no AAD
  27. var_dump(openssl_decrypt($test['ct'], $method, $test['key'], OPENSSL_RAW_DATA,
  28. $test['iv'], $test['tag']));
  29. // failed because wrong tag
  30. var_dump(openssl_decrypt($test['ct'], $method, $test['key'], OPENSSL_RAW_DATA,
  31. $test['iv'], str_repeat('x', 10), $test['aad']));
  32. ?>
  33. --EXPECTF--
  34. aes-128-ccm - TEST 0
  35. bool(true)
  36. aes-128-ccm - TEST 1
  37. bool(true)
  38. aes-256-ccm - TEST 0
  39. bool(true)
  40. Warning: openssl_decrypt(): Setting of IV length for AEAD mode failed in %s on line %d
  41. bool(false)
  42. bool(false)
  43. bool(false)