1--TEST--
2Check for libsodium secretstream
3--SKIPIF--
4<?php
5if (!extension_loaded("sodium")) print "skip extension not loaded";
6if (!defined('SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_ABYTES')) print "skip libsodium without secretbytes";
7?>
8--FILE--
9<?php
10echo "secretstream_xchacha20poly1305:\n";
11
12$msg1 = random_bytes(random_int(1, 1000));
13$msg2 = random_bytes(random_int(1, 1000));
14$key = sodium_crypto_secretstream_xchacha20poly1305_keygen();
15$ad = random_bytes(random_int(1, 1000));
16
17$res = sodium_crypto_secretstream_xchacha20poly1305_init_push($key);
18$stream = $res[0];
19$header = $res[1];
20
21$c1 = sodium_crypto_secretstream_xchacha20poly1305_push($stream, $msg1, $ad);
22$c2 = sodium_crypto_secretstream_xchacha20poly1305_push($stream, $msg2, '', SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_TAG_FINAL);
23
24$stream = sodium_crypto_secretstream_xchacha20poly1305_init_pull($header, $key);
25
26$r1 = sodium_crypto_secretstream_xchacha20poly1305_pull($stream, $c1, $ad);
27$r2 = sodium_crypto_secretstream_xchacha20poly1305_pull($stream, $c2);
28
29var_dump($msg1 === $r1[0]);
30var_dump($msg2 === $r2[0]);
31var_dump($r1[1]);
32var_dump($r2[1]);
33
34var_dump(sodium_crypto_secretstream_xchacha20poly1305_pull($stream, $c2));
35var_dump(sodium_crypto_secretstream_xchacha20poly1305_pull($stream, 'x'));
36
37$stream = sodium_crypto_secretstream_xchacha20poly1305_init_pull($header, $key);
38$r1 = sodium_crypto_secretstream_xchacha20poly1305_pull($stream, $c1);
39var_dump($r1);
40$r1 = sodium_crypto_secretstream_xchacha20poly1305_pull($stream, $c1, $ad);
41var_dump($msg1 === $r1[0]);
42
43$stream = sodium_crypto_secretstream_xchacha20poly1305_init_pull($header, $key);
44sodium_crypto_secretstream_xchacha20poly1305_rekey($stream);
45$r1 = sodium_crypto_secretstream_xchacha20poly1305_pull($stream, $c1, $ad);
46var_dump($r1);
47$r2 = sodium_crypto_secretstream_xchacha20poly1305_pull($stream, $c2);
48var_dump($r2);
49?>
50--EXPECT--
51secretstream_xchacha20poly1305:
52bool(true)
53bool(true)
54int(0)
55int(3)
56bool(false)
57bool(false)
58bool(false)
59bool(true)
60bool(false)
61bool(false)
62