// SPDX-License-Identifier: GPL-2.0-only1/*2* Aug 8, 2011 Bob Pearson with help from Joakim Tjernlund and George Spelvin3* cleaned up code to current version of sparse and added the slicing-by-84* algorithm to the closely similar existing slicing-by-4 algorithm.5*6* Oct 15, 2000 Matt Domsch <[email protected]>7* Nicer crc32 functions/docs submitted by [email protected]. Thanks!8* Code was from the public domain, copyright abandoned. Code was9* subsequently included in the kernel, thus was re-licensed under the10* GNU GPL v2.11*12* Oct 12, 2000 Matt Domsch <[email protected]>13* Same crc32 function was used in 5 other places in the kernel.14* I made one version, and deleted the others.15* There are various incantations of crc32(). Some use a seed of 0 or ~0.16* Some xor at the end with ~0. The generic crc32() function takes17* seed as an argument, and doesn't xor at the end. Then individual18* users can do whatever they need.19* drivers/net/smc9194.c uses seed ~0, doesn't xor with ~0.20* fs/jffs2 uses seed 0, doesn't xor with ~0.21* fs/partitions/efi.c uses seed ~0, xor's with ~0.22*/2324/* see: Documentation/staging/crc32.rst for a description of algorithms */2526#include <linux/crc32.h>27#include <linux/export.h>28#include <linux/module.h>29#include <linux/types.h>3031#include "crc32table.h"3233static inline u32 __maybe_unused34crc32_le_base(u32 crc, const u8 *p, size_t len)35{36while (len--)37crc = (crc >> 8) ^ crc32table_le[(crc & 255) ^ *p++];38return crc;39}4041static inline u32 __maybe_unused42crc32_be_base(u32 crc, const u8 *p, size_t len)43{44while (len--)45crc = (crc << 8) ^ crc32table_be[(crc >> 24) ^ *p++];46return crc;47}4849static inline u32 __maybe_unused50crc32c_base(u32 crc, const u8 *p, size_t len)51{52while (len--)53crc = (crc >> 8) ^ crc32ctable_le[(crc & 255) ^ *p++];54return crc;55}5657#ifdef CONFIG_CRC32_ARCH58#include "crc32.h" /* $(SRCARCH)/crc32.h */5960u32 crc32_optimizations(void)61{62return crc32_optimizations_arch();63}64EXPORT_SYMBOL(crc32_optimizations);65#else66#define crc32_le_arch crc32_le_base67#define crc32_be_arch crc32_be_base68#define crc32c_arch crc32c_base69#endif7071u32 crc32_le(u32 crc, const void *p, size_t len)72{73return crc32_le_arch(crc, p, len);74}75EXPORT_SYMBOL(crc32_le);7677u32 crc32_be(u32 crc, const void *p, size_t len)78{79return crc32_be_arch(crc, p, len);80}81EXPORT_SYMBOL(crc32_be);8283u32 crc32c(u32 crc, const void *p, size_t len)84{85return crc32c_arch(crc, p, len);86}87EXPORT_SYMBOL(crc32c);8889#ifdef crc32_mod_init_arch90static int __init crc32_mod_init(void)91{92crc32_mod_init_arch();93return 0;94}95subsys_initcall(crc32_mod_init);9697static void __exit crc32_mod_exit(void)98{99}100module_exit(crc32_mod_exit);101#endif102103MODULE_DESCRIPTION("CRC32 library functions");104MODULE_LICENSE("GPL");105106107