gpio: pca953x: refactor pca953x_write_regs()
[linux/fpc-iii.git] / crypto / crct10dif_generic.c
blobc1229614c7e324e5ee9341d6f2be530afd437487
1 /*
2 * Cryptographic API.
4 * T10 Data Integrity Field CRC16 Crypto Transform
6 * Copyright (c) 2007 Oracle Corporation. All rights reserved.
7 * Written by Martin K. Petersen <martin.petersen@oracle.com>
8 * Copyright (C) 2013 Intel Corporation
9 * Author: Tim Chen <tim.c.chen@linux.intel.com>
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the Free
13 * Software Foundation; either version 2 of the License, or (at your option)
14 * any later version.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
27 #include <linux/module.h>
28 #include <linux/crc-t10dif.h>
29 #include <crypto/internal/hash.h>
30 #include <linux/init.h>
31 #include <linux/kernel.h>
33 struct chksum_desc_ctx {
34 __u16 crc;
38 * Steps through buffer one byte at at time, calculates reflected
39 * crc using table.
42 static int chksum_init(struct shash_desc *desc)
44 struct chksum_desc_ctx *ctx = shash_desc_ctx(desc);
46 ctx->crc = 0;
48 return 0;
51 static int chksum_update(struct shash_desc *desc, const u8 *data,
52 unsigned int length)
54 struct chksum_desc_ctx *ctx = shash_desc_ctx(desc);
56 ctx->crc = crc_t10dif_generic(ctx->crc, data, length);
57 return 0;
60 static int chksum_final(struct shash_desc *desc, u8 *out)
62 struct chksum_desc_ctx *ctx = shash_desc_ctx(desc);
64 *(__u16 *)out = ctx->crc;
65 return 0;
68 static int __chksum_finup(__u16 *crcp, const u8 *data, unsigned int len,
69 u8 *out)
71 *(__u16 *)out = crc_t10dif_generic(*crcp, data, len);
72 return 0;
75 static int chksum_finup(struct shash_desc *desc, const u8 *data,
76 unsigned int len, u8 *out)
78 struct chksum_desc_ctx *ctx = shash_desc_ctx(desc);
80 return __chksum_finup(&ctx->crc, data, len, out);
83 static int chksum_digest(struct shash_desc *desc, const u8 *data,
84 unsigned int length, u8 *out)
86 struct chksum_desc_ctx *ctx = shash_desc_ctx(desc);
88 return __chksum_finup(&ctx->crc, data, length, out);
91 static struct shash_alg alg = {
92 .digestsize = CRC_T10DIF_DIGEST_SIZE,
93 .init = chksum_init,
94 .update = chksum_update,
95 .final = chksum_final,
96 .finup = chksum_finup,
97 .digest = chksum_digest,
98 .descsize = sizeof(struct chksum_desc_ctx),
99 .base = {
100 .cra_name = "crct10dif",
101 .cra_driver_name = "crct10dif-generic",
102 .cra_priority = 100,
103 .cra_blocksize = CRC_T10DIF_BLOCK_SIZE,
104 .cra_module = THIS_MODULE,
108 static int __init crct10dif_mod_init(void)
110 int ret;
112 ret = crypto_register_shash(&alg);
113 return ret;
116 static void __exit crct10dif_mod_fini(void)
118 crypto_unregister_shash(&alg);
121 module_init(crct10dif_mod_init);
122 module_exit(crct10dif_mod_fini);
124 MODULE_AUTHOR("Tim Chen <tim.c.chen@linux.intel.com>");
125 MODULE_DESCRIPTION("T10 DIF CRC calculation.");
126 MODULE_LICENSE("GPL");
127 MODULE_ALIAS_CRYPTO("crct10dif");
128 MODULE_ALIAS_CRYPTO("crct10dif-generic");