blob: d915c656e5feb634265b1400e307b93c3f84ca59 [file] [log] [blame]
David Brazdil0f672f62019-12-10 10:32:29 +00001// SPDX-License-Identifier: GPL-2.0-or-later
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002/*
3 * Linux/arm64 port of the OpenSSL SHA512 implementation for AArch64
4 *
5 * Copyright (c) 2016 Linaro Ltd. <ard.biesheuvel@linaro.org>
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00006 */
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
16MODULE_DESCRIPTION("SHA-384/SHA-512 secure hash for arm64");
17MODULE_AUTHOR("Andy Polyakov <appro@openssl.org>");
18MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>");
19MODULE_LICENSE("GPL v2");
20MODULE_ALIAS_CRYPTO("sha384");
21MODULE_ALIAS_CRYPTO("sha512");
22
23asmlinkage void sha512_block_data_order(u32 *digest, const void *data,
24 unsigned int num_blks);
25EXPORT_SYMBOL(sha512_block_data_order);
26
27static int sha512_update(struct shash_desc *desc, const u8 *data,
28 unsigned int len)
29{
30 return sha512_base_do_update(desc, data, len,
31 (sha512_block_fn *)sha512_block_data_order);
32}
33
34static int sha512_finup(struct shash_desc *desc, const u8 *data,
35 unsigned int len, u8 *out)
36{
37 if (len)
38 sha512_base_do_update(desc, data, len,
39 (sha512_block_fn *)sha512_block_data_order);
40 sha512_base_do_finalize(desc,
41 (sha512_block_fn *)sha512_block_data_order);
42
43 return sha512_base_finish(desc, out);
44}
45
46static int sha512_final(struct shash_desc *desc, u8 *out)
47{
48 return sha512_finup(desc, NULL, 0, out);
49}
50
51static struct shash_alg algs[] = { {
52 .digestsize = SHA512_DIGEST_SIZE,
53 .init = sha512_base_init,
54 .update = sha512_update,
55 .final = sha512_final,
56 .finup = sha512_finup,
57 .descsize = sizeof(struct sha512_state),
58 .base.cra_name = "sha512",
59 .base.cra_driver_name = "sha512-arm64",
60 .base.cra_priority = 150,
61 .base.cra_blocksize = SHA512_BLOCK_SIZE,
62 .base.cra_module = THIS_MODULE,
63}, {
64 .digestsize = SHA384_DIGEST_SIZE,
65 .init = sha384_base_init,
66 .update = sha512_update,
67 .final = sha512_final,
68 .finup = sha512_finup,
69 .descsize = sizeof(struct sha512_state),
70 .base.cra_name = "sha384",
71 .base.cra_driver_name = "sha384-arm64",
72 .base.cra_priority = 150,
73 .base.cra_blocksize = SHA384_BLOCK_SIZE,
74 .base.cra_module = THIS_MODULE,
75} };
76
77static int __init sha512_mod_init(void)
78{
79 return crypto_register_shashes(algs, ARRAY_SIZE(algs));
80}
81
82static void __exit sha512_mod_fini(void)
83{
84 crypto_unregister_shashes(algs, ARRAY_SIZE(algs));
85}
86
87module_init(sha512_mod_init);
88module_exit(sha512_mod_fini);