Back to home page

LXR

 
 

    


0001 /* 
0002  * CRC32C
0003  *@Article{castagnoli-crc,
0004  * author =       { Guy Castagnoli and Stefan Braeuer and Martin Herrman},
0005  * title =        {{Optimization of Cyclic Redundancy-Check Codes with 24
0006  *                 and 32 Parity Bits}},
0007  * journal =      IEEE Transactions on Communication,
0008  * year =         {1993},
0009  * volume =       {41},
0010  * number =       {6},
0011  * pages =        {},
0012  * month =        {June},
0013  *}
0014  * Used by the iSCSI driver, possibly others, and derived from the
0015  * the iscsi-crc.c module of the linux-iscsi driver at
0016  * http://linux-iscsi.sourceforge.net.
0017  *
0018  * Following the example of lib/crc32, this function is intended to be
0019  * flexible and useful for all users.  Modules that currently have their
0020  * own crc32c, but hopefully may be able to use this one are:
0021  *  net/sctp (please add all your doco to here if you change to
0022  *            use this one!)
0023  *  <endoflist>
0024  *
0025  * Copyright (c) 2004 Cisco Systems, Inc.
0026  * 
0027  * This program is free software; you can redistribute it and/or modify it
0028  * under the terms of the GNU General Public License as published by the Free
0029  * Software Foundation; either version 2 of the License, or (at your option) 
0030  * any later version.
0031  *
0032  */
0033 
0034 #include <crypto/hash.h>
0035 #include <linux/err.h>
0036 #include <linux/init.h>
0037 #include <linux/kernel.h>
0038 #include <linux/module.h>
0039 #include <linux/crc32c.h>
0040 
0041 static struct crypto_shash *tfm;
0042 
0043 u32 crc32c(u32 crc, const void *address, unsigned int length)
0044 {
0045     SHASH_DESC_ON_STACK(shash, tfm);
0046     u32 *ctx = (u32 *)shash_desc_ctx(shash);
0047     int err;
0048 
0049     shash->tfm = tfm;
0050     shash->flags = 0;
0051     *ctx = crc;
0052 
0053     err = crypto_shash_update(shash, address, length);
0054     BUG_ON(err);
0055 
0056     return *ctx;
0057 }
0058 
0059 EXPORT_SYMBOL(crc32c);
0060 
0061 static int __init libcrc32c_mod_init(void)
0062 {
0063     tfm = crypto_alloc_shash("crc32c", 0, 0);
0064     return PTR_ERR_OR_ZERO(tfm);
0065 }
0066 
0067 static void __exit libcrc32c_mod_fini(void)
0068 {
0069     crypto_free_shash(tfm);
0070 }
0071 
0072 module_init(libcrc32c_mod_init);
0073 module_exit(libcrc32c_mod_fini);
0074 
0075 MODULE_AUTHOR("Clay Haapala <chaapala@cisco.com>");
0076 MODULE_DESCRIPTION("CRC32c (Castagnoli) calculations");
0077 MODULE_LICENSE("GPL");
0078 MODULE_SOFTDEP("pre: crc32c");