diff options
| author | Marcel Moolenaar <marcel@FreeBSD.org> | 2005-04-27 22:26:45 +0000 |
|---|---|---|
| committer | Marcel Moolenaar <marcel@FreeBSD.org> | 2005-04-27 22:26:45 +0000 |
| commit | ee6bcf12231c47cec8bdc8df9b9e5fd41e7aa37c (patch) | |
| tree | 561ffb753666f41dfb80e6d9182262888ede6ec8 /sys/libkern | |
| parent | ca83142fc338b492b2e63534cfc55c50a677c2d7 (diff) | |
Notes
Diffstat (limited to 'sys/libkern')
| -rw-r--r-- | sys/libkern/crc32.c | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/sys/libkern/crc32.c b/sys/libkern/crc32.c index a6a162b718bf..4c937d29a568 100644 --- a/sys/libkern/crc32.c +++ b/sys/libkern/crc32.c @@ -94,18 +94,21 @@ uint32_t crc32_tab[] = { 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d }; -uint32_t -crc32(const void *buf, size_t size) -{ - const uint8_t *p; - uint32_t crc; - - p = buf; - crc = ~0U; - - while (size--) - crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8); - - return crc ^ ~0U; -} - +/* + * A function that calculates the CRC-32 based on the table above is + * given below for documentation purposes. An equivalent implementation + * of this function that's actually used in the kernel can be found + * in sys/systm.h, where it can be inlined. + * + * uint32_t + * crc32(const void *buf, size_t size) + * { + * const uint8_t *p = buf; + * uint32_t crc; + * + * crc = ~0U; + * while (size--) + * crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8); + * return crc ^ ~0U; + * } + */ |
