0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #include <crypto/internal/hash.h>
0014 #include <linux/crypto.h>
0015 #include <linux/init.h>
0016 #include <linux/module.h>
0017 #include <linux/mm.h>
0018 #include <linux/types.h>
0019 #include <linux/string.h>
0020 #include <crypto/sha2.h>
0021 #include <crypto/sha256_base.h>
0022 #include <asm/simd.h>
0023 #include <asm/neon.h>
0024
0025 #include "sha256_glue.h"
0026
0027 asmlinkage void sha256_block_data_order(u32 *digest, const void *data,
0028 unsigned int num_blks);
0029
0030 int crypto_sha256_arm_update(struct shash_desc *desc, const u8 *data,
0031 unsigned int len)
0032 {
0033
0034 BUILD_BUG_ON(offsetof(struct sha256_state, state) != 0);
0035
0036 return sha256_base_do_update(desc, data, len,
0037 (sha256_block_fn *)sha256_block_data_order);
0038 }
0039 EXPORT_SYMBOL(crypto_sha256_arm_update);
0040
0041 static int crypto_sha256_arm_final(struct shash_desc *desc, u8 *out)
0042 {
0043 sha256_base_do_finalize(desc,
0044 (sha256_block_fn *)sha256_block_data_order);
0045 return sha256_base_finish(desc, out);
0046 }
0047
0048 int crypto_sha256_arm_finup(struct shash_desc *desc, const u8 *data,
0049 unsigned int len, u8 *out)
0050 {
0051 sha256_base_do_update(desc, data, len,
0052 (sha256_block_fn *)sha256_block_data_order);
0053 return crypto_sha256_arm_final(desc, out);
0054 }
0055 EXPORT_SYMBOL(crypto_sha256_arm_finup);
0056
0057 static struct shash_alg algs[] = { {
0058 .digestsize = SHA256_DIGEST_SIZE,
0059 .init = sha256_base_init,
0060 .update = crypto_sha256_arm_update,
0061 .final = crypto_sha256_arm_final,
0062 .finup = crypto_sha256_arm_finup,
0063 .descsize = sizeof(struct sha256_state),
0064 .base = {
0065 .cra_name = "sha256",
0066 .cra_driver_name = "sha256-asm",
0067 .cra_priority = 150,
0068 .cra_blocksize = SHA256_BLOCK_SIZE,
0069 .cra_module = THIS_MODULE,
0070 }
0071 }, {
0072 .digestsize = SHA224_DIGEST_SIZE,
0073 .init = sha224_base_init,
0074 .update = crypto_sha256_arm_update,
0075 .final = crypto_sha256_arm_final,
0076 .finup = crypto_sha256_arm_finup,
0077 .descsize = sizeof(struct sha256_state),
0078 .base = {
0079 .cra_name = "sha224",
0080 .cra_driver_name = "sha224-asm",
0081 .cra_priority = 150,
0082 .cra_blocksize = SHA224_BLOCK_SIZE,
0083 .cra_module = THIS_MODULE,
0084 }
0085 } };
0086
0087 static int __init sha256_mod_init(void)
0088 {
0089 int res = crypto_register_shashes(algs, ARRAY_SIZE(algs));
0090
0091 if (res < 0)
0092 return res;
0093
0094 if (IS_ENABLED(CONFIG_KERNEL_MODE_NEON) && cpu_has_neon()) {
0095 res = crypto_register_shashes(sha256_neon_algs,
0096 ARRAY_SIZE(sha256_neon_algs));
0097
0098 if (res < 0)
0099 crypto_unregister_shashes(algs, ARRAY_SIZE(algs));
0100 }
0101
0102 return res;
0103 }
0104
0105 static void __exit sha256_mod_fini(void)
0106 {
0107 crypto_unregister_shashes(algs, ARRAY_SIZE(algs));
0108
0109 if (IS_ENABLED(CONFIG_KERNEL_MODE_NEON) && cpu_has_neon())
0110 crypto_unregister_shashes(sha256_neon_algs,
0111 ARRAY_SIZE(sha256_neon_algs));
0112 }
0113
0114 module_init(sha256_mod_init);
0115 module_exit(sha256_mod_fini);
0116
0117 MODULE_LICENSE("GPL");
0118 MODULE_DESCRIPTION("SHA256 Secure Hash Algorithm (ARM), including NEON");
0119
0120 MODULE_ALIAS_CRYPTO("sha256");