1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * SHA-1 accelerated using the sparc64 crypto opcodes 4 * 5 * Copyright (c) Alan Smithee. 6 * Copyright (c) Andrew McDonald <andrew@mcdonald.org.uk> 7 * Copyright (c) Jean-Francois Dive <jef@linuxbe.org> 8 * Copyright (c) Mathias Krause <minipli@googlemail.com> 9 */ 10 11 #include <asm/elf.h> 12 #include <asm/opcodes.h> 13 #include <asm/pstate.h> 14 15 static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_sha1_opcodes); 16 17 asmlinkage void sha1_sparc64_transform(struct sha1_block_state *state, 18 const u8 *data, size_t nblocks); 19 20 static void sha1_blocks(struct sha1_block_state *state, 21 const u8 *data, size_t nblocks) 22 { 23 if (static_branch_likely(&have_sha1_opcodes)) 24 sha1_sparc64_transform(state, data, nblocks); 25 else 26 sha1_blocks_generic(state, data, nblocks); 27 } 28 29 #define sha1_mod_init_arch sha1_mod_init_arch 30 static inline void sha1_mod_init_arch(void) 31 { 32 unsigned long cfr; 33 34 if (!(sparc64_elf_hwcap & HWCAP_SPARC_CRYPTO)) 35 return; 36 37 __asm__ __volatile__("rd %%asr26, %0" : "=r" (cfr)); 38 if (!(cfr & CFR_SHA1)) 39 return; 40 41 static_branch_enable(&have_sha1_opcodes); 42 pr_info("Using sparc64 sha1 opcode optimized SHA-1 implementation\n"); 43 } 44