openssl_encrypt_ccm.phpt 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. --TEST--
  2. openssl_encrypt() 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. $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
  25. var_dump(openssl_encrypt('data', $method, 'password', 0, '', $tag, ''));
  26. // Test setting different IV length and tag length
  27. var_dump(openssl_encrypt('data', $method, 'password', 0, str_repeat('x', 10), $tag, '', 14));
  28. var_dump(strlen($tag));
  29. // Test setting invalid tag length
  30. var_dump(openssl_encrypt('data', $method, 'password', 0, str_repeat('x', 16), $tag, '', 1024));
  31. ?>
  32. --EXPECTF--
  33. aes-128-ccm - TEST 0
  34. bool(true)
  35. bool(true)
  36. aes-128-ccm - TEST 1
  37. bool(true)
  38. bool(true)
  39. aes-256-ccm - TEST 0
  40. bool(true)
  41. bool(true)
  42. Warning: openssl_encrypt(): Setting of IV length for AEAD mode failed in %s on line %d
  43. bool(false)
  44. string(8) "p/lvgA=="
  45. int(14)
  46. Warning: openssl_encrypt(): Setting of IV length for AEAD mode failed in %s on line %d
  47. bool(false)