php-src/ext/hash/tests/xxhash_seed.phpt
Anatol Belski 23590f7c53 hash: Implement xxHash
The implementation bundles the xxHash v0.8.0 release and includes all the variants

- xxh32, 32-bit wide
- xxh64, 64-bit wide
- xxh3, 64-bit wide
- xxh128, 128-bit wide

An initial hash state can be passed through the options arrray. An additional
functionality not targeted in this implementation is the secret support in xxh3
and xxh128. That can be added at a later point.

The serialization for xxh3 and xxh128 should not be implemented, as the
state would contain the secret. Despite the xxHash is a non crypto
algorithm, the secret would be serialized as plain text which would be
insecure.

Closes GH-6524

Signed-off-by: Anatol Belski <ab@php.net>
2021-01-09 19:35:32 +01:00

30 lines
630 B
PHP

--TEST--
Hash: xxHash seed
--FILE--
<?php
foreach (["xxh32", "xxh64", "xxh3", "xxh128"] as $a) {
$ctx = hash_init($a, options: ["seed" => 42]);
hash_update($ctx, "Lorem");
hash_update($ctx, " ipsum dolor");
hash_update($ctx, " sit amet,");
hash_update($ctx, " consectetur adipiscing elit.");
$h0 = hash_final($ctx);
echo $h0, "\n";
$h0 = hash($a, "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", options: ["seed" => 42]);
echo $h0, "\n";
}
?>
--EXPECT--
3d0cc7e5
3d0cc7e5
9c9aa071b5d22a15
9c9aa071b5d22a15
366409913c16b70d
366409913c16b70d
f87856a7589354e92aeca886c71ed7fb
f87856a7589354e92aeca886c71ed7fb