openssl_encrypt_gcm.phpt 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. --TEST--
  2. openssl_encrypt() with GCM cipher algorithm tests
  3. --EXTENSIONS--
  4. openssl
  5. --SKIPIF--
  6. <?php
  7. if (!in_array('aes-128-gcm', openssl_get_cipher_methods()))
  8. die("skip: aes-128-gcm not available");
  9. ?>
  10. --FILE--
  11. <?php
  12. require_once __DIR__ . "/cipher_tests.inc";
  13. $method = 'aes-128-gcm';
  14. $tests = openssl_get_cipher_tests($method);
  15. foreach ($tests as $idx => $test) {
  16. echo "TEST $idx\n";
  17. $ct = openssl_encrypt($test['pt'], $method, $test['key'], OPENSSL_RAW_DATA,
  18. $test['iv'], $tag, $test['aad'], strlen($test['tag']));
  19. var_dump($test['ct'] === $ct);
  20. var_dump($test['tag'] === $tag);
  21. }
  22. // Empty IV error
  23. var_dump(openssl_encrypt('data', $method, 'password', 0, '', $tag, ''));
  24. // Failing to retrieve tag (max is 16 bytes)
  25. var_dump(openssl_encrypt('data', $method, 'password', 0, str_repeat('x', 32), $tag, '', 20));
  26. // Failing when no tag supplied
  27. var_dump(openssl_encrypt('data', $method, 'password', 0, str_repeat('x', 32)));
  28. ?>
  29. --EXPECTF--
  30. TEST 0
  31. bool(true)
  32. bool(true)
  33. TEST 1
  34. bool(true)
  35. bool(true)
  36. TEST 2
  37. bool(true)
  38. bool(true)
  39. TEST 3
  40. bool(true)
  41. bool(true)
  42. TEST 4
  43. bool(true)
  44. bool(true)
  45. TEST 5
  46. bool(true)
  47. bool(true)
  48. Warning: openssl_encrypt(): Setting of IV length for AEAD mode failed in %s on line %d
  49. bool(false)
  50. Warning: openssl_encrypt(): Retrieving verification tag failed in %s on line %d
  51. bool(false)
  52. Warning: openssl_encrypt(): A tag should be provided when using AEAD mode in %s on line %d
  53. bool(false)