summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/openssl/tests/cipher_tests.inc32
-rw-r--r--ext/openssl/tests/openssl_encrypt_gcm.phpt28
2 files changed, 60 insertions, 0 deletions
diff --git a/ext/openssl/tests/cipher_tests.inc b/ext/openssl/tests/cipher_tests.inc
new file mode 100644
index 0000000000..41240a594c
--- /dev/null
+++ b/ext/openssl/tests/cipher_tests.inc
@@ -0,0 +1,32 @@
+<?php
+$php_openssl_cipher_tests = array(
+ 'aes-128-gcm' => array(
+ array(
+ 'key' => '00000000000000000000000000000000',
+ 'iv' => '000000000000000000000000',
+ 'tag' => 'ab6e47d42cec13bdf53a67b21257bddf',
+ 'pt' => '00000000000000000000000000000000',
+ 'ct' => '0388dace60b6a392f328c2b971b2fe78',
+ ),
+ )
+);
+
+function openssl_get_cipher_tests($method)
+{
+ global $php_openssl_cipher_tests;
+
+ $tests = array();
+
+ foreach ($php_openssl_cipher_tests[$method] as $instance) {
+ $test = array();
+ foreach ($instance as $field_name => $field_value) {
+ $test[$field_name] = pack("H*", $field_value);
+ }
+ if (!isset($test['aad'])) {
+ $test['aad'] = "";
+ }
+ $tests[] = $test;
+ }
+
+ return $tests;
+}
diff --git a/ext/openssl/tests/openssl_encrypt_gcm.phpt b/ext/openssl/tests/openssl_encrypt_gcm.phpt
new file mode 100644
index 0000000000..e1309f3a79
--- /dev/null
+++ b/ext/openssl/tests/openssl_encrypt_gcm.phpt
@@ -0,0 +1,28 @@
+--TEST--
+openssl_encrypt() with GCM cipher algorithm tests
+--SKIPIF--
+<?php
+if (!extension_loaded("openssl"))
+ die("skip");
+if (!in_array('aes-128-gcm', openssl_get_cipher_methods()))
+ die("skip: aes-128-gcm not available");
+?>
+--FILE--
+<?php
+require_once __DIR__ . "/cipher_tests.inc";
+$method = 'aes-128-gcm';
+$tests = openssl_get_cipher_tests($method);
+
+foreach ($tests as $idx => $test) {
+ echo "TEST $idx\n";
+ $ct = openssl_encrypt($test['pt'], $method, $test['key'], OPENSSL_RAW_DATA,
+ $test['iv'], $tag, $test['aad'], strlen($test['tag']));
+ var_dump($test['ct'] === $ct);
+ var_dump($test['tag'] === $tag);
+}
+
+?>
+--EXPECT--
+TEST 0
+bool(true)
+bool(true)