Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 
0003 #include <linux/crc64.h>
0004 #include <linux/module.h>
0005 #include <crypto/internal/hash.h>
0006 #include <asm/unaligned.h>
0007 
0008 static int chksum_init(struct shash_desc *desc)
0009 {
0010     u64 *crc = shash_desc_ctx(desc);
0011 
0012     *crc = 0;
0013 
0014     return 0;
0015 }
0016 
0017 static int chksum_update(struct shash_desc *desc, const u8 *data,
0018              unsigned int length)
0019 {
0020     u64 *crc = shash_desc_ctx(desc);
0021 
0022     *crc = crc64_rocksoft_generic(*crc, data, length);
0023 
0024     return 0;
0025 }
0026 
0027 static int chksum_final(struct shash_desc *desc, u8 *out)
0028 {
0029     u64 *crc = shash_desc_ctx(desc);
0030 
0031     put_unaligned_le64(*crc, out);
0032     return 0;
0033 }
0034 
0035 static int __chksum_finup(u64 crc, const u8 *data, unsigned int len, u8 *out)
0036 {
0037     crc = crc64_rocksoft_generic(crc, data, len);
0038     put_unaligned_le64(crc, out);
0039     return 0;
0040 }
0041 
0042 static int chksum_finup(struct shash_desc *desc, const u8 *data,
0043             unsigned int len, u8 *out)
0044 {
0045     u64 *crc = shash_desc_ctx(desc);
0046 
0047     return __chksum_finup(*crc, data, len, out);
0048 }
0049 
0050 static int chksum_digest(struct shash_desc *desc, const u8 *data,
0051              unsigned int length, u8 *out)
0052 {
0053     return __chksum_finup(0, data, length, out);
0054 }
0055 
0056 static struct shash_alg alg = {
0057     .digestsize =   sizeof(u64),
0058     .init       =   chksum_init,
0059     .update     =   chksum_update,
0060     .final      =   chksum_final,
0061     .finup      =   chksum_finup,
0062     .digest     =   chksum_digest,
0063     .descsize   =   sizeof(u64),
0064     .base       =   {
0065         .cra_name       =   CRC64_ROCKSOFT_STRING,
0066         .cra_driver_name    =   "crc64-rocksoft-generic",
0067         .cra_priority       =   200,
0068         .cra_blocksize      =   1,
0069         .cra_module     =   THIS_MODULE,
0070     }
0071 };
0072 
0073 static int __init crc64_rocksoft_init(void)
0074 {
0075     return crypto_register_shash(&alg);
0076 }
0077 
0078 static void __exit crc64_rocksoft_exit(void)
0079 {
0080     crypto_unregister_shash(&alg);
0081 }
0082 
0083 module_init(crc64_rocksoft_init);
0084 module_exit(crc64_rocksoft_exit);
0085 
0086 MODULE_LICENSE("GPL");
0087 MODULE_DESCRIPTION("Rocksoft model CRC64 calculation.");
0088 MODULE_ALIAS_CRYPTO("crc64-rocksoft");
0089 MODULE_ALIAS_CRYPTO("crc64-rocksoft-generic");