FILE
nhpoly1305-neon-glue.c
File preview with syntax highlighting.
linux-6.19.14/arch/arm64/crypto/nhpoly1305-neon-glue.c
1// SPDX-License-Identifier: GPL-2.0 2/* 3 * NHPoly1305 - ε-almost-∆-universal hash function for Adiantum 4 * (ARM64 NEON accelerated version) 5 * 6 * Copyright 2018 Google LLC 7 */ 8 9#include <asm/neon.h> 10#include <asm/simd.h> 11#include <crypto/internal/hash.h> 12#include <crypto/internal/simd.h> 13#include <crypto/nhpoly1305.h> 14#include <linux/module.h> 15 16asmlinkage void nh_neon(const u32 *key, const u8 *message, size_t message_len, 17 __le64 hash[NH_NUM_PASSES]); 18 19static int nhpoly1305_neon_update(struct shash_desc *desc, 20 const u8 *src, unsigned int srclen) 21{ 22 if (srclen < 64 || !crypto_simd_usable()) 23 return crypto_nhpoly1305_update(desc, src, srclen); 24 25 do { 26 unsigned int n = min_t(unsigned int, srclen, SZ_4K); 27 28 scoped_ksimd() 29 crypto_nhpoly1305_update_helper(desc, src, n, nh_neon); 30 src += n; 31 srclen -= n; 32 } while (srclen); 33 return 0; 34} 35 36static int nhpoly1305_neon_digest(struct shash_desc *desc, 37 const u8 *src, unsigned int srclen, u8 *out) 38{ 39 return crypto_nhpoly1305_init(desc) ?: 40 nhpoly1305_neon_update(desc, src, srclen) ?: 41 crypto_nhpoly1305_final(desc, out); 42} 43 44static struct shash_alg nhpoly1305_alg = { 45 .base.cra_name = "nhpoly1305", 46 .base.cra_driver_name = "nhpoly1305-neon", 47 .base.cra_priority = 200, 48 .base.cra_ctxsize = sizeof(struct nhpoly1305_key), 49 .base.cra_module = THIS_MODULE, 50 .digestsize = POLY1305_DIGEST_SIZE, 51 .init = crypto_nhpoly1305_init, 52 .update = nhpoly1305_neon_update, 53 .final = crypto_nhpoly1305_final, 54 .digest = nhpoly1305_neon_digest, 55 .setkey = crypto_nhpoly1305_setkey, 56 .descsize = sizeof(struct nhpoly1305_state), 57}; 58 59static int __init nhpoly1305_mod_init(void) 60{ 61 if (!cpu_have_named_feature(ASIMD)) 62 return -ENODEV; 63 64 return crypto_register_shash(&nhpoly1305_alg); 65} 66 67static void __exit nhpoly1305_mod_exit(void) 68{ 69 crypto_unregister_shash(&nhpoly1305_alg); 70} 71 72module_init(nhpoly1305_mod_init); 73module_exit(nhpoly1305_mod_exit); 74 75MODULE_DESCRIPTION("NHPoly1305 ε-almost-∆-universal hash function (NEON-accelerated)"); 76MODULE_LICENSE("GPL v2"); 77MODULE_AUTHOR("Eric Biggers <ebiggers@google.com>"); 78MODULE_ALIAS_CRYPTO("nhpoly1305"); 79MODULE_ALIAS_CRYPTO("nhpoly1305-neon");
~/
Read-only file preview.