Commit | Line | Data |
---|---|---|
2874c5fd | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
f2f770d7 ST |
2 | /* |
3 | * Glue code for the SHA256 Secure Hash Algorithm assembly implementation | |
4 | * using NEON instructions. | |
5 | * | |
3723c632 | 6 | * Copyright © 2015 Google Inc. |
f2f770d7 ST |
7 | * |
8 | * This file is based on sha512_neon_glue.c: | |
3723c632 | 9 | * Copyright © 2014 Jussi Kivilinna <jussi.kivilinna@iki.fi> |
f2f770d7 ST |
10 | */ |
11 | ||
12 | #include <crypto/internal/hash.h> | |
99680c5e | 13 | #include <crypto/internal/simd.h> |
f2f770d7 ST |
14 | #include <linux/types.h> |
15 | #include <linux/string.h> | |
a24d22b2 | 16 | #include <crypto/sha2.h> |
b59e2ae3 | 17 | #include <crypto/sha256_base.h> |
f2f770d7 ST |
18 | #include <asm/byteorder.h> |
19 | #include <asm/simd.h> | |
20 | #include <asm/neon.h> | |
b59e2ae3 | 21 | |
f2f770d7 ST |
22 | #include "sha256_glue.h" |
23 | ||
547ea1b1 HX |
24 | asmlinkage void sha256_block_data_order_neon(struct sha256_state *digest, |
25 | const u8 *data, int num_blks); | |
f2f770d7 | 26 | |
e4dcc1be HG |
27 | static int crypto_sha256_neon_update(struct shash_desc *desc, const u8 *data, |
28 | unsigned int len) | |
f2f770d7 ST |
29 | { |
30 | struct sha256_state *sctx = shash_desc_ctx(desc); | |
f2f770d7 | 31 | |
99680c5e | 32 | if (!crypto_simd_usable() || |
b59e2ae3 AB |
33 | (sctx->count % SHA256_BLOCK_SIZE) + len < SHA256_BLOCK_SIZE) |
34 | return crypto_sha256_arm_update(desc, data, len); | |
f2f770d7 | 35 | |
b59e2ae3 | 36 | kernel_neon_begin(); |
547ea1b1 | 37 | sha256_base_do_update(desc, data, len, sha256_block_data_order_neon); |
b59e2ae3 | 38 | kernel_neon_end(); |
f2f770d7 ST |
39 | |
40 | return 0; | |
41 | } | |
42 | ||
e4dcc1be HG |
43 | static int crypto_sha256_neon_finup(struct shash_desc *desc, const u8 *data, |
44 | unsigned int len, u8 *out) | |
f2f770d7 | 45 | { |
99680c5e | 46 | if (!crypto_simd_usable()) |
b59e2ae3 AB |
47 | return crypto_sha256_arm_finup(desc, data, len, out); |
48 | ||
49 | kernel_neon_begin(); | |
50 | if (len) | |
51 | sha256_base_do_update(desc, data, len, | |
547ea1b1 HX |
52 | sha256_block_data_order_neon); |
53 | sha256_base_do_finalize(desc, sha256_block_data_order_neon); | |
b59e2ae3 AB |
54 | kernel_neon_end(); |
55 | ||
56 | return sha256_base_finish(desc, out); | |
f2f770d7 ST |
57 | } |
58 | ||
e4dcc1be | 59 | static int crypto_sha256_neon_final(struct shash_desc *desc, u8 *out) |
f2f770d7 | 60 | { |
e4dcc1be | 61 | return crypto_sha256_neon_finup(desc, NULL, 0, out); |
f2f770d7 ST |
62 | } |
63 | ||
64 | struct shash_alg sha256_neon_algs[] = { { | |
65 | .digestsize = SHA256_DIGEST_SIZE, | |
b59e2ae3 | 66 | .init = sha256_base_init, |
e4dcc1be HG |
67 | .update = crypto_sha256_neon_update, |
68 | .final = crypto_sha256_neon_final, | |
69 | .finup = crypto_sha256_neon_finup, | |
f2f770d7 | 70 | .descsize = sizeof(struct sha256_state), |
f2f770d7 ST |
71 | .base = { |
72 | .cra_name = "sha256", | |
73 | .cra_driver_name = "sha256-neon", | |
74 | .cra_priority = 250, | |
f2f770d7 ST |
75 | .cra_blocksize = SHA256_BLOCK_SIZE, |
76 | .cra_module = THIS_MODULE, | |
77 | } | |
78 | }, { | |
79 | .digestsize = SHA224_DIGEST_SIZE, | |
b59e2ae3 | 80 | .init = sha224_base_init, |
e4dcc1be HG |
81 | .update = crypto_sha256_neon_update, |
82 | .final = crypto_sha256_neon_final, | |
83 | .finup = crypto_sha256_neon_finup, | |
f2f770d7 | 84 | .descsize = sizeof(struct sha256_state), |
f2f770d7 ST |
85 | .base = { |
86 | .cra_name = "sha224", | |
87 | .cra_driver_name = "sha224-neon", | |
88 | .cra_priority = 250, | |
f2f770d7 ST |
89 | .cra_blocksize = SHA224_BLOCK_SIZE, |
90 | .cra_module = THIS_MODULE, | |
91 | } | |
92 | } }; |