1 // SPDX-License-Identifier: GPL-2.0
3 * NHPoly1305 - ε-almost-∆-universal hash function for Adiantum
4 * (ARM64 NEON accelerated version)
6 * Copyright 2018 Google LLC
11 #include <crypto/internal/hash.h>
12 #include <crypto/internal/simd.h>
13 #include <crypto/nhpoly1305.h>
14 #include <linux/module.h>
16 asmlinkage void nh_neon(const u32 *key, const u8 *message, size_t message_len,
17 __le64 hash[NH_NUM_PASSES]);
19 static int nhpoly1305_neon_update(struct shash_desc *desc,
20 const u8 *src, unsigned int srclen)
22 if (srclen < 64 || !crypto_simd_usable())
23 return crypto_nhpoly1305_update(desc, src, srclen);
26 unsigned int n = min_t(unsigned int, srclen, SZ_4K);
29 crypto_nhpoly1305_update_helper(desc, src, n, nh_neon);
37 static struct shash_alg nhpoly1305_alg = {
38 .base.cra_name = "nhpoly1305",
39 .base.cra_driver_name = "nhpoly1305-neon",
40 .base.cra_priority = 200,
41 .base.cra_ctxsize = sizeof(struct nhpoly1305_key),
42 .base.cra_module = THIS_MODULE,
43 .digestsize = POLY1305_DIGEST_SIZE,
44 .init = crypto_nhpoly1305_init,
45 .update = nhpoly1305_neon_update,
46 .final = crypto_nhpoly1305_final,
47 .setkey = crypto_nhpoly1305_setkey,
48 .descsize = sizeof(struct nhpoly1305_state),
51 static int __init nhpoly1305_mod_init(void)
53 if (!cpu_have_named_feature(ASIMD))
56 return crypto_register_shash(&nhpoly1305_alg);
59 static void __exit nhpoly1305_mod_exit(void)
61 crypto_unregister_shash(&nhpoly1305_alg);
64 module_init(nhpoly1305_mod_init);
65 module_exit(nhpoly1305_mod_exit);
67 MODULE_DESCRIPTION("NHPoly1305 ε-almost-∆-universal hash function (NEON-accelerated)");
68 MODULE_LICENSE("GPL v2");
69 MODULE_AUTHOR("Eric Biggers <ebiggers@google.com>");
70 MODULE_ALIAS_CRYPTO("nhpoly1305");
71 MODULE_ALIAS_CRYPTO("nhpoly1305-neon");