Lines Matching full:crc
3 * Unit tests and benchmarks for the CRC library functions
12 #include <linux/crc-t10dif.h>
28 * struct crc_variant - describes a CRC variant
29 * @bits: Number of bits in the CRC, 1 <= @bits <= 64.
30 * @le: true if it's a "little endian" CRC (reversed mapping between bits and
31 * polynomial coefficients in each byte), false if it's a "big endian" CRC
35 * @func: The function to compute a CRC. The type signature uses u64 so that it
36 * can fit any CRC up to CRC-64. The CRC is passed in, and is expected
38 * function is expected to *not* invert the CRC at the beginning and end.
45 u64 (*func)(u64 crc, const u8 *p, size_t len);
66 /* Reference implementation of any CRC variant */
68 u64 crc, const u8 *p, size_t len) in crc_ref()
75 crc ^= (p[i] >> j) & 1; in crc_ref()
76 crc = (crc >> 1) ^ ((crc & 1) ? v->poly : 0); in crc_ref()
78 crc ^= (u64)((p[i] >> (7 - j)) & 1) << in crc_ref()
80 if (crc & (1ULL << (v->bits - 1))) in crc_ref()
81 crc = ((crc << 1) ^ v->poly) & in crc_ref()
84 crc <<= 1; in crc_ref()
88 return crc; in crc_ref()
114 /* Generate a random initial CRC. */
176 * Compute the CRC, and verify that it equals the CRC computed in crc_main_test()
191 /* Test that CRC(concat(A, B)) == combine_CRCs(CRC(A), CRC(B), len(B)). */
208 "CRC combination gave wrong result with len1=%zu len2=%zu\n", in crc_combine_test()
222 u64 (*crc_func)(u64 crc, const u8 *p, size_t len)) in crc_benchmark() argument
229 * The CRC value that this function computes in a series of calls to in crc_benchmark()
233 volatile u64 crc = 0; in crc_benchmark() local
241 crc = crc_func(crc, test_buffer, CRC_KUNIT_MAX_LEN); in crc_benchmark()
250 crc = crc_func(crc, test_buffer, len); in crc_benchmark()
260 static u64 crc7_be_wrapper(u64 crc, const u8 *p, size_t len) in crc7_be_wrapper() argument
263 * crc7_be() left-aligns the 7-bit CRC in a u8, whereas the test wants a in crc7_be_wrapper()
264 * right-aligned CRC (in a u64). Convert between the conventions. in crc7_be_wrapper()
266 return crc7_be(crc << 1, p, len) >> 1; in crc7_be_wrapper()
287 static u64 crc16_wrapper(u64 crc, const u8 *p, size_t len) in crc16_wrapper() argument
289 return crc16(crc, p, len); in crc16_wrapper()
311 static u64 crc_t10dif_wrapper(u64 crc, const u8 *p, size_t len) in crc_t10dif_wrapper() argument
313 return crc_t10dif_update(crc, p, len); in crc_t10dif_wrapper()
335 static u64 crc32_le_wrapper(u64 crc, const u8 *p, size_t len) in crc32_le_wrapper() argument
337 return crc32_le(crc, p, len); in crc32_le_wrapper()
365 static u64 crc32_be_wrapper(u64 crc, const u8 *p, size_t len) in crc32_be_wrapper() argument
367 return crc32_be(crc, p, len); in crc32_be_wrapper()
389 static u64 crc32c_wrapper(u64 crc, const u8 *p, size_t len) in crc32c_wrapper() argument
391 return crc32c(crc, p, len); in crc32c_wrapper()
419 static u64 crc64_be_wrapper(u64 crc, const u8 *p, size_t len) in crc64_be_wrapper() argument
421 return crc64_be(crc, p, len); in crc64_be_wrapper()
443 static u64 crc64_nvme_wrapper(u64 crc, const u8 *p, size_t len) in crc64_nvme_wrapper() argument
446 return ~crc64_nvme(~crc, p, len); in crc64_nvme_wrapper()
487 .name = "crc",
494 MODULE_DESCRIPTION("Unit tests and benchmarks for the CRC library functions");