xxhash_secret.phpt 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. --TEST--
  2. Hash: xxHash secret
  3. --FILE--
  4. <?php
  5. foreach (["xxh3", "xxh128"] as $a) {
  6. //$secret = random_bytes(256);
  7. $secret = str_repeat('a', 256);
  8. try {
  9. $ctx = hash_init($a, options: ["seed" => 24, "secret" => $secret]);
  10. } catch (Throwable $e) {
  11. var_dump($e->getMessage());
  12. }
  13. try {
  14. $ctx = hash_init($a, options: ["secret" => str_repeat('a', 17)]);
  15. } catch (Throwable $e) {
  16. var_dump($e->getMessage());
  17. }
  18. $ctx = hash_init($a, options: ["secret" => $secret]);
  19. hash_update($ctx, "Lorem");
  20. hash_update($ctx, " ipsum dolor");
  21. hash_update($ctx, " sit amet,");
  22. hash_update($ctx, " consectetur adipiscing elit.");
  23. $h0 = hash_final($ctx);
  24. $h1 = hash($a, "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", options: ["secret" => $secret]);
  25. echo $h0 , " == ", $h1, " == ", (($h0 == $h1) ? "true" : "false"), "\n";
  26. }
  27. ?>
  28. --EXPECT--
  29. string(67) "xxh3: Only one of seed or secret is to be passed for initialization"
  30. string(57) "xxh3: Secret length must be >= 136 bytes, 17 bytes passed"
  31. 8028aa834c03557a == 8028aa834c03557a == true
  32. string(69) "xxh128: Only one of seed or secret is to be passed for initialization"
  33. string(59) "xxh128: Secret length must be >= 136 bytes, 17 bytes passed"
  34. 54279097795e7218093a05d4d781cbb9 == 54279097795e7218093a05d4d781cbb9 == true