]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - arch/arm/crypto/sha256_neon_glue.c
treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152
[mirror_ubuntu-hirsute-kernel.git] / arch / arm / crypto / sha256_neon_glue.c
CommitLineData
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/cryptohash.h>
15#include <linux/types.h>
16#include <linux/string.h>
17#include <crypto/sha.h>
b59e2ae3 18#include <crypto/sha256_base.h>
f2f770d7
ST
19#include <asm/byteorder.h>
20#include <asm/simd.h>
21#include <asm/neon.h>
b59e2ae3 22
f2f770d7
ST
23#include "sha256_glue.h"
24
25asmlinkage void sha256_block_data_order_neon(u32 *digest, const void *data,
b59e2ae3 26 unsigned int num_blks);
f2f770d7 27
b59e2ae3
AB
28static int sha256_update(struct shash_desc *desc, const u8 *data,
29 unsigned int len)
f2f770d7
ST
30{
31 struct sha256_state *sctx = shash_desc_ctx(desc);
f2f770d7 32
99680c5e 33 if (!crypto_simd_usable() ||
b59e2ae3
AB
34 (sctx->count % SHA256_BLOCK_SIZE) + len < SHA256_BLOCK_SIZE)
35 return crypto_sha256_arm_update(desc, data, len);
f2f770d7 36
b59e2ae3
AB
37 kernel_neon_begin();
38 sha256_base_do_update(desc, data, len,
39 (sha256_block_fn *)sha256_block_data_order_neon);
40 kernel_neon_end();
f2f770d7
ST
41
42 return 0;
43}
44
b59e2ae3
AB
45static int sha256_finup(struct shash_desc *desc, const u8 *data,
46 unsigned int len, u8 *out)
f2f770d7 47{
99680c5e 48 if (!crypto_simd_usable())
b59e2ae3
AB
49 return crypto_sha256_arm_finup(desc, data, len, out);
50
51 kernel_neon_begin();
52 if (len)
53 sha256_base_do_update(desc, data, len,
54 (sha256_block_fn *)sha256_block_data_order_neon);
55 sha256_base_do_finalize(desc,
56 (sha256_block_fn *)sha256_block_data_order_neon);
57 kernel_neon_end();
58
59 return sha256_base_finish(desc, out);
f2f770d7
ST
60}
61
b59e2ae3 62static int sha256_final(struct shash_desc *desc, u8 *out)
f2f770d7 63{
b59e2ae3 64 return sha256_finup(desc, NULL, 0, out);
f2f770d7
ST
65}
66
67struct shash_alg sha256_neon_algs[] = { {
68 .digestsize = SHA256_DIGEST_SIZE,
b59e2ae3
AB
69 .init = sha256_base_init,
70 .update = sha256_update,
71 .final = sha256_final,
72 .finup = sha256_finup,
f2f770d7 73 .descsize = sizeof(struct sha256_state),
f2f770d7
ST
74 .base = {
75 .cra_name = "sha256",
76 .cra_driver_name = "sha256-neon",
77 .cra_priority = 250,
f2f770d7
ST
78 .cra_blocksize = SHA256_BLOCK_SIZE,
79 .cra_module = THIS_MODULE,
80 }
81}, {
82 .digestsize = SHA224_DIGEST_SIZE,
b59e2ae3
AB
83 .init = sha224_base_init,
84 .update = sha256_update,
85 .final = sha256_final,
86 .finup = sha256_finup,
f2f770d7 87 .descsize = sizeof(struct sha256_state),
f2f770d7
ST
88 .base = {
89 .cra_name = "sha224",
90 .cra_driver_name = "sha224-neon",
91 .cra_priority = 250,
f2f770d7
ST
92 .cra_blocksize = SHA224_BLOCK_SIZE,
93 .cra_module = THIS_MODULE,
94 }
95} };