diff options
| author | Anatol Belski <ab@php.net> | 2021-03-13 21:34:19 +0100 |
|---|---|---|
| committer | Anatol Belski <ab@php.net> | 2021-03-13 21:38:10 +0100 |
| commit | 8ff6dbb57cacf6a8e89a1be7bfd373207fbe03be (patch) | |
| tree | af02499d5fa8c907b49304b5be7ae6d43ac43cd5 | |
| parent | d5a15d2c919d2ba8f2e81afc0b77f0455d140fbe (diff) | |
| download | php-git-8ff6dbb57cacf6a8e89a1be7bfd373207fbe03be.tar.gz | |
hash: xxhash: Use canonicalization routine from existing API
Signed-off-by: Anatol Belski <ab@php.net>
| -rw-r--r-- | ext/hash/hash_xxhash.c | 48 |
1 files changed, 4 insertions, 44 deletions
diff --git a/ext/hash/hash_xxhash.c b/ext/hash/hash_xxhash.c index 9a49c7691a..15e3c1f9e1 100644 --- a/ext/hash/hash_xxhash.c +++ b/ext/hash/hash_xxhash.c @@ -63,12 +63,7 @@ PHP_HASH_API void PHP_XXH32Update(PHP_XXH32_CTX *ctx, const unsigned char *in, s PHP_HASH_API void PHP_XXH32Final(unsigned char digest[4], PHP_XXH32_CTX *ctx) { - XXH32_hash_t const h = XXH32_digest(&ctx->s); - - digest[0] = (unsigned char)((h >> 24) & 0xff); - digest[1] = (unsigned char)((h >> 16) & 0xff); - digest[2] = (unsigned char)((h >> 8) & 0xff); - digest[3] = (unsigned char)(h & 0xff); + XXH32_canonicalFromHash((XXH32_canonical_t*)digest, XXH32_digest(&ctx->s)); } PHP_HASH_API int PHP_XXH32Copy(const php_hash_ops *ops, PHP_XXH32_CTX *orig_context, PHP_XXH32_CTX *copy_context) @@ -132,16 +127,7 @@ PHP_HASH_API void PHP_XXH64Update(PHP_XXH64_CTX *ctx, const unsigned char *in, s PHP_HASH_API void PHP_XXH64Final(unsigned char digest[8], PHP_XXH64_CTX *ctx) { - XXH64_hash_t const h = XXH64_digest(&ctx->s); - - digest[0] = (unsigned char)((h >> 56) & 0xff); - digest[1] = (unsigned char)((h >> 48) & 0xff); - digest[2] = (unsigned char)((h >> 40) & 0xff); - digest[3] = (unsigned char)((h >> 32) & 0xff); - digest[4] = (unsigned char)((h >> 24) & 0xff); - digest[5] = (unsigned char)((h >> 16) & 0xff); - digest[6] = (unsigned char)((h >> 8) & 0xff); - digest[7] = (unsigned char)(h & 0xff); + XXH64_canonicalFromHash((XXH64_canonical_t*)digest, XXH64_digest(&ctx->s)); } PHP_HASH_API int PHP_XXH64Copy(const php_hash_ops *ops, PHP_XXH64_CTX *orig_context, PHP_XXH64_CTX *copy_context) @@ -219,16 +205,7 @@ PHP_HASH_API void PHP_XXH3_64_Update(PHP_XXH3_64_CTX *ctx, const unsigned char * PHP_HASH_API void PHP_XXH3_64_Final(unsigned char digest[8], PHP_XXH3_64_CTX *ctx) { - XXH64_hash_t const h = XXH3_64bits_digest(&ctx->s); - - digest[0] = (unsigned char)((h >> 56) & 0xff); - digest[1] = (unsigned char)((h >> 48) & 0xff); - digest[2] = (unsigned char)((h >> 40) & 0xff); - digest[3] = (unsigned char)((h >> 32) & 0xff); - digest[4] = (unsigned char)((h >> 24) & 0xff); - digest[5] = (unsigned char)((h >> 16) & 0xff); - digest[6] = (unsigned char)((h >> 8) & 0xff); - digest[7] = (unsigned char)(h & 0xff); + XXH64_canonicalFromHash((XXH64_canonical_t*)digest, XXH3_64bits_digest(&ctx->s)); } 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) @@ -278,24 +255,7 @@ PHP_HASH_API void PHP_XXH3_128_Update(PHP_XXH3_128_CTX *ctx, const unsigned char PHP_HASH_API void PHP_XXH3_128_Final(unsigned char digest[16], PHP_XXH3_128_CTX *ctx) { - XXH128_hash_t const h = XXH3_128bits_digest(&ctx->s); - - digest[0] = (unsigned char)((h.high64 >> 56) & 0xff); - digest[1] = (unsigned char)((h.high64 >> 48) & 0xff); - digest[2] = (unsigned char)((h.high64 >> 40) & 0xff); - digest[3] = (unsigned char)((h.high64 >> 32) & 0xff); - digest[4] = (unsigned char)((h.high64 >> 24) & 0xff); - digest[5] = (unsigned char)((h.high64 >> 16) & 0xff); - digest[6] = (unsigned char)((h.high64 >> 8) & 0xff); - digest[7] = (unsigned char)(h.high64 & 0xff); - digest[8] = (unsigned char)((h.low64 >> 56) & 0xff); - digest[9] = (unsigned char)((h.low64 >> 48) & 0xff); - digest[10] = (unsigned char)((h.low64 >> 40) & 0xff); - digest[11] = (unsigned char)((h.low64 >> 32) & 0xff); - digest[12] = (unsigned char)((h.low64 >> 24) & 0xff); - digest[13] = (unsigned char)((h.low64 >> 16) & 0xff); - digest[14] = (unsigned char)((h.low64 >> 8) & 0xff); - digest[15] = (unsigned char)(h.low64 & 0xff); + XXH128_canonicalFromHash((XXH128_canonical_t*)digest, XXH3_128bits_digest(&ctx->s)); } 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) |
