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

TOMOYO Linux Cross Reference
Linux/crypto/xxhash_generic.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ 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 // SPDX-License-Identifier: GPL-2.0
  2 
  3 #include <crypto/internal/hash.h>
  4 #include <linux/init.h>
  5 #include <linux/module.h>
  6 #include <linux/xxhash.h>
  7 #include <linux/unaligned.h>
  8 
  9 #define XXHASH64_BLOCK_SIZE     32
 10 #define XXHASH64_DIGEST_SIZE    8
 11 
 12 struct xxhash64_tfm_ctx {
 13         u64 seed;
 14 };
 15 
 16 struct xxhash64_desc_ctx {
 17         struct xxh64_state xxhstate;
 18 };
 19 
 20 static int xxhash64_setkey(struct crypto_shash *tfm, const u8 *key,
 21                          unsigned int keylen)
 22 {
 23         struct xxhash64_tfm_ctx *tctx = crypto_shash_ctx(tfm);
 24 
 25         if (keylen != sizeof(tctx->seed))
 26                 return -EINVAL;
 27         tctx->seed = get_unaligned_le64(key);
 28         return 0;
 29 }
 30 
 31 static int xxhash64_init(struct shash_desc *desc)
 32 {
 33         struct xxhash64_tfm_ctx *tctx = crypto_shash_ctx(desc->tfm);
 34         struct xxhash64_desc_ctx *dctx = shash_desc_ctx(desc);
 35 
 36         xxh64_reset(&dctx->xxhstate, tctx->seed);
 37 
 38         return 0;
 39 }
 40 
 41 static int xxhash64_update(struct shash_desc *desc, const u8 *data,
 42                          unsigned int length)
 43 {
 44         struct xxhash64_desc_ctx *dctx = shash_desc_ctx(desc);
 45 
 46         xxh64_update(&dctx->xxhstate, data, length);
 47 
 48         return 0;
 49 }
 50 
 51 static int xxhash64_final(struct shash_desc *desc, u8 *out)
 52 {
 53         struct xxhash64_desc_ctx *dctx = shash_desc_ctx(desc);
 54 
 55         put_unaligned_le64(xxh64_digest(&dctx->xxhstate), out);
 56 
 57         return 0;
 58 }
 59 
 60 static int xxhash64_digest(struct shash_desc *desc, const u8 *data,
 61                          unsigned int length, u8 *out)
 62 {
 63         struct xxhash64_tfm_ctx *tctx = crypto_shash_ctx(desc->tfm);
 64 
 65         put_unaligned_le64(xxh64(data, length, tctx->seed), out);
 66 
 67         return 0;
 68 }
 69 
 70 static struct shash_alg alg = {
 71         .digestsize     = XXHASH64_DIGEST_SIZE,
 72         .setkey         = xxhash64_setkey,
 73         .init           = xxhash64_init,
 74         .update         = xxhash64_update,
 75         .final          = xxhash64_final,
 76         .digest         = xxhash64_digest,
 77         .descsize       = sizeof(struct xxhash64_desc_ctx),
 78         .base           = {
 79                 .cra_name        = "xxhash64",
 80                 .cra_driver_name = "xxhash64-generic",
 81                 .cra_priority    = 100,
 82                 .cra_flags       = CRYPTO_ALG_OPTIONAL_KEY,
 83                 .cra_blocksize   = XXHASH64_BLOCK_SIZE,
 84                 .cra_ctxsize     = sizeof(struct xxhash64_tfm_ctx),
 85                 .cra_module      = THIS_MODULE,
 86         }
 87 };
 88 
 89 static int __init xxhash_mod_init(void)
 90 {
 91         return crypto_register_shash(&alg);
 92 }
 93 
 94 static void __exit xxhash_mod_fini(void)
 95 {
 96         crypto_unregister_shash(&alg);
 97 }
 98 
 99 subsys_initcall(xxhash_mod_init);
100 module_exit(xxhash_mod_fini);
101 
102 MODULE_AUTHOR("Nikolay Borisov <nborisov@suse.com>");
103 MODULE_DESCRIPTION("xxhash calculations wrapper for lib/xxhash.c");
104 MODULE_LICENSE("GPL");
105 MODULE_ALIAS_CRYPTO("xxhash64");
106 MODULE_ALIAS_CRYPTO("xxhash64-generic");
107 

~ [ 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