Linux Audio

Check our new training course

Loading...
v3.15
 
 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 */
33
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>
 
39
40static struct crypto_shash *tfm;
41
42u32 crc32c(u32 crc, const void *address, unsigned int length)
43{
44	struct {
45		struct shash_desc shash;
46		char ctx[crypto_shash_descsize(tfm)];
47	} desc;
48	int err;
49
50	desc.shash.tfm = tfm;
51	desc.shash.flags = 0;
52	*(u32 *)desc.ctx = crc;
53
54	err = crypto_shash_update(&desc.shash, address, length);
55	BUG_ON(err);
56
57	return *(u32 *)desc.ctx;
 
 
58}
59
60EXPORT_SYMBOL(crc32c);
61
62static int __init libcrc32c_mod_init(void)
63{
64	tfm = crypto_alloc_shash("crc32c", 0, 0);
65	if (IS_ERR(tfm))
66		return PTR_ERR(tfm);
67
68	return 0;
69}
70
71static void __exit libcrc32c_mod_fini(void)
72{
73	crypto_free_shash(tfm);
74}
75
76module_init(libcrc32c_mod_init);
77module_exit(libcrc32c_mod_fini);
78
79MODULE_AUTHOR("Clay Haapala <chaapala@cisco.com>");
80MODULE_DESCRIPTION("CRC32c (Castagnoli) calculations");
81MODULE_LICENSE("GPL");
v6.8
 1// SPDX-License-Identifier: GPL-2.0-or-later
 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
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.
 
 
 
 
 
 
27 */
28
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>
34#include <linux/crc32c.h>
35
36static struct crypto_shash *tfm;
37
38u32 crc32c(u32 crc, const void *address, unsigned int length)
39{
40	SHASH_DESC_ON_STACK(shash, tfm);
41	u32 ret, *ctx = (u32 *)shash_desc_ctx(shash);
 
 
42	int err;
43
44	shash->tfm = tfm;
45	*ctx = crc;
 
46
47	err = crypto_shash_update(shash, address, length);
48	BUG_ON(err);
49
50	ret = *ctx;
51	barrier_data(ctx);
52	return ret;
53}
54
55EXPORT_SYMBOL(crc32c);
56
57static int __init libcrc32c_mod_init(void)
58{
59	tfm = crypto_alloc_shash("crc32c", 0, 0);
60	return PTR_ERR_OR_ZERO(tfm);
 
 
 
61}
62
63static void __exit libcrc32c_mod_fini(void)
64{
65	crypto_free_shash(tfm);
66}
67
68module_init(libcrc32c_mod_init);
69module_exit(libcrc32c_mod_fini);
70
71MODULE_AUTHOR("Clay Haapala <chaapala@cisco.com>");
72MODULE_DESCRIPTION("CRC32c (Castagnoli) calculations");
73MODULE_LICENSE("GPL");
74MODULE_SOFTDEP("pre: crc32c");