From 20d4a472800cbc9338f0c6c9c3dfce8eb13663c7 Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Sat, 25 Apr 2026 22:46:05 +0200 Subject: lib: Add CRC-64/NVMe checksum Add CRC-64/NVMe implementation with compile-time hardware backend selection: x86 PCLMUL+SSE4.1 fold-by-16 (HAVE_PCLMUL) aarch64 PMULL fold-by-16 when (HAVE_PMULL) and a byte-table fallback. It's added as HASH_CRC64 to enum hash_algo (in the internal-use-only section after HASH_MD5). Both mem_hash() and hash_len() early-return for HASH_CRC64 because libgcrypt has no CRC-64/NVMe. Signed-off-by: Dimitri Staessens Signed-off-by: Sander Vrijders --- src/lib/hash.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/lib/hash.c') diff --git a/src/lib/hash.c b/src/lib/hash.c index 7adee968..f32001d9 100644 --- a/src/lib/hash.c +++ b/src/lib/hash.c @@ -39,6 +39,7 @@ #include #include #endif +#include #include #include #include @@ -69,6 +70,8 @@ int hash_len_tbl [] = { uint16_t hash_len(enum hash_algo algo) { + if (algo == HASH_CRC64) + return CRC64_HASH_LEN; #ifdef HAVE_LIBGCRYPT return (uint16_t) gcry_md_get_algo_dlen(gcry_algo_tbl[algo]); #else @@ -81,6 +84,13 @@ void mem_hash(enum hash_algo algo, const uint8_t * buf, size_t len) { + if (algo == HASH_CRC64) { + uint64_t crc = 0; + + crc64_nvme(&crc, buf, len); + *(uint64_t *) dst = htobe64(crc); + return; + } #ifdef HAVE_LIBGCRYPT gcry_md_hash_buffer(gcry_algo_tbl[algo], dst, buf, len); #else -- cgit v1.2.3