Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
torvalds
GitHub Repository: torvalds/linux
Path: blob/master/arch/arm64/crypto/sm3-neon-glue.c
53443 views
1
// SPDX-License-Identifier: GPL-2.0-or-later
2
/*
3
* sm3-neon-glue.c - SM3 secure hash using NEON instructions
4
*
5
* Copyright (C) 2022 Tianjia Zhang <[email protected]>
6
*/
7
8
#include <asm/simd.h>
9
#include <crypto/internal/hash.h>
10
#include <crypto/sm3.h>
11
#include <crypto/sm3_base.h>
12
#include <linux/cpufeature.h>
13
#include <linux/kernel.h>
14
#include <linux/module.h>
15
16
17
asmlinkage void sm3_neon_transform(struct sm3_state *sst, u8 const *src,
18
int blocks);
19
20
static int sm3_neon_update(struct shash_desc *desc, const u8 *data,
21
unsigned int len)
22
{
23
scoped_ksimd()
24
return sm3_base_do_update_blocks(desc, data, len,
25
sm3_neon_transform);
26
}
27
28
static int sm3_neon_finup(struct shash_desc *desc, const u8 *data,
29
unsigned int len, u8 *out)
30
{
31
scoped_ksimd()
32
sm3_base_do_finup(desc, data, len, sm3_neon_transform);
33
return sm3_base_finish(desc, out);
34
}
35
36
static struct shash_alg sm3_alg = {
37
.digestsize = SM3_DIGEST_SIZE,
38
.init = sm3_base_init,
39
.update = sm3_neon_update,
40
.finup = sm3_neon_finup,
41
.descsize = SM3_STATE_SIZE,
42
.base.cra_name = "sm3",
43
.base.cra_driver_name = "sm3-neon",
44
.base.cra_flags = CRYPTO_AHASH_ALG_BLOCK_ONLY |
45
CRYPTO_AHASH_ALG_FINUP_MAX,
46
.base.cra_blocksize = SM3_BLOCK_SIZE,
47
.base.cra_module = THIS_MODULE,
48
.base.cra_priority = 200,
49
};
50
51
static int __init sm3_neon_init(void)
52
{
53
return crypto_register_shash(&sm3_alg);
54
}
55
56
static void __exit sm3_neon_fini(void)
57
{
58
crypto_unregister_shash(&sm3_alg);
59
}
60
61
module_init(sm3_neon_init);
62
module_exit(sm3_neon_fini);
63
64
MODULE_DESCRIPTION("SM3 secure hash using NEON instructions");
65
MODULE_AUTHOR("Jussi Kivilinna <[email protected]>");
66
MODULE_AUTHOR("Tianjia Zhang <[email protected]>");
67
MODULE_LICENSE("GPL v2");
68
69