xref: /openbmc/linux/arch/arm64/crypto/sha512-glue.c (revision 7fbbbc78)
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 <linux/cryptohash.h>
10 #include <linux/types.h>
11 #include <linux/string.h>
12 #include <crypto/sha.h>
13 #include <crypto/sha512_base.h>
14 #include <asm/neon.h>
15 
16 MODULE_DESCRIPTION("SHA-384/SHA-512 secure hash for arm64");
17 MODULE_AUTHOR("Andy Polyakov <appro@openssl.org>");
18 MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>");
19 MODULE_LICENSE("GPL v2");
20 MODULE_ALIAS_CRYPTO("sha384");
21 MODULE_ALIAS_CRYPTO("sha512");
22 
23 asmlinkage void sha512_block_data_order(u64 *digest, const void *data,
24 					unsigned int num_blks);
25 EXPORT_SYMBOL(sha512_block_data_order);
26 
27 static void __sha512_block_data_order(struct sha512_state *sst, u8 const *src,
28 				      int blocks)
29 {
30 	sha512_block_data_order(sst->state, src, blocks);
31 }
32 
33 static int sha512_update(struct shash_desc *desc, const u8 *data,
34 			 unsigned int len)
35 {
36 	return sha512_base_do_update(desc, data, len,
37 				     __sha512_block_data_order);
38 }
39 
40 static int sha512_finup(struct shash_desc *desc, const u8 *data,
41 			unsigned int len, u8 *out)
42 {
43 	if (len)
44 		sha512_base_do_update(desc, data, len,
45 				      __sha512_block_data_order);
46 	sha512_base_do_finalize(desc, __sha512_block_data_order);
47 
48 	return sha512_base_finish(desc, out);
49 }
50 
51 static int sha512_final(struct shash_desc *desc, u8 *out)
52 {
53 	return sha512_finup(desc, NULL, 0, out);
54 }
55 
56 static struct shash_alg algs[] = { {
57 	.digestsize		= SHA512_DIGEST_SIZE,
58 	.init			= sha512_base_init,
59 	.update			= sha512_update,
60 	.final			= sha512_final,
61 	.finup			= sha512_finup,
62 	.descsize		= sizeof(struct sha512_state),
63 	.base.cra_name		= "sha512",
64 	.base.cra_driver_name	= "sha512-arm64",
65 	.base.cra_priority	= 150,
66 	.base.cra_blocksize	= SHA512_BLOCK_SIZE,
67 	.base.cra_module	= THIS_MODULE,
68 }, {
69 	.digestsize		= SHA384_DIGEST_SIZE,
70 	.init			= sha384_base_init,
71 	.update			= sha512_update,
72 	.final			= sha512_final,
73 	.finup			= sha512_finup,
74 	.descsize		= sizeof(struct sha512_state),
75 	.base.cra_name		= "sha384",
76 	.base.cra_driver_name	= "sha384-arm64",
77 	.base.cra_priority	= 150,
78 	.base.cra_blocksize	= SHA384_BLOCK_SIZE,
79 	.base.cra_module	= THIS_MODULE,
80 } };
81 
82 static int __init sha512_mod_init(void)
83 {
84 	return crypto_register_shashes(algs, ARRAY_SIZE(algs));
85 }
86 
87 static void __exit sha512_mod_fini(void)
88 {
89 	crypto_unregister_shashes(algs, ARRAY_SIZE(algs));
90 }
91 
92 module_init(sha512_mod_init);
93 module_exit(sha512_mod_fini);
94