aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2022-12-30 20:10:08 +0200
committerJia Tan <jiat0218@gmail.com>2023-01-05 00:28:09 +0800
commitab5229d32adfec1f3fbc95228d9dd6f560732ab5 (patch)
tree09f0ff40773b7705b35236bca343a8d90eae1ed2
parentTests: Clarify a comment in test_lzip_decoder.c. (diff)
downloadxz-ab5229d32adfec1f3fbc95228d9dd6f560732ab5.tar.xz
Tests: test_check: Test corner cases of CLMUL CRC64.
-rw-r--r--tests/test_check.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/test_check.c b/tests/test_check.c
index 3c3a6e46..bc52f403 100644
--- a/tests/test_check.c
+++ b/tests/test_check.c
@@ -50,6 +50,22 @@ static uint8_t *sha256_xz_data;
#endif
+#ifdef HAVE_CHECK_CRC64
+static const uint8_t *
+get_random256(uint32_t *seed)
+{
+ static uint8_t buf[256];
+
+ for (size_t i = 0; i < sizeof(buf); ++i) {
+ *seed = *seed * 1103515245 + 12345;
+ buf[i] = (uint8_t)(*seed >> 22);
+ }
+
+ return buf;
+}
+#endif
+
+
static void
test_lzma_crc32(void)
{
@@ -99,6 +115,17 @@ test_lzma_crc64(void)
for (size_t i = 0; i < sizeof(test_string); ++i)
crc = lzma_crc64(test_string + i, 1, crc);
assert_uint_eq(crc, test_vector);
+
+ // Test 4: The CLMUL implementation works on 16-byte chunks.
+ // Test combination of different start and end alignments
+ // and also short buffer lengths where special handling is needed.
+ uint32_t seed = 29;
+ crc = 0x96E30D5184B7FA2C; // Random initial value
+ for (size_t start = 0; start < 32; ++start)
+ for (size_t size = 1; size < 256 - 32; ++size)
+ crc = lzma_crc64(get_random256(&seed), size, crc);
+
+ assert_uint_eq(crc, 0x23AB787177231C9F);
#endif
}