Commit | Line | Data |
---|---|---|
864cbeed AB |
1 | /* |
2 | * sha1-ce-glue.c - SHA-1 secure hash using ARMv8 Crypto Extensions | |
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> | |
12 | #include <crypto/sha.h> | |
dde00981 | 13 | #include <crypto/sha1_base.h> |
bd56f95e | 14 | #include <linux/cpufeature.h> |
864cbeed AB |
15 | #include <linux/crypto.h> |
16 | #include <linux/module.h> | |
17 | ||
864cbeed AB |
18 | #include <asm/hwcap.h> |
19 | #include <asm/neon.h> | |
20 | #include <asm/simd.h> | |
864cbeed | 21 | |
90451d6b AB |
22 | #include "sha1.h" |
23 | ||
864cbeed AB |
24 | MODULE_DESCRIPTION("SHA1 secure hash using ARMv8 Crypto Extensions"); |
25 | MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>"); | |
26 | MODULE_LICENSE("GPL v2"); | |
27 | ||
dde00981 AB |
28 | asmlinkage void sha1_ce_transform(struct sha1_state *sst, u8 const *src, |
29 | int blocks); | |
864cbeed | 30 | |
dde00981 AB |
31 | static int sha1_ce_update(struct shash_desc *desc, const u8 *data, |
32 | unsigned int len) | |
864cbeed AB |
33 | { |
34 | struct sha1_state *sctx = shash_desc_ctx(desc); | |
35 | ||
dde00981 AB |
36 | if (!may_use_simd() || |
37 | (sctx->count % SHA1_BLOCK_SIZE) + len < SHA1_BLOCK_SIZE) | |
864cbeed AB |
38 | return sha1_update_arm(desc, data, len); |
39 | ||
dde00981 AB |
40 | kernel_neon_begin(); |
41 | sha1_base_do_update(desc, data, len, sha1_ce_transform); | |
42 | kernel_neon_end(); | |
864cbeed | 43 | |
864cbeed AB |
44 | return 0; |
45 | } | |
46 | ||
dde00981 AB |
47 | static int sha1_ce_finup(struct shash_desc *desc, const u8 *data, |
48 | unsigned int len, u8 *out) | |
864cbeed | 49 | { |
dde00981 AB |
50 | if (!may_use_simd()) |
51 | return sha1_finup_arm(desc, data, len, out); | |
864cbeed | 52 | |
dde00981 AB |
53 | kernel_neon_begin(); |
54 | if (len) | |
55 | sha1_base_do_update(desc, data, len, sha1_ce_transform); | |
56 | sha1_base_do_finalize(desc, sha1_ce_transform); | |
57 | kernel_neon_end(); | |
864cbeed | 58 | |
dde00981 | 59 | return sha1_base_finish(desc, out); |
864cbeed AB |
60 | } |
61 | ||
dde00981 | 62 | static int sha1_ce_final(struct shash_desc *desc, u8 *out) |
864cbeed | 63 | { |
dde00981 | 64 | return sha1_ce_finup(desc, NULL, 0, out); |
864cbeed AB |
65 | } |
66 | ||
67 | static struct shash_alg alg = { | |
dde00981 AB |
68 | .init = sha1_base_init, |
69 | .update = sha1_ce_update, | |
70 | .final = sha1_ce_final, | |
71 | .finup = sha1_ce_finup, | |
864cbeed AB |
72 | .descsize = sizeof(struct sha1_state), |
73 | .digestsize = SHA1_DIGEST_SIZE, | |
864cbeed AB |
74 | .base = { |
75 | .cra_name = "sha1", | |
76 | .cra_driver_name = "sha1-ce", | |
77 | .cra_priority = 200, | |
864cbeed AB |
78 | .cra_blocksize = SHA1_BLOCK_SIZE, |
79 | .cra_module = THIS_MODULE, | |
80 | } | |
81 | }; | |
82 | ||
83 | static int __init sha1_ce_mod_init(void) | |
84 | { | |
864cbeed AB |
85 | return crypto_register_shash(&alg); |
86 | } | |
87 | ||
88 | static void __exit sha1_ce_mod_fini(void) | |
89 | { | |
90 | crypto_unregister_shash(&alg); | |
91 | } | |
92 | ||
bd56f95e | 93 | module_cpu_feature_match(SHA1, sha1_ce_mod_init); |
864cbeed | 94 | module_exit(sha1_ce_mod_fini); |