1--TEST--
2Stream cipher gcm decryption filter for reading
3--SKIPIF--
4<?php if (!Crypto\Cipher::hasMode(Crypto\Cipher::MODE_GCM)) die("Skip: GCM mode not defined (update OpenSSL version)"); ?>
5--FILE--
6<?php
7$algorithm = 'aes-256-gcm';
8$key = str_repeat('x', 32);
9$iv = str_repeat('i', 16);
10$aad = str_repeat('b', 16);
11$tag = pack("H*", 'f3c2954804f101d3342f6b37ba46ac8e');
12$ciphertext = pack("H*", '622070d3bea6f720943d1198a7e6afa5');
13
14$filename = (dirname( __FILE__) . "/stream_filters_cipher_gcm_dec_read.tmp");
15file_put_contents($filename, $ciphertext);
16
17$context = stream_context_create(array(
18	'crypto' => array(
19		'filters' => array(
20			array(
21				'type' => 'cipher',
22				'action' => 'decrypt',
23				'algorithm' => $algorithm,
24				'key' => $key,
25				'iv'  => $iv,
26				'tag' => $tag,
27				'aad' => $aad,
28			)
29		)
30	),
31));
32
33$stream = fopen("crypto.file://" . $filename, "r", false, $context);
34if (!$stream) {
35	exit;
36}
37while ($data = fread($stream, strlen($ciphertext))) {
38	echo $data . "\n";
39}
40
41$meta_data = stream_get_meta_data($stream);
42echo $meta_data['wrapper_data'][0] . "\n";
43?>
44--CLEAN--
45<?php
46$filename = (dirname( __FILE__) . "/stream_filters_cipher_gcm_dec_read.tmp");
47if (file_exists($filename))
48	unlink($filename);
49?>
50--EXPECT--
51aaaaaaaaaaaaaaaa
52X-PHP-Crypto-Auth-Result: success