28 #include <linux/module.h>
29 #include <linux/string.h>
30 #include <linux/kernel.h>
33 #include <asm/cpufeature.h>
36 #define CHKSUM_BLOCK_SIZE 1
37 #define CHKSUM_DIGEST_SIZE 4
39 #define SCALE_F sizeof(unsigned long)
42 #define REX_PRE "0x48, "
51 ".byte 0xf2, 0xf, 0x38, 0xf0, 0xf1"
61 static u32 __pure crc32c_intel_le_hw(
u32 crc,
unsigned char const *
p,
size_t len)
63 unsigned int iquotient = len /
SCALE_F;
64 unsigned int iremainder = len %
SCALE_F;
65 unsigned long *ptmp = (
unsigned long *)p;
69 ".byte 0xf2, " REX_PRE "0xf, 0x38, 0xf1, 0xf1;"
77 crc = crc32c_intel_le_hw_byte(crc, (
unsigned char *)ptmp,
91 u32 *mctx = crypto_shash_ctx(hash);
93 if (keylen !=
sizeof(
u32)) {
103 u32 *mctx = crypto_shash_ctx(desc->
tfm);
104 u32 *crcp = shash_desc_ctx(desc);
114 u32 *crcp = shash_desc_ctx(desc);
116 *crcp = crc32c_intel_le_hw(*crcp, data, len);
120 static int __crc32c_intel_finup(
u32 *crcp,
const u8 *
data,
unsigned int len,
128 unsigned int len,
u8 *out)
130 return __crc32c_intel_finup(shash_desc_ctx(desc), data, len, out);
133 static int crc32c_intel_final(
struct shash_desc *desc,
u8 *out)
135 u32 *crcp = shash_desc_ctx(desc);
141 static int crc32c_intel_digest(
struct shash_desc *desc,
const u8 *data,
142 unsigned int len,
u8 *out)
144 return __crc32c_intel_finup(crypto_shash_ctx(desc->
tfm), data, len,
148 static int crc32c_intel_cra_init(
struct crypto_tfm *tfm)
150 u32 *key = crypto_tfm_ctx(tfm);
158 .setkey = crc32c_intel_setkey,
159 .init = crc32c_intel_init,
160 .update = crc32c_intel_update,
161 .final = crc32c_intel_final,
162 .finup = crc32c_intel_finup,
163 .digest = crc32c_intel_digest,
164 .descsize =
sizeof(
u32),
167 .cra_name =
"crc32c",
168 .cra_driver_name =
"crc32c-intel",
171 .cra_ctxsize =
sizeof(
u32),
173 .cra_init = crc32c_intel_cra_init,
177 static const struct x86_cpu_id crc32c_cpu_id[] = {
183 static int __init crc32c_intel_mod_init(
void)
190 static void __exit crc32c_intel_mod_fini(
void)