openssl_decrypt_gcm.phpt 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. --TEST--
  2. openssl_decrypt() 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. $pt = openssl_decrypt($test['ct'], $method, $test['key'], OPENSSL_RAW_DATA,
  18. $test['iv'], $test['tag'], $test['aad']);
  19. var_dump($test['pt'] === $pt);
  20. }
  21. // no IV
  22. var_dump(openssl_decrypt($test['ct'], $method, $test['key'], OPENSSL_RAW_DATA,
  23. '', $test['tag'], $test['aad']));
  24. // failed because no AAD
  25. var_dump(openssl_decrypt($test['ct'], $method, $test['key'], OPENSSL_RAW_DATA,
  26. $test['iv'], $test['tag']));
  27. // failed because wrong tag
  28. var_dump(openssl_decrypt($test['ct'], $method, $test['key'], OPENSSL_RAW_DATA,
  29. $test['iv'], str_repeat('x', 16), $test['aad']));
  30. ?>
  31. --EXPECTF--
  32. TEST 0
  33. bool(true)
  34. TEST 1
  35. bool(true)
  36. TEST 2
  37. bool(true)
  38. TEST 3
  39. bool(true)
  40. TEST 4
  41. bool(true)
  42. TEST 5
  43. bool(true)
  44. Warning: openssl_decrypt(): Setting of IV length for AEAD mode failed in %s on line %d
  45. bool(false)
  46. bool(false)
  47. bool(false)