1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * OpenSSL/Cryptogams accelerated Poly1305 transform for arm64 4 * 5 * Copyright (C) 2019 Linaro Ltd. <ard.biesheuvel@linaro.org> 6 */ 7 8 #include <asm/hwcap.h> 9 #include <asm/simd.h> 10 #include <linux/cpufeature.h> 11 #include <linux/jump_label.h> 12 #include <linux/kernel.h> 13 14 asmlinkage void poly1305_block_init(struct poly1305_block_state *state, 15 const u8 raw_key[POLY1305_BLOCK_SIZE]); 16 asmlinkage void poly1305_blocks_arm64(struct poly1305_block_state *state, 17 const u8 *src, u32 len, u32 hibit); 18 asmlinkage void poly1305_blocks_neon(struct poly1305_block_state *state, 19 const u8 *src, u32 len, u32 hibit); 20 asmlinkage void poly1305_emit(const struct poly1305_state *state, 21 u8 digest[POLY1305_DIGEST_SIZE], 22 const u32 nonce[4]); 23 24 static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_neon); 25 26 static void poly1305_blocks(struct poly1305_block_state *state, const u8 *src, 27 unsigned int len, u32 padbit) 28 { 29 if (static_branch_likely(&have_neon) && likely(may_use_simd())) { 30 scoped_ksimd() 31 poly1305_blocks_neon(state, src, len, padbit); 32 } else { 33 poly1305_blocks_arm64(state, src, len, padbit); 34 } 35 } 36 37 #define poly1305_mod_init_arch poly1305_mod_init_arch 38 static void poly1305_mod_init_arch(void) 39 { 40 if (cpu_have_named_feature(ASIMD)) 41 static_branch_enable(&have_neon); 42 } 43