Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
torvalds
GitHub Repository: torvalds/linux
Path: blob/master/lib/crypto/riscv/sm3.h
170891 views
1
/* SPDX-License-Identifier: GPL-2.0-or-later */
2
/*
3
* SM3 using the RISC-V vector crypto extensions
4
*
5
* Copyright (C) 2023 VRULL GmbH
6
* Author: Heiko Stuebner <[email protected]>
7
*
8
* Copyright (C) 2023 SiFive, Inc.
9
* Author: Jerry Shih <[email protected]>
10
*/
11
12
#include <asm/simd.h>
13
#include <asm/vector.h>
14
15
static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_extensions);
16
17
asmlinkage void sm3_transform_zvksh_zvkb(struct sm3_block_state *state,
18
const u8 *data, size_t nblocks);
19
20
static void sm3_blocks(struct sm3_block_state *state,
21
const u8 *data, size_t nblocks)
22
{
23
if (static_branch_likely(&have_extensions) && likely(may_use_simd())) {
24
kernel_vector_begin();
25
sm3_transform_zvksh_zvkb(state, data, nblocks);
26
kernel_vector_end();
27
} else {
28
sm3_blocks_generic(state, data, nblocks);
29
}
30
}
31
32
#define sm3_mod_init_arch sm3_mod_init_arch
33
static void sm3_mod_init_arch(void)
34
{
35
if (riscv_isa_extension_available(NULL, ZVKSH) &&
36
riscv_isa_extension_available(NULL, ZVKB) &&
37
riscv_vector_vlen() >= 128)
38
static_branch_enable(&have_extensions);
39
}
40
41