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