diff options
Diffstat (limited to 'ext/hash/tests/xxhash_secret.phpt')
-rw-r--r-- | ext/hash/tests/xxhash_secret.phpt | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/ext/hash/tests/xxhash_secret.phpt b/ext/hash/tests/xxhash_secret.phpt new file mode 100644 index 0000000000..91e7d929d3 --- /dev/null +++ b/ext/hash/tests/xxhash_secret.phpt @@ -0,0 +1,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 |