Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
torvalds
GitHub Repository: torvalds/linux
Path: blob/master/lib/crypto/arm64/sm3.h
170891 views
1
/* SPDX-License-Identifier: GPL-2.0-or-later */
2
/*
3
* SM3 optimized for ARM64
4
*
5
* Copyright 2026 Google LLC
6
*/
7
#include <asm/simd.h>
8
#include <linux/cpufeature.h>
9
10
static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_neon);
11
static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_ce);
12
13
asmlinkage void sm3_neon_transform(struct sm3_block_state *state,
14
const u8 *data, size_t nblocks);
15
asmlinkage void sm3_ce_transform(struct sm3_block_state *state,
16
const u8 *data, size_t nblocks);
17
18
static void sm3_blocks(struct sm3_block_state *state,
19
const u8 *data, size_t nblocks)
20
{
21
if (static_branch_likely(&have_neon) && likely(may_use_simd())) {
22
scoped_ksimd() {
23
if (static_branch_likely(&have_ce))
24
sm3_ce_transform(state, data, nblocks);
25
else
26
sm3_neon_transform(state, data, nblocks);
27
}
28
} else {
29
sm3_blocks_generic(state, data, nblocks);
30
}
31
}
32
33
#define sm3_mod_init_arch sm3_mod_init_arch
34
static void sm3_mod_init_arch(void)
35
{
36
if (cpu_have_named_feature(ASIMD)) {
37
static_branch_enable(&have_neon);
38
if (cpu_have_named_feature(SM3))
39
static_branch_enable(&have_ce);
40
}
41
}
42
43