1// SPDX-License-Identifier: GPL-2.0
2/*
3 * sha512-ce-glue.c - SHA-384/SHA-512 using ARMv8 Crypto Extensions
4 *
5 * Copyright (C) 2018 Linaro Ltd <ard.biesheuvel@linaro.org>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <asm/neon.h>
13#include <crypto/internal/hash.h>
14#include <crypto/sha2.h>
15#include <crypto/sha512_base.h>
16#include <linux/cpufeature.h>
17#include <linux/kernel.h>
18#include <linux/module.h>
19
20MODULE_DESCRIPTION("SHA-384/SHA-512 secure hash using ARMv8 Crypto Extensions");
21MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>");
22MODULE_LICENSE("GPL v2");
23MODULE_ALIAS_CRYPTO("sha384");
24MODULE_ALIAS_CRYPTO("sha512");
25
26asmlinkage int __sha512_ce_transform(struct sha512_state *sst, u8 const *src,
27 int blocks);
28
29static void sha512_ce_transform(struct sha512_state *sst, u8 const *src,
30 int blocks)
31{
32 do {
33 int rem;
34
35 kernel_neon_begin();
36 rem = __sha512_ce_transform(sst, src, blocks);
37 kernel_neon_end();
38 src += (blocks - rem) * SHA512_BLOCK_SIZE;
39 blocks = rem;
40 } while (blocks);
41}
42
43static int sha512_ce_update(struct shash_desc *desc, const u8 *data,
44 unsigned int len)
45{
46 return sha512_base_do_update_blocks(desc, data, len,
47 block_fn: sha512_ce_transform);
48}
49
50static int sha512_ce_finup(struct shash_desc *desc, const u8 *data,
51 unsigned int len, u8 *out)
52{
53 sha512_base_do_finup(desc, src: data, len, block_fn: sha512_ce_transform);
54 return sha512_base_finish(desc, out);
55}
56
57static struct shash_alg algs[] = { {
58 .init = sha384_base_init,
59 .update = sha512_ce_update,
60 .finup = sha512_ce_finup,
61 .descsize = SHA512_STATE_SIZE,
62 .digestsize = SHA384_DIGEST_SIZE,
63 .base.cra_name = "sha384",
64 .base.cra_driver_name = "sha384-ce",
65 .base.cra_priority = 200,
66 .base.cra_flags = CRYPTO_AHASH_ALG_BLOCK_ONLY |
67 CRYPTO_AHASH_ALG_FINUP_MAX,
68 .base.cra_blocksize = SHA512_BLOCK_SIZE,
69 .base.cra_module = THIS_MODULE,
70}, {
71 .init = sha512_base_init,
72 .update = sha512_ce_update,
73 .finup = sha512_ce_finup,
74 .descsize = SHA512_STATE_SIZE,
75 .digestsize = SHA512_DIGEST_SIZE,
76 .base.cra_name = "sha512",
77 .base.cra_driver_name = "sha512-ce",
78 .base.cra_priority = 200,
79 .base.cra_flags = CRYPTO_AHASH_ALG_BLOCK_ONLY |
80 CRYPTO_AHASH_ALG_FINUP_MAX,
81 .base.cra_blocksize = SHA512_BLOCK_SIZE,
82 .base.cra_module = THIS_MODULE,
83} };
84
85static int __init sha512_ce_mod_init(void)
86{
87 return crypto_register_shashes(algs, ARRAY_SIZE(algs));
88}
89
90static void __exit sha512_ce_mod_fini(void)
91{
92 crypto_unregister_shashes(algs, ARRAY_SIZE(algs));
93}
94
95module_cpu_feature_match(SHA512, sha512_ce_mod_init);
96module_exit(sha512_ce_mod_fini);
97

Provided by KDAB

Privacy Policy
Improve your Profiling and Debugging skills
Find out more

source code of linux/arch/arm64/crypto/sha512-ce-glue.c