0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #include <crypto/hash.h>
0030 #include <linux/err.h>
0031 #include <linux/init.h>
0032 #include <linux/kernel.h>
0033 #include <linux/module.h>
0034 #include <linux/crc32c.h>
0035
0036 static struct crypto_shash *tfm;
0037
0038 u32 crc32c(u32 crc, const void *address, unsigned int length)
0039 {
0040 SHASH_DESC_ON_STACK(shash, tfm);
0041 u32 ret, *ctx = (u32 *)shash_desc_ctx(shash);
0042 int err;
0043
0044 shash->tfm = tfm;
0045 *ctx = crc;
0046
0047 err = crypto_shash_update(shash, address, length);
0048 BUG_ON(err);
0049
0050 ret = *ctx;
0051 barrier_data(ctx);
0052 return ret;
0053 }
0054
0055 EXPORT_SYMBOL(crc32c);
0056
0057 static int __init libcrc32c_mod_init(void)
0058 {
0059 tfm = crypto_alloc_shash("crc32c", 0, 0);
0060 return PTR_ERR_OR_ZERO(tfm);
0061 }
0062
0063 static void __exit libcrc32c_mod_fini(void)
0064 {
0065 crypto_free_shash(tfm);
0066 }
0067
0068 const char *crc32c_impl(void)
0069 {
0070 return crypto_shash_driver_name(tfm);
0071 }
0072 EXPORT_SYMBOL(crc32c_impl);
0073
0074 module_init(libcrc32c_mod_init);
0075 module_exit(libcrc32c_mod_fini);
0076
0077 MODULE_AUTHOR("Clay Haapala <chaapala@cisco.com>");
0078 MODULE_DESCRIPTION("CRC32c (Castagnoli) calculations");
0079 MODULE_LICENSE("GPL");
0080 MODULE_SOFTDEP("pre: crc32c");