File Index
Files and directories
Sign in
FILE

sha256.h

File preview with syntax highlighting.

linux-6.19.14/lib/crypto/sparc/sha256.h C
 1/* SPDX-License-Identifier: GPL-2.0-only */
 2/*
 3 * SHA-256 accelerated using the sparc64 sha256 opcodes
 4 *
 5 * Copyright (c) Jean-Luc Cooke <jlcooke@certainkey.com>
 6 * Copyright (c) Andrew McDonald <andrew@mcdonald.org.uk>
 7 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
 8 * SHA224 Support Copyright 2007 Intel Corporation <jonathan.lynch@intel.com>
 9 */
10
11#include <asm/elf.h>
12#include <asm/opcodes.h>
13#include <asm/pstate.h>
14
15static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_sha256_opcodes);
16
17asmlinkage void sha256_sparc64_transform(struct sha256_block_state *state,
18					 const u8 *data, size_t nblocks);
19
20static void sha256_blocks(struct sha256_block_state *state,
21			  const u8 *data, size_t nblocks)
22{
23	if (static_branch_likely(&have_sha256_opcodes))
24		sha256_sparc64_transform(state, data, nblocks);
25	else
26		sha256_blocks_generic(state, data, nblocks);
27}
28
29#define sha256_mod_init_arch sha256_mod_init_arch
30static void sha256_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_SHA256))
39		return;
40
41	static_branch_enable(&have_sha256_opcodes);
42	pr_info("Using sparc64 sha256 opcode optimized SHA-256/SHA-224 implementation\n");
43}
~/ Read-only file preview.