Merge tag 'for-linus-5.3-ofs1' of git://git.kernel.org/pub/scm/linux/kernel/git/hubca...
[linux-2.6-block.git] / arch / arm / crypto / sha1-ce-glue.c
CommitLineData
d2912cb1 1// SPDX-License-Identifier: GPL-2.0-only
864cbeed
AB
2/*
3 * sha1-ce-glue.c - SHA-1 secure hash using ARMv8 Crypto Extensions
4 *
5 * Copyright (C) 2015 Linaro Ltd <ard.biesheuvel@linaro.org>
864cbeed
AB
6 */
7
8#include <crypto/internal/hash.h>
99680c5e 9#include <crypto/internal/simd.h>
864cbeed 10#include <crypto/sha.h>
dde00981 11#include <crypto/sha1_base.h>
bd56f95e 12#include <linux/cpufeature.h>
864cbeed
AB
13#include <linux/crypto.h>
14#include <linux/module.h>
15
864cbeed
AB
16#include <asm/hwcap.h>
17#include <asm/neon.h>
18#include <asm/simd.h>
864cbeed 19
90451d6b
AB
20#include "sha1.h"
21
864cbeed
AB
22MODULE_DESCRIPTION("SHA1 secure hash using ARMv8 Crypto Extensions");
23MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>");
24MODULE_LICENSE("GPL v2");
25
dde00981
AB
26asmlinkage void sha1_ce_transform(struct sha1_state *sst, u8 const *src,
27 int blocks);
864cbeed 28
dde00981
AB
29static int sha1_ce_update(struct shash_desc *desc, const u8 *data,
30 unsigned int len)
864cbeed
AB
31{
32 struct sha1_state *sctx = shash_desc_ctx(desc);
33
99680c5e 34 if (!crypto_simd_usable() ||
dde00981 35 (sctx->count % SHA1_BLOCK_SIZE) + len < SHA1_BLOCK_SIZE)
864cbeed
AB
36 return sha1_update_arm(desc, data, len);
37
dde00981
AB
38 kernel_neon_begin();
39 sha1_base_do_update(desc, data, len, sha1_ce_transform);
40 kernel_neon_end();
864cbeed 41
864cbeed
AB
42 return 0;
43}
44
dde00981
AB
45static int sha1_ce_finup(struct shash_desc *desc, const u8 *data,
46 unsigned int len, u8 *out)
864cbeed 47{
99680c5e 48 if (!crypto_simd_usable())
dde00981 49 return sha1_finup_arm(desc, data, len, out);
864cbeed 50
dde00981
AB
51 kernel_neon_begin();
52 if (len)
53 sha1_base_do_update(desc, data, len, sha1_ce_transform);
54 sha1_base_do_finalize(desc, sha1_ce_transform);
55 kernel_neon_end();
864cbeed 56
dde00981 57 return sha1_base_finish(desc, out);
864cbeed
AB
58}
59
dde00981 60static int sha1_ce_final(struct shash_desc *desc, u8 *out)
864cbeed 61{
dde00981 62 return sha1_ce_finup(desc, NULL, 0, out);
864cbeed
AB
63}
64
65static struct shash_alg alg = {
dde00981
AB
66 .init = sha1_base_init,
67 .update = sha1_ce_update,
68 .final = sha1_ce_final,
69 .finup = sha1_ce_finup,
864cbeed
AB
70 .descsize = sizeof(struct sha1_state),
71 .digestsize = SHA1_DIGEST_SIZE,
864cbeed
AB
72 .base = {
73 .cra_name = "sha1",
74 .cra_driver_name = "sha1-ce",
75 .cra_priority = 200,
864cbeed
AB
76 .cra_blocksize = SHA1_BLOCK_SIZE,
77 .cra_module = THIS_MODULE,
78 }
79};
80
81static int __init sha1_ce_mod_init(void)
82{
864cbeed
AB
83 return crypto_register_shash(&alg);
84}
85
86static void __exit sha1_ce_mod_fini(void)
87{
88 crypto_unregister_shash(&alg);
89}
90
bd56f95e 91module_cpu_feature_match(SHA1, sha1_ce_mod_init);
864cbeed 92module_exit(sha1_ce_mod_fini);