forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrypto_stream.phpt
52 lines (43 loc) · 1.11 KB
/
crypto_stream.phpt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
--TEST--
Check for libsodium stream
--EXTENSIONS--
sodium
--FILE--
<?php
$nonce = random_bytes(SODIUM_CRYPTO_STREAM_NONCEBYTES);
$key = sodium_crypto_stream_keygen();
$len = 100;
$stream = sodium_crypto_stream($len, $nonce, $key);
var_dump(strlen($stream));
$stream2 = sodium_crypto_stream($len, $nonce, $key);
$nonce = random_bytes(SODIUM_CRYPTO_STREAM_NONCEBYTES);
$stream3 = sodium_crypto_stream($len, $nonce, $key);
$key = sodium_crypto_stream_keygen();
$stream4 = sodium_crypto_stream($len, $nonce, $key);
var_dump($stream === $stream2);
var_dump($stream !== $stream3);
var_dump($stream !== $stream4);
var_dump($stream2 !== $stream3);
var_dump($stream2 !== $stream4);
var_dump($stream3 !== $stream4);
$stream5 = sodium_crypto_stream_xor($stream, $nonce, $key);
var_dump($stream5 !== $stream);
$stream6 = sodium_crypto_stream_xor($stream5, $nonce, $key);
var_dump($stream6 === $stream);
try {
sodium_crypto_stream($len, substr($nonce, 1), $key);
} catch (SodiumException $ex) {
var_dump(true);
}
?>
--EXPECT--
int(100)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)