2 * T10 Data Integrity Field CRC16 calculation
4 * Copyright (c) 2007 Oracle Corporation. All rights reserved.
5 * Written by Martin K. Petersen <martin.petersen@oracle.com>
7 * This source code is licensed under the GNU General Public License,
8 * Version 2. See the file COPYING for more details.
11 #include <linux/types.h>
12 #include <linux/module.h>
13 #include <linux/crc-t10dif.h>
14 #include <linux/err.h>
15 #include <linux/init.h>
16 #include <crypto/hash.h>
18 static struct crypto_shash *crct10dif_tfm;
20 __u16 crc_t10dif(const unsigned char *buffer, size_t len)
23 struct shash_desc shash;
28 desc.shash.tfm = crct10dif_tfm;
30 *(__u16 *)desc.ctx = 0;
32 err = crypto_shash_update(&desc.shash, buffer, len);
35 return *(__u16 *)desc.ctx;
37 EXPORT_SYMBOL(crc_t10dif);
39 static int __init crc_t10dif_mod_init(void)
41 crct10dif_tfm = crypto_alloc_shash("crct10dif", 0, 0);
42 return PTR_RET(crct10dif_tfm);
45 static void __exit crc_t10dif_mod_fini(void)
47 crypto_free_shash(crct10dif_tfm);
50 module_init(crc_t10dif_mod_init);
51 module_exit(crc_t10dif_mod_fini);
53 MODULE_DESCRIPTION("T10 DIF CRC calculation");
54 MODULE_LICENSE("GPL");
55 MODULE_SOFTDEP("pre: crct10dif");