Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

hash: add CRC-32C (Castagnoli) support

Dirk Petersena7759387d6b0
diff --git a/fs/hash/hash.go b/fs/hash/hash.go
index 8674efae0..d5c5b1ae7 100644
--- a/fs/hash/hash.go
+++ b/fs/hash/hash.go
@@ -102,8 +102,14 @@ var (
// XXH128 indicates XXH128 support, also known as XXH3-128, a variant of xxHash
XXH128 Type
+
+ // CRC32C indicates CRC-32C (Castagnoli) support
+ CRC32C Type
)
+// castagnoliTable is the CRC-32C table (hardware accelerated where available)
+var castagnoliTable = crc32.MakeTable(crc32.Castagnoli)
+
type xxh128Hasher struct {
xxh3.Hasher
}
@@ -129,6 +135,7 @@ func init() {
BLAKE3 = RegisterHash("blake3", "BLAKE3", 64, func() hash.Hash { return blake3.New() })
XXH3 = RegisterHash("xxh3", "XXH3", 16, func() hash.Hash { return xxh3.New() })
XXH128 = RegisterHash("xxh128", "XXH128", 32, func() hash.Hash { return &xxh128Hasher{} })
+ CRC32C = RegisterHash("crc32c", "CRC-32C", 8, func() hash.Hash { return crc32.New(castagnoliTable) })
}
// Supported returns a set of all the supported hashes by
diff --git a/fs/hash/hash_test.go b/fs/hash/hash_test.go
index a5e5f8cb7..b07fc1c87 100644
--- a/fs/hash/hash_test.go
+++ b/fs/hash/hash_test.go
@@ -81,6 +81,7 @@ var hashTestSet = []hashTest{
hash.BLAKE3: "0a7276a407a3be1b4d31488318ee05a335aad5a3b82c4420e592a8178c9e86bb",
hash.XXH3: "4b83b0c51c543525",
hash.XXH128: "438de241a57d684214f67657f7aad93b",
+ hash.CRC32C: "4d8ae017",
},
},
// Empty data set
@@ -96,6 +97,7 @@ var hashTestSet = []hashTest{
hash.BLAKE3: "af1349b9f5f9a1a6a0404dea36dcc9499bcb25c9adc112b7cc9a93cae41f3262",
hash.XXH3: "2d06800538d394c2",
hash.XXH128: "99aa06d3014798d86001c324468d497f",
+ hash.CRC32C: "00000000",
},
},
}