forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
crc32: make CRC_*_BITS definition correspond to actual bit counts
crc32.c provides a choice of one of several algorithms for computing the LSB and LSB versions of the CRC32 checksum based on the parameters CRC_LE_BITS and CRC_BE_BITS. In the original version the values 1, 2, 4 and 8 respectively selected versions of the alrogithm that computed the crc 1, 2, 4 and 32 bits as a time. This patch series adds a new version that computes the CRC 64 bits at a time. To make things easier to understand the parameter has been reinterpreted to actually stand for the number of bits processed in each step of the algorithm so that the old value 8 has been replaced with the value 32. This also allows us to add in a widely used crc algorithm that computes the crc 8 bits at a time called the Sarwate algorithm. [[email protected]: Minor changelog tweaks] Signed-off-by: Bob Pearson <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
- Loading branch information
Showing
3 changed files
with
34 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,13 +27,13 @@ | |
#include <linux/types.h> | ||
#include "crc32defs.h" | ||
|
||
#if CRC_LE_BITS == 8 | ||
#if CRC_LE_BITS > 8 | ||
# define tole(x) ((__force u32) __constant_cpu_to_le32(x)) | ||
#else | ||
# define tole(x) (x) | ||
#endif | ||
|
||
#if CRC_BE_BITS == 8 | ||
#if CRC_BE_BITS > 8 | ||
# define tobe(x) ((__force u32) __constant_cpu_to_be32(x)) | ||
#else | ||
# define tobe(x) (x) | ||
|
@@ -45,7 +45,7 @@ MODULE_AUTHOR("Matt Domsch <[email protected]>"); | |
MODULE_DESCRIPTION("Ethernet CRC32 calculations"); | ||
MODULE_LICENSE("GPL"); | ||
|
||
#if CRC_LE_BITS == 8 || CRC_BE_BITS == 8 | ||
#if CRC_LE_BITS > 8 || CRC_BE_BITS > 8 | ||
|
||
static inline u32 | ||
crc32_body(u32 crc, unsigned char const *buf, size_t len, const u32 (*tab)[256]) | ||
|
@@ -126,6 +126,12 @@ u32 __pure crc32_le(u32 crc, unsigned char const *p, size_t len) | |
crc = (crc >> 4) ^ crc32table_le[0][crc & 15]; | ||
} | ||
# elif CRC_LE_BITS == 8 | ||
/* aka Sarwate algorithm */ | ||
while (len--) { | ||
crc ^= *p++; | ||
crc = (crc >> 8) ^ crc32table_le[0][crc & 255]; | ||
} | ||
# else | ||
const u32 (*tab)[] = crc32table_le; | ||
|
||
crc = (__force u32) __cpu_to_le32(crc); | ||
|
@@ -169,6 +175,11 @@ u32 __pure crc32_be(u32 crc, unsigned char const *p, size_t len) | |
crc = (crc << 4) ^ crc32table_be[0][crc >> 28]; | ||
} | ||
# elif CRC_BE_BITS == 8 | ||
while (len--) { | ||
crc ^= *p++ << 24; | ||
crc = (crc << 8) ^ crc32table_be[0][crc >> 24]; | ||
} | ||
# else | ||
const u32 (*tab)[] = crc32table_be; | ||
|
||
crc = (__force u32) __cpu_to_be32(crc); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters