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