From c58cc09cf50a18058efb59e1b4fb73ab1e3a45a2 Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Mon, 19 Feb 2024 16:05:59 +0100 Subject: lib: Fix CRC32 hashing I assumed that all hashes were stored in Big Endian, but apparently the CRC32 was still in machine endianness when calculated by the rhash implementation. Fixed and updated hash tests a bit. Signed-off-by: Dimitri Staessens Signed-off-by: Sander Vrijders --- src/lib/hash.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/lib/hash.c') diff --git a/src/lib/hash.c b/src/lib/hash.c index 995ba0d2..b465f894 100644 --- a/src/lib/hash.c +++ b/src/lib/hash.c @@ -29,6 +29,7 @@ #include "config.h" +#include #include #ifdef HAVE_LIBGCRYPT @@ -90,6 +91,7 @@ void mem_hash(enum hash_algo algo, case HASH_CRC32: memset(dst, 0, CRC32_HASH_LEN); crc32((uint32_t *) dst, buf, len); + *(uint32_t *) dst = htobe32(*(uint32_t *) dst); break; case HASH_MD5: rhash_md5_init(&md5_ctx); -- cgit v1.2.3