blob: d33ab59c26c07e4f59873210ffb69c4546e15e1b [file] [log] [blame]
Ard Biesheuvelc80ae7c2015-05-08 10:46:21 +02001/*
2 * sha512-neon-glue.c - accelerated SHA-384/512 for ARM NEON
3 *
4 * Copyright (C) 2015 Linaro Ltd <ard.biesheuvel@linaro.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#include <crypto/internal/hash.h>
Eric Biggers99680c52019-03-12 22:12:49 -070012#include <crypto/internal/simd.h>
Ard Biesheuvelc80ae7c2015-05-08 10:46:21 +020013#include <crypto/sha.h>
14#include <crypto/sha512_base.h>
15#include <linux/crypto.h>
16#include <linux/module.h>
17
18#include <asm/simd.h>
19#include <asm/neon.h>
20
21#include "sha512.h"
22
23MODULE_ALIAS_CRYPTO("sha384-neon");
24MODULE_ALIAS_CRYPTO("sha512-neon");
25
26asmlinkage void sha512_block_data_order_neon(u64 *state, u8 const *src,
27 int blocks);
28
29static int sha512_neon_update(struct shash_desc *desc, const u8 *data,
30 unsigned int len)
31{
32 struct sha512_state *sctx = shash_desc_ctx(desc);
33
Eric Biggers99680c52019-03-12 22:12:49 -070034 if (!crypto_simd_usable() ||
Ard Biesheuvelc80ae7c2015-05-08 10:46:21 +020035 (sctx->count[0] % SHA512_BLOCK_SIZE) + len < SHA512_BLOCK_SIZE)
36 return sha512_arm_update(desc, data, len);
37
38 kernel_neon_begin();
39 sha512_base_do_update(desc, data, len,
40 (sha512_block_fn *)sha512_block_data_order_neon);
41 kernel_neon_end();
42
43 return 0;
44}
45
46static int sha512_neon_finup(struct shash_desc *desc, const u8 *data,
47 unsigned int len, u8 *out)
48{
Eric Biggers99680c52019-03-12 22:12:49 -070049 if (!crypto_simd_usable())
Ard Biesheuvelc80ae7c2015-05-08 10:46:21 +020050 return sha512_arm_finup(desc, data, len, out);
51
52 kernel_neon_begin();
53 if (len)
54 sha512_base_do_update(desc, data, len,
55 (sha512_block_fn *)sha512_block_data_order_neon);
56 sha512_base_do_finalize(desc,
57 (sha512_block_fn *)sha512_block_data_order_neon);
58 kernel_neon_end();
59
60 return sha512_base_finish(desc, out);
61}
62
63static int sha512_neon_final(struct shash_desc *desc, u8 *out)
64{
65 return sha512_neon_finup(desc, NULL, 0, out);
66}
67
68struct shash_alg sha512_neon_algs[] = { {
69 .init = sha384_base_init,
70 .update = sha512_neon_update,
71 .final = sha512_neon_final,
72 .finup = sha512_neon_finup,
73 .descsize = sizeof(struct sha512_state),
74 .digestsize = SHA384_DIGEST_SIZE,
75 .base = {
76 .cra_name = "sha384",
77 .cra_driver_name = "sha384-neon",
78 .cra_priority = 300,
Ard Biesheuvelc80ae7c2015-05-08 10:46:21 +020079 .cra_blocksize = SHA384_BLOCK_SIZE,
80 .cra_module = THIS_MODULE,
81
82 }
83}, {
84 .init = sha512_base_init,
85 .update = sha512_neon_update,
86 .final = sha512_neon_final,
87 .finup = sha512_neon_finup,
88 .descsize = sizeof(struct sha512_state),
89 .digestsize = SHA512_DIGEST_SIZE,
90 .base = {
91 .cra_name = "sha512",
92 .cra_driver_name = "sha512-neon",
93 .cra_priority = 300,
Ard Biesheuvelc80ae7c2015-05-08 10:46:21 +020094 .cra_blocksize = SHA512_BLOCK_SIZE,
95 .cra_module = THIS_MODULE,
96 }
97} };