Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * Linux/arm64 port of the OpenSSL SHA512 implementation for AArch64
0004  *
0005  * Copyright (c) 2016 Linaro Ltd. <ard.biesheuvel@linaro.org>
0006  */
0007 
0008 #include <crypto/internal/hash.h>
0009 #include <linux/types.h>
0010 #include <linux/string.h>
0011 #include <crypto/sha2.h>
0012 #include <crypto/sha512_base.h>
0013 #include <asm/neon.h>
0014 
0015 MODULE_DESCRIPTION("SHA-384/SHA-512 secure hash for arm64");
0016 MODULE_AUTHOR("Andy Polyakov <appro@openssl.org>");
0017 MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>");
0018 MODULE_LICENSE("GPL v2");
0019 MODULE_ALIAS_CRYPTO("sha384");
0020 MODULE_ALIAS_CRYPTO("sha512");
0021 
0022 asmlinkage void sha512_block_data_order(u64 *digest, const void *data,
0023                     unsigned int num_blks);
0024 EXPORT_SYMBOL(sha512_block_data_order);
0025 
0026 static void __sha512_block_data_order(struct sha512_state *sst, u8 const *src,
0027                       int blocks)
0028 {
0029     sha512_block_data_order(sst->state, src, blocks);
0030 }
0031 
0032 static int sha512_update(struct shash_desc *desc, const u8 *data,
0033              unsigned int len)
0034 {
0035     return sha512_base_do_update(desc, data, len,
0036                      __sha512_block_data_order);
0037 }
0038 
0039 static int sha512_finup(struct shash_desc *desc, const u8 *data,
0040             unsigned int len, u8 *out)
0041 {
0042     if (len)
0043         sha512_base_do_update(desc, data, len,
0044                       __sha512_block_data_order);
0045     sha512_base_do_finalize(desc, __sha512_block_data_order);
0046 
0047     return sha512_base_finish(desc, out);
0048 }
0049 
0050 static int sha512_final(struct shash_desc *desc, u8 *out)
0051 {
0052     return sha512_finup(desc, NULL, 0, out);
0053 }
0054 
0055 static struct shash_alg algs[] = { {
0056     .digestsize     = SHA512_DIGEST_SIZE,
0057     .init           = sha512_base_init,
0058     .update         = sha512_update,
0059     .final          = sha512_final,
0060     .finup          = sha512_finup,
0061     .descsize       = sizeof(struct sha512_state),
0062     .base.cra_name      = "sha512",
0063     .base.cra_driver_name   = "sha512-arm64",
0064     .base.cra_priority  = 150,
0065     .base.cra_blocksize = SHA512_BLOCK_SIZE,
0066     .base.cra_module    = THIS_MODULE,
0067 }, {
0068     .digestsize     = SHA384_DIGEST_SIZE,
0069     .init           = sha384_base_init,
0070     .update         = sha512_update,
0071     .final          = sha512_final,
0072     .finup          = sha512_finup,
0073     .descsize       = sizeof(struct sha512_state),
0074     .base.cra_name      = "sha384",
0075     .base.cra_driver_name   = "sha384-arm64",
0076     .base.cra_priority  = 150,
0077     .base.cra_blocksize = SHA384_BLOCK_SIZE,
0078     .base.cra_module    = THIS_MODULE,
0079 } };
0080 
0081 static int __init sha512_mod_init(void)
0082 {
0083     return crypto_register_shashes(algs, ARRAY_SIZE(algs));
0084 }
0085 
0086 static void __exit sha512_mod_fini(void)
0087 {
0088     crypto_unregister_shashes(algs, ARRAY_SIZE(algs));
0089 }
0090 
0091 module_init(sha512_mod_init);
0092 module_exit(sha512_mod_fini);