~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/crypto/crct10dif_generic.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * Cryptographic API.
  3  *
  4  * T10 Data Integrity Field CRC16 Crypto Transform
  5  *
  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>
 10  *
 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.
 15  *
 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.
 24  *
 25  */
 26 
 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>
 32 
 33 struct chksum_desc_ctx {
 34         __u16 crc;
 35 };
 36 
 37 /*
 38  * Steps through buffer one byte at a time, calculates reflected
 39  * crc using table.
 40  */
 41 
 42 static int chksum_init(struct shash_desc *desc)
 43 {
 44         struct chksum_desc_ctx *ctx = shash_desc_ctx(desc);
 45 
 46         ctx->crc = 0;
 47 
 48         return 0;
 49 }
 50 
 51 static int chksum_update(struct shash_desc *desc, const u8 *data,
 52                          unsigned int length)
 53 {
 54         struct chksum_desc_ctx *ctx = shash_desc_ctx(desc);
 55 
 56         ctx->crc = crc_t10dif_generic(ctx->crc, data, length);
 57         return 0;
 58 }
 59 
 60 static int chksum_final(struct shash_desc *desc, u8 *out)
 61 {
 62         struct chksum_desc_ctx *ctx = shash_desc_ctx(desc);
 63 
 64         *(__u16 *)out = ctx->crc;
 65         return 0;
 66 }
 67 
 68 static int __chksum_finup(__u16 crc, const u8 *data, unsigned int len, u8 *out)
 69 {
 70         *(__u16 *)out = crc_t10dif_generic(crc, data, len);
 71         return 0;
 72 }
 73 
 74 static int chksum_finup(struct shash_desc *desc, const u8 *data,
 75                         unsigned int len, u8 *out)
 76 {
 77         struct chksum_desc_ctx *ctx = shash_desc_ctx(desc);
 78 
 79         return __chksum_finup(ctx->crc, data, len, out);
 80 }
 81 
 82 static int chksum_digest(struct shash_desc *desc, const u8 *data,
 83                          unsigned int length, u8 *out)
 84 {
 85         return __chksum_finup(0, data, length, out);
 86 }
 87 
 88 static struct shash_alg alg = {
 89         .digestsize             =       CRC_T10DIF_DIGEST_SIZE,
 90         .init           =       chksum_init,
 91         .update         =       chksum_update,
 92         .final          =       chksum_final,
 93         .finup          =       chksum_finup,
 94         .digest         =       chksum_digest,
 95         .descsize               =       sizeof(struct chksum_desc_ctx),
 96         .base                   =       {
 97                 .cra_name               =       "crct10dif",
 98                 .cra_driver_name        =       "crct10dif-generic",
 99                 .cra_priority           =       100,
100                 .cra_blocksize          =       CRC_T10DIF_BLOCK_SIZE,
101                 .cra_module             =       THIS_MODULE,
102         }
103 };
104 
105 static int __init crct10dif_mod_init(void)
106 {
107         return crypto_register_shash(&alg);
108 }
109 
110 static void __exit crct10dif_mod_fini(void)
111 {
112         crypto_unregister_shash(&alg);
113 }
114 
115 subsys_initcall(crct10dif_mod_init);
116 module_exit(crct10dif_mod_fini);
117 
118 MODULE_AUTHOR("Tim Chen <tim.c.chen@linux.intel.com>");
119 MODULE_DESCRIPTION("T10 DIF CRC calculation.");
120 MODULE_LICENSE("GPL");
121 MODULE_ALIAS_CRYPTO("crct10dif");
122 MODULE_ALIAS_CRYPTO("crct10dif-generic");
123 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php