1 | // SPDX-License-Identifier: GPL-2.0-or-later |
2 | /* |
3 | * Linux/arm64 port of the OpenSSL SHA512 implementation for AArch64 |
4 | * |
5 | * Copyright (c) 2016 Linaro Ltd. <ard.biesheuvel@linaro.org> |
6 | */ |
7 | |
8 | #include <crypto/internal/hash.h> |
9 | #include <crypto/sha2.h> |
10 | #include <crypto/sha512_base.h> |
11 | #include <linux/kernel.h> |
12 | #include <linux/module.h> |
13 | |
14 | MODULE_DESCRIPTION("SHA-384/SHA-512 secure hash for arm64" ); |
15 | MODULE_AUTHOR("Andy Polyakov <appro@openssl.org>" ); |
16 | MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>" ); |
17 | MODULE_LICENSE("GPL v2" ); |
18 | MODULE_ALIAS_CRYPTO("sha384" ); |
19 | MODULE_ALIAS_CRYPTO("sha512" ); |
20 | |
21 | asmlinkage void sha512_blocks_arch(u64 *digest, const void *data, |
22 | unsigned int num_blks); |
23 | |
24 | static void sha512_arm64_transform(struct sha512_state *sst, u8 const *src, |
25 | int blocks) |
26 | { |
27 | sha512_blocks_arch(digest: sst->state, data: src, num_blks: blocks); |
28 | } |
29 | |
30 | static int sha512_update(struct shash_desc *desc, const u8 *data, |
31 | unsigned int len) |
32 | { |
33 | return sha512_base_do_update_blocks(desc, data, len, |
34 | block_fn: sha512_arm64_transform); |
35 | } |
36 | |
37 | static int sha512_finup(struct shash_desc *desc, const u8 *data, |
38 | unsigned int len, u8 *out) |
39 | { |
40 | sha512_base_do_finup(desc, src: data, len, block_fn: sha512_arm64_transform); |
41 | return sha512_base_finish(desc, out); |
42 | } |
43 | |
44 | static struct shash_alg algs[] = { { |
45 | .digestsize = SHA512_DIGEST_SIZE, |
46 | .init = sha512_base_init, |
47 | .update = sha512_update, |
48 | .finup = sha512_finup, |
49 | .descsize = SHA512_STATE_SIZE, |
50 | .base.cra_name = "sha512" , |
51 | .base.cra_driver_name = "sha512-arm64" , |
52 | .base.cra_priority = 150, |
53 | .base.cra_flags = CRYPTO_AHASH_ALG_BLOCK_ONLY | |
54 | CRYPTO_AHASH_ALG_FINUP_MAX, |
55 | .base.cra_blocksize = SHA512_BLOCK_SIZE, |
56 | .base.cra_module = THIS_MODULE, |
57 | }, { |
58 | .digestsize = SHA384_DIGEST_SIZE, |
59 | .init = sha384_base_init, |
60 | .update = sha512_update, |
61 | .finup = sha512_finup, |
62 | .descsize = SHA512_STATE_SIZE, |
63 | .base.cra_name = "sha384" , |
64 | .base.cra_driver_name = "sha384-arm64" , |
65 | .base.cra_priority = 150, |
66 | .base.cra_flags = CRYPTO_AHASH_ALG_BLOCK_ONLY | |
67 | CRYPTO_AHASH_ALG_FINUP_MAX, |
68 | .base.cra_blocksize = SHA384_BLOCK_SIZE, |
69 | .base.cra_module = THIS_MODULE, |
70 | } }; |
71 | |
72 | static int __init sha512_mod_init(void) |
73 | { |
74 | return crypto_register_shashes(algs, ARRAY_SIZE(algs)); |
75 | } |
76 | |
77 | static void __exit sha512_mod_fini(void) |
78 | { |
79 | crypto_unregister_shashes(algs, ARRAY_SIZE(algs)); |
80 | } |
81 | |
82 | module_init(sha512_mod_init); |
83 | module_exit(sha512_mod_fini); |
84 | |