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 17 #ifndef PHP_HASH_XXHASH_H 18 #define PHP_HASH_XXHASH_H 19 20 #define XXH_INLINE_ALL 1 21 #include "xxhash.h" 22 23 typedef struct { 24 XXH32_state_t s; 25 } PHP_XXH32_CTX; 26 #define PHP_XXH32_SPEC "llllllllllll" 27 28 PHP_HASH_API void PHP_XXH32Init(PHP_XXH32_CTX *ctx, HashTable *args); 29 PHP_HASH_API void PHP_XXH32Update(PHP_XXH32_CTX *ctx, const unsigned char *in, size_t len); 30 PHP_HASH_API void PHP_XXH32Final(unsigned char digest[4], PHP_XXH32_CTX *ctx); 31 PHP_HASH_API int PHP_XXH32Copy(const php_hash_ops *ops, PHP_XXH32_CTX *orig_context, PHP_XXH32_CTX *copy_context); 32 33 typedef struct { 34 XXH64_state_t s; 35 } PHP_XXH64_CTX; 36 #define PHP_XXH64_SPEC "qqqqqqqqqllq" 37 38 PHP_HASH_API void PHP_XXH64Init(PHP_XXH64_CTX *ctx, HashTable *args); 39 PHP_HASH_API void PHP_XXH64Update(PHP_XXH64_CTX *ctx, const unsigned char *in, size_t len); 40 PHP_HASH_API void PHP_XXH64Final(unsigned char digest[8], PHP_XXH64_CTX *ctx); 41 PHP_HASH_API int PHP_XXH64Copy(const php_hash_ops *ops, PHP_XXH64_CTX *orig_context, PHP_XXH64_CTX *copy_context); 42 43 #define PHP_XXH3_SECRET_SIZE_MIN XXH3_SECRET_SIZE_MIN 44 #define PHP_XXH3_SECRET_SIZE_MAX 256 45 46 typedef struct { 47 XXH3_state_t s; 48 /* The value must survive the whole streaming cycle from init to final. 49 50 A more flexible mechanism would be to carry zend_string* passed through 51 the options. However, that will require to introduce a destructor 52 handler for ctx, so then it wolud be automatically called from the 53 object destructor. Until that is given, the viable way is to use a 54 plausible max secret length. */ 55 const unsigned char secret[PHP_XXH3_SECRET_SIZE_MAX]; 56 } PHP_XXH3_CTX; 57 58 typedef PHP_XXH3_CTX PHP_XXH3_64_CTX; 59 60 PHP_HASH_API void PHP_XXH3_64_Init(PHP_XXH3_64_CTX *ctx, HashTable *args); 61 PHP_HASH_API void PHP_XXH3_64_Update(PHP_XXH3_64_CTX *ctx, const unsigned char *in, size_t len); 62 PHP_HASH_API void PHP_XXH3_64_Final(unsigned char digest[8], PHP_XXH3_64_CTX *ctx); 63 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); 64 65 typedef PHP_XXH3_CTX PHP_XXH3_128_CTX; 66 67 PHP_HASH_API void PHP_XXH3_128_Init(PHP_XXH3_128_CTX *ctx, HashTable *args); 68 PHP_HASH_API void PHP_XXH3_128_Update(PHP_XXH3_128_CTX *ctx, const unsigned char *in, size_t len); 69 PHP_HASH_API void PHP_XXH3_128_Final(unsigned char digest[16], PHP_XXH3_128_CTX *ctx); 70 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); 71 72 #endif /* PHP_HASH_XXHASH_H */ 73 74