]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - arch/arm64/crypto/sha512-glue.c
sfc: don't try and read ef10 data on non-ef10 NIC
[karo-tx-linux.git] / arch / arm64 / crypto / sha512-glue.c
1 /*
2  * Linux/arm64 port of the OpenSSL SHA512 implementation for AArch64
3  *
4  * Copyright (c) 2016 Linaro Ltd. <ard.biesheuvel@linaro.org>
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the Free
8  * Software Foundation; either version 2 of the License, or (at your option)
9  * any later version.
10  *
11  */
12
13 #include <crypto/internal/hash.h>
14 #include <linux/cryptohash.h>
15 #include <linux/types.h>
16 #include <linux/string.h>
17 #include <crypto/sha.h>
18 #include <crypto/sha512_base.h>
19 #include <asm/neon.h>
20
21 MODULE_DESCRIPTION("SHA-384/SHA-512 secure hash for arm64");
22 MODULE_AUTHOR("Andy Polyakov <appro@openssl.org>");
23 MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>");
24 MODULE_LICENSE("GPL v2");
25 MODULE_ALIAS_CRYPTO("sha384");
26 MODULE_ALIAS_CRYPTO("sha512");
27
28 asmlinkage void sha512_block_data_order(u32 *digest, const void *data,
29                                         unsigned int num_blks);
30
31 static int sha512_update(struct shash_desc *desc, const u8 *data,
32                          unsigned int len)
33 {
34         return sha512_base_do_update(desc, data, len,
35                         (sha512_block_fn *)sha512_block_data_order);
36 }
37
38 static int sha512_finup(struct shash_desc *desc, const u8 *data,
39                         unsigned int len, u8 *out)
40 {
41         if (len)
42                 sha512_base_do_update(desc, data, len,
43                         (sha512_block_fn *)sha512_block_data_order);
44         sha512_base_do_finalize(desc,
45                         (sha512_block_fn *)sha512_block_data_order);
46
47         return sha512_base_finish(desc, out);
48 }
49
50 static int sha512_final(struct shash_desc *desc, u8 *out)
51 {
52         return sha512_finup(desc, NULL, 0, out);
53 }
54
55 static struct shash_alg algs[] = { {
56         .digestsize             = SHA512_DIGEST_SIZE,
57         .init                   = sha512_base_init,
58         .update                 = sha512_update,
59         .final                  = sha512_final,
60         .finup                  = sha512_finup,
61         .descsize               = sizeof(struct sha512_state),
62         .base.cra_name          = "sha512",
63         .base.cra_driver_name   = "sha512-arm64",
64         .base.cra_priority      = 150,
65         .base.cra_flags         = CRYPTO_ALG_TYPE_SHASH,
66         .base.cra_blocksize     = SHA512_BLOCK_SIZE,
67         .base.cra_module        = THIS_MODULE,
68 }, {
69         .digestsize             = SHA384_DIGEST_SIZE,
70         .init                   = sha384_base_init,
71         .update                 = sha512_update,
72         .final                  = sha512_final,
73         .finup                  = sha512_finup,
74         .descsize               = sizeof(struct sha512_state),
75         .base.cra_name          = "sha384",
76         .base.cra_driver_name   = "sha384-arm64",
77         .base.cra_priority      = 150,
78         .base.cra_flags         = CRYPTO_ALG_TYPE_SHASH,
79         .base.cra_blocksize     = SHA384_BLOCK_SIZE,
80         .base.cra_module        = THIS_MODULE,
81 } };
82
83 static int __init sha512_mod_init(void)
84 {
85         return crypto_register_shashes(algs, ARRAY_SIZE(algs));
86 }
87
88 static void __exit sha512_mod_fini(void)
89 {
90         crypto_unregister_shashes(algs, ARRAY_SIZE(algs));
91 }
92
93 module_init(sha512_mod_init);
94 module_exit(sha512_mod_fini);