com php-src: Add an initial openssl encrypt GCM test: ext/openssl/tests/cipher_tests.inc ext/openssl/tests/open ssl_encrypt_gcm.phpt

From: Date: Mon, 28 Dec 2015 19:16:05 +0000
Subject: com php-src: Add an initial openssl encrypt GCM test: ext/openssl/tests/cipher_tests.inc ext/openssl/tests/open ssl_encrypt_gcm.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-92481@lists.php.net to get a copy of this message
Commit: a00d1eccc72ab116b30ffbab52f8fab86f27a851 Author: Jakub Zelenka <bukka@php.net> Mon, 28 Dec 2015 19:16:05 +0000 Parents: 5e9540f77dc5fba67ee69e5a38b79ced28f42368 Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=a00d1eccc72ab116b30ffbab52f8fab86f27a851 Log: Add an initial openssl encrypt GCM test Changed paths: A ext/openssl/tests/cipher_tests.inc A ext/openssl/tests/openssl_encrypt_gcm.phpt Diff: diff --git a/ext/openssl/tests/cipher_tests.inc b/ext/openssl/tests/cipher_tests.inc new file mode 100644 index 0000000..41240a5 --- /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 0000000..e1309f3 --- /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)

« previous php.cvs (#92481) next »