hash: Add CRC-64 (ISO 3306) and inverse.

This commit is contained in:
Jeroen van Rijn
2021-09-21 16:17:01 +02:00
parent b600ffba3b
commit 181eabcffc
2 changed files with 119 additions and 16 deletions
+13 -3
View File
@@ -261,14 +261,18 @@ test_xxhash_vectors :: proc(t: ^testing.T) {
test_crc64_vectors :: proc(t: ^testing.T) {
fmt.println("Verifying CRC-64:")
vectors := map[string][2]u64 {
vectors := map[string][4]u64 {
"123456789" = {
0x6c40df5f0b497347, // ECMA-182,
0x995dc9bbdf1939fa, // XZ
0x46a5a9388a5beffe, // ISO 3306
0xb90956c775a41001, // ISO 3306, input and output inverted
},
"This is a test of the emergency broadcast system." = {
0x344fe1d09c983d13, // ECMA-182
0x27db187fc15bbc72, // XZ
0x187184d744afc49e, // ISO 3306
0xe7fcf1006b503b61, // ISO 3306, input and output inverted
},
}
@@ -277,11 +281,17 @@ test_crc64_vectors :: proc(t: ^testing.T) {
b := transmute([]u8)vector
ecma := hash.crc64_ecma_182(b)
xz := hash.crc64_xz(b)
iso := hash.crc64_iso_3306(b)
iso2 := hash.crc64_iso_3306_inverse(b)
ecma_error := fmt.tprintf("[CRC-64 ECMA] Expected: %016x. Got: %016x.", ecma, expected[0])
xz_error := fmt.tprintf("[CRC-64 XZ ] Expected: %016x. Got: %016x.", xz, expected[1])
ecma_error := fmt.tprintf("[ CRC-64 ECMA ] Expected: %016x. Got: %016x.", ecma, expected[0])
xz_error := fmt.tprintf("[ CRC-64 XZ ] Expected: %016x. Got: %016x.", xz, expected[1])
iso_error := fmt.tprintf("[ CRC-64 ISO 3306] Expected: %016x. Got: %016x.", iso, expected[2])
iso2_error := fmt.tprintf("[~CRC-64 ISO 3306] Expected: %016x. Got: %016x.", iso2, expected[3])
expect(t, ecma == expected[0], ecma_error)
expect(t, xz == expected[1], xz_error)
expect(t, iso == expected[2], iso_error)
expect(t, iso2 == expected[3], iso2_error)
}
}