hash: add CRC-32C (Castagnoli) support
Add the hash type crc32c. It is the checksum that AWS S3 stores for
objects uploaded with x-amz-checksum-crc32c (FULL_OBJECT checksum),
and the checksum that iSCSI, ext4 and Btrfs use. Go calculates it with
the SSE 4.2 and ARMv8 CRC32 instructions where they are available.
With it, rclone can calculate the value that S3 returns in
ChecksumCRC32C for a local file:
rclone hashsum crc32c file
prints it as hex; `--base64` prints it in the URL-safe base64 alphabet
that rclone uses for every hash (`-` and `_` where S3 prints `+` and
`/`).
The new type is registered after the existing core types, so their
Type values do not change. The types that backends register (dropbox,
hidrive, mailru, quickxor) move up one bit, as they did when blake3,
xxh3 and xxh128 were added; no Type value is persisted (the hasher
cache and bisync listings store hash names).
This commit is contained in:
1 parent
1d11d94927
commit
a7759387d6
2 files changed
+9
No files matched your search
@@ -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
|
||||
|
||||
@@ -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",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user