summaryrefslogtreecommitdiff
path: root/ext/hash/tests/xxhash_secret.phpt
blob: 91e7d929d323d8ee0556cfd67528a0d6b82fe051 (plain)
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
--TEST--
Hash: xxHash secret
--FILE--
<?php

foreach (["xxh3", "xxh128"] as $a) {

	//$secret = random_bytes(256);
	$secret = str_repeat('a', 256);

	try {
		$ctx = hash_init($a, options: ["seed" => 24, "secret" => $secret]);
	} catch (Throwable $e) {
		var_dump($e->getMessage());
	}

	try {
		$ctx = hash_init($a, options: ["secret" => str_repeat('a', 17)]);
	} catch (Throwable $e) {
		var_dump($e->getMessage());
	}

	$ctx = hash_init($a, options: ["secret" => $secret]);
	hash_update($ctx, "Lorem");
	hash_update($ctx, " ipsum dolor");
	hash_update($ctx, " sit amet,");
	hash_update($ctx, " consectetur adipiscing elit.");
	$h0 = hash_final($ctx);

	$h1 = hash($a, "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", options: ["secret" => $secret]);
	echo $h0 , " == ", $h1, " == ", (($h0 == $h1) ? "true" : "false"), "\n";

}

?>
--EXPECT--
string(67) "xxh3: Only one of seed or secret is to be passed for initialization"
string(57) "xxh3: Secret length must be >= 136 bytes, 17 bytes passed"
8028aa834c03557a == 8028aa834c03557a == true
string(69) "xxh128: Only one of seed or secret is to be passed for initialization"
string(59) "xxh128: Secret length must be >= 136 bytes, 17 bytes passed"
54279097795e7218093a05d4d781cbb9 == 54279097795e7218093a05d4d781cbb9 == true