2 * Glue code for the SHA256 Secure Hash Algorithm assembly implementation
3 * using optimized ARM assembler and NEON instructions.
5 * Copyright © 2015 Google Inc.
7 * This file is based on sha256_ssse3_glue.c:
8 * Copyright (C) 2013 Intel Corporation
9 * Author: Tim Chen <tim.c.chen@linux.intel.com>
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the Free
13 * Software Foundation; either version 2 of the License, or (at your option)
18 #include <crypto/internal/hash.h>
19 #include <linux/crypto.h>
20 #include <linux/init.h>
21 #include <linux/module.h>
23 #include <linux/cryptohash.h>
24 #include <linux/types.h>
25 #include <linux/string.h>
26 #include <crypto/sha.h>
27 #include <crypto/sha256_base.h>
31 #include "sha256_glue.h"
33 asmlinkage void sha256_block_data_order(struct sha256_state *state,
34 const u8 *data, int num_blks);
36 int crypto_sha256_arm_update(struct shash_desc *desc, const u8 *data,
39 /* make sure casting to sha256_block_fn() is safe */
40 BUILD_BUG_ON(offsetof(struct sha256_state, state) != 0);
42 return sha256_base_do_update(desc, data, len, sha256_block_data_order);
44 EXPORT_SYMBOL(crypto_sha256_arm_update);
46 static int crypto_sha256_arm_final(struct shash_desc *desc, u8 *out)
48 sha256_base_do_finalize(desc, sha256_block_data_order);
49 return sha256_base_finish(desc, out);
52 int crypto_sha256_arm_finup(struct shash_desc *desc, const u8 *data,
53 unsigned int len, u8 *out)
55 sha256_base_do_update(desc, data, len, sha256_block_data_order);
56 return crypto_sha256_arm_final(desc, out);
58 EXPORT_SYMBOL(crypto_sha256_arm_finup);
60 static struct shash_alg algs[] = { {
61 .digestsize = SHA256_DIGEST_SIZE,
62 .init = sha256_base_init,
63 .update = crypto_sha256_arm_update,
64 .final = crypto_sha256_arm_final,
65 .finup = crypto_sha256_arm_finup,
66 .descsize = sizeof(struct sha256_state),
69 .cra_driver_name = "sha256-asm",
71 .cra_blocksize = SHA256_BLOCK_SIZE,
72 .cra_module = THIS_MODULE,
75 .digestsize = SHA224_DIGEST_SIZE,
76 .init = sha224_base_init,
77 .update = crypto_sha256_arm_update,
78 .final = crypto_sha256_arm_final,
79 .finup = crypto_sha256_arm_finup,
80 .descsize = sizeof(struct sha256_state),
83 .cra_driver_name = "sha224-asm",
85 .cra_blocksize = SHA224_BLOCK_SIZE,
86 .cra_module = THIS_MODULE,
90 static int __init sha256_mod_init(void)
92 int res = crypto_register_shashes(algs, ARRAY_SIZE(algs));
97 if (IS_ENABLED(CONFIG_KERNEL_MODE_NEON) && cpu_has_neon()) {
98 res = crypto_register_shashes(sha256_neon_algs,
99 ARRAY_SIZE(sha256_neon_algs));
102 crypto_unregister_shashes(algs, ARRAY_SIZE(algs));
108 static void __exit sha256_mod_fini(void)
110 crypto_unregister_shashes(algs, ARRAY_SIZE(algs));
112 if (IS_ENABLED(CONFIG_KERNEL_MODE_NEON) && cpu_has_neon())
113 crypto_unregister_shashes(sha256_neon_algs,
114 ARRAY_SIZE(sha256_neon_algs));
117 module_init(sha256_mod_init);
118 module_exit(sha256_mod_fini);
120 MODULE_LICENSE("GPL");
121 MODULE_DESCRIPTION("SHA256 Secure Hash Algorithm (ARM), including NEON");
123 MODULE_ALIAS_CRYPTO("sha256");