This source file includes following definitions.
- crc32c
- libcrc32c_mod_init
- libcrc32c_mod_fini
- crc32c_impl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 #include <crypto/hash.h>
30 #include <linux/err.h>
31 #include <linux/init.h>
32 #include <linux/kernel.h>
33 #include <linux/module.h>
34 #include <linux/crc32c.h>
35
36 static struct crypto_shash *tfm;
37
38 u32 crc32c(u32 crc, const void *address, unsigned int length)
39 {
40 SHASH_DESC_ON_STACK(shash, tfm);
41 u32 ret, *ctx = (u32 *)shash_desc_ctx(shash);
42 int err;
43
44 shash->tfm = tfm;
45 *ctx = crc;
46
47 err = crypto_shash_update(shash, address, length);
48 BUG_ON(err);
49
50 ret = *ctx;
51 barrier_data(ctx);
52 return ret;
53 }
54
55 EXPORT_SYMBOL(crc32c);
56
57 static int __init libcrc32c_mod_init(void)
58 {
59 tfm = crypto_alloc_shash("crc32c", 0, 0);
60 return PTR_ERR_OR_ZERO(tfm);
61 }
62
63 static void __exit libcrc32c_mod_fini(void)
64 {
65 crypto_free_shash(tfm);
66 }
67
68 const char *crc32c_impl(void)
69 {
70 return crypto_shash_driver_name(tfm);
71 }
72 EXPORT_SYMBOL(crc32c_impl);
73
74 module_init(libcrc32c_mod_init);
75 module_exit(libcrc32c_mod_fini);
76
77 MODULE_AUTHOR("Clay Haapala <chaapala@cisco.com>");
78 MODULE_DESCRIPTION("CRC32c (Castagnoli) calculations");
79 MODULE_LICENSE("GPL");
80 MODULE_SOFTDEP("pre: crc32c");