]> granicus.if.org Git - php/commitdiff
hash: xxhash: Use canonicalization routine from existing API
authorAnatol Belski <ab@php.net>
Sat, 13 Mar 2021 20:34:19 +0000 (21:34 +0100)
committerAnatol Belski <ab@php.net>
Sat, 13 Mar 2021 20:38:10 +0000 (21:38 +0100)
Signed-off-by: Anatol Belski <ab@php.net>
ext/hash/hash_xxhash.c

index 9a49c7691acf48ad07f13601bd09b74116be1ff8..15e3c1f9e11b104653f21705291fecfaad5a0e6e 100644 (file)
@@ -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)