powerpc/64: reuse PPC32 static inline flush_dcache_range()
[linux-2.6-block.git] / lib / libcrc32c.c
CommitLineData
1da177e4
LT
1/*
2 * CRC32C
3 *@Article{castagnoli-crc,
4 * author = { Guy Castagnoli and Stefan Braeuer and Martin Herrman},
5 * title = {{Optimization of Cyclic Redundancy-Check Codes with 24
6 * and 32 Parity Bits}},
7 * journal = IEEE Transactions on Communication,
8 * year = {1993},
9 * volume = {41},
10 * number = {6},
11 * pages = {},
12 * month = {June},
13 *}
14 * Used by the iSCSI driver, possibly others, and derived from the
15 * the iscsi-crc.c module of the linux-iscsi driver at
16 * http://linux-iscsi.sourceforge.net.
17 *
18 * Following the example of lib/crc32, this function is intended to be
19 * flexible and useful for all users. Modules that currently have their
20 * own crc32c, but hopefully may be able to use this one are:
21 * net/sctp (please add all your doco to here if you change to
22 * use this one!)
23 * <endoflist>
24 *
25 * Copyright (c) 2004 Cisco Systems, Inc.
26 *
27 * This program is free software; you can redistribute it and/or modify it
28 * under the terms of the GNU General Public License as published by the Free
29 * Software Foundation; either version 2 of the License, or (at your option)
30 * any later version.
31 *
32 */
1da177e4 33
69c35efc
HX
34#include <crypto/hash.h>
35#include <linux/err.h>
36#include <linux/init.h>
37#include <linux/kernel.h>
38#include <linux/module.h>
290e0e0f 39#include <linux/crc32c.h>
1da177e4 40
69c35efc 41static struct crypto_shash *tfm;
1da177e4 42
69c35efc 43u32 crc32c(u32 crc, const void *address, unsigned int length)
1da177e4 44{
ea0e0de6 45 SHASH_DESC_ON_STACK(shash, tfm);
d41519a6 46 u32 ret, *ctx = (u32 *)shash_desc_ctx(shash);
69c35efc 47 int err;
1da177e4 48
ea0e0de6 49 shash->tfm = tfm;
ea0e0de6 50 *ctx = crc;
1da177e4 51
ea0e0de6 52 err = crypto_shash_update(shash, address, length);
69c35efc 53 BUG_ON(err);
1da177e4 54
d41519a6
DM
55 ret = *ctx;
56 barrier_data(ctx);
57 return ret;
69c35efc 58}
1da177e4 59
53b146ae
AKR
60EXPORT_SYMBOL(crc32c);
61
69c35efc 62static int __init libcrc32c_mod_init(void)
1da177e4 63{
69c35efc 64 tfm = crypto_alloc_shash("crc32c", 0, 0);
f8eaf298 65 return PTR_ERR_OR_ZERO(tfm);
1da177e4
LT
66}
67
69c35efc 68static void __exit libcrc32c_mod_fini(void)
1da177e4 69{
69c35efc 70 crypto_free_shash(tfm);
1da177e4 71}
1da177e4 72
df91f56a
NB
73const char *crc32c_impl(void)
74{
75 return crypto_shash_driver_name(tfm);
76}
77EXPORT_SYMBOL(crc32c_impl);
78
69c35efc
HX
79module_init(libcrc32c_mod_init);
80module_exit(libcrc32c_mod_fini);
81
82MODULE_AUTHOR("Clay Haapala <chaapala@cisco.com>");
83MODULE_DESCRIPTION("CRC32c (Castagnoli) calculations");
84MODULE_LICENSE("GPL");
fd7f6727 85MODULE_SOFTDEP("pre: crc32c");