php_hash_xxhash.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Copyright (c) The PHP Group |
  4. +----------------------------------------------------------------------+
  5. | This source file is subject to version 3.01 of the PHP license, |
  6. | that is bundled with this package in the file LICENSE, and is |
  7. | available through the world-wide-web at the following url: |
  8. | https://www.php.net/license/3_01.txt |
  9. | If you did not receive a copy of the PHP license and are unable to |
  10. | obtain it through the world-wide-web, please send a note to |
  11. | license@php.net so we can mail you a copy immediately. |
  12. +----------------------------------------------------------------------+
  13. | Author: Anatol Belski <ab@php.net> |
  14. +----------------------------------------------------------------------+
  15. */
  16. #ifndef PHP_HASH_XXHASH_H
  17. #define PHP_HASH_XXHASH_H
  18. #define XXH_INLINE_ALL 1
  19. #include "xxhash.h"
  20. typedef struct {
  21. XXH32_state_t s;
  22. } PHP_XXH32_CTX;
  23. #define PHP_XXH32_SPEC "llllllllllll"
  24. PHP_HASH_API void PHP_XXH32Init(PHP_XXH32_CTX *ctx, HashTable *args);
  25. PHP_HASH_API void PHP_XXH32Update(PHP_XXH32_CTX *ctx, const unsigned char *in, size_t len);
  26. PHP_HASH_API void PHP_XXH32Final(unsigned char digest[4], PHP_XXH32_CTX *ctx);
  27. PHP_HASH_API int PHP_XXH32Copy(const php_hash_ops *ops, PHP_XXH32_CTX *orig_context, PHP_XXH32_CTX *copy_context);
  28. typedef struct {
  29. XXH64_state_t s;
  30. } PHP_XXH64_CTX;
  31. #define PHP_XXH64_SPEC "qqqqqqqqqllq"
  32. PHP_HASH_API void PHP_XXH64Init(PHP_XXH64_CTX *ctx, HashTable *args);
  33. PHP_HASH_API void PHP_XXH64Update(PHP_XXH64_CTX *ctx, const unsigned char *in, size_t len);
  34. PHP_HASH_API void PHP_XXH64Final(unsigned char digest[8], PHP_XXH64_CTX *ctx);
  35. PHP_HASH_API int PHP_XXH64Copy(const php_hash_ops *ops, PHP_XXH64_CTX *orig_context, PHP_XXH64_CTX *copy_context);
  36. #define PHP_XXH3_SECRET_SIZE_MIN XXH3_SECRET_SIZE_MIN
  37. #define PHP_XXH3_SECRET_SIZE_MAX 256
  38. typedef struct {
  39. XXH3_state_t s;
  40. /* The value must survive the whole streaming cycle from init to final.
  41. A more flexible mechanism would be to carry zend_string* passed through
  42. the options. However, that will require to introduce a destructor
  43. handler for ctx, so then it wolud be automatically called from the
  44. object destructor. Until that is given, the viable way is to use a
  45. plausible max secret length. */
  46. const unsigned char secret[PHP_XXH3_SECRET_SIZE_MAX];
  47. } PHP_XXH3_CTX;
  48. typedef PHP_XXH3_CTX PHP_XXH3_64_CTX;
  49. PHP_HASH_API void PHP_XXH3_64_Init(PHP_XXH3_64_CTX *ctx, HashTable *args);
  50. PHP_HASH_API void PHP_XXH3_64_Update(PHP_XXH3_64_CTX *ctx, const unsigned char *in, size_t len);
  51. PHP_HASH_API void PHP_XXH3_64_Final(unsigned char digest[8], PHP_XXH3_64_CTX *ctx);
  52. PHP_HASH_API int PHP_XXH3_64_Copy(const php_hash_ops *ops, PHP_XXH3_64_CTX *orig_context, PHP_XXH3_64_CTX *copy_context);
  53. typedef PHP_XXH3_CTX PHP_XXH3_128_CTX;
  54. PHP_HASH_API void PHP_XXH3_128_Init(PHP_XXH3_128_CTX *ctx, HashTable *args);
  55. PHP_HASH_API void PHP_XXH3_128_Update(PHP_XXH3_128_CTX *ctx, const unsigned char *in, size_t len);
  56. PHP_HASH_API void PHP_XXH3_128_Final(unsigned char digest[16], PHP_XXH3_128_CTX *ctx);
  57. PHP_HASH_API int PHP_XXH3_128_Copy(const php_hash_ops *ops, PHP_XXH3_128_CTX *orig_context, PHP_XXH3_128_CTX *copy_context);
  58. #endif /* PHP_HASH_XXHASH_H */