~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/arm64/crypto/sha512-ce-glue.c

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 /*
  3  * sha512-ce-glue.c - SHA-384/SHA-512 using ARMv8 Crypto Extensions
  4  *
  5  * Copyright (C) 2018 Linaro Ltd <ard.biesheuvel@linaro.org>
  6  *
  7  * This program is free software; you can redistribute it and/or modify
  8  * it under the terms of the GNU General Public License version 2 as
  9  * published by the Free Software Foundation.
 10  */
 11 
 12 #include <asm/neon.h>
 13 #include <asm/simd.h>
 14 #include <asm/unaligned.h>
 15 #include <crypto/internal/hash.h>
 16 #include <crypto/internal/simd.h>
 17 #include <crypto/sha2.h>
 18 #include <crypto/sha512_base.h>
 19 #include <linux/cpufeature.h>
 20 #include <linux/crypto.h>
 21 #include <linux/module.h>
 22 
 23 MODULE_DESCRIPTION("SHA-384/SHA-512 secure hash using ARMv8 Crypto Extensions");
 24 MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>");
 25 MODULE_LICENSE("GPL v2");
 26 MODULE_ALIAS_CRYPTO("sha384");
 27 MODULE_ALIAS_CRYPTO("sha512");
 28 
 29 asmlinkage int __sha512_ce_transform(struct sha512_state *sst, u8 const *src,
 30                                      int blocks);
 31 
 32 asmlinkage void sha512_block_data_order(u64 *digest, u8 const *src, int blocks);
 33 
 34 static void sha512_ce_transform(struct sha512_state *sst, u8 const *src,
 35                                 int blocks)
 36 {
 37         while (blocks) {
 38                 int rem;
 39 
 40                 kernel_neon_begin();
 41                 rem = __sha512_ce_transform(sst, src, blocks);
 42                 kernel_neon_end();
 43                 src += (blocks - rem) * SHA512_BLOCK_SIZE;
 44                 blocks = rem;
 45         }
 46 }
 47 
 48 static void sha512_arm64_transform(struct sha512_state *sst, u8 const *src,
 49                                    int blocks)
 50 {
 51         sha512_block_data_order(sst->state, src, blocks);
 52 }
 53 
 54 static int sha512_ce_update(struct shash_desc *desc, const u8 *data,
 55                             unsigned int len)
 56 {
 57         sha512_block_fn *fn = crypto_simd_usable() ? sha512_ce_transform
 58                                                    : sha512_arm64_transform;
 59 
 60         sha512_base_do_update(desc, data, len, fn);
 61         return 0;
 62 }
 63 
 64 static int sha512_ce_finup(struct shash_desc *desc, const u8 *data,
 65                            unsigned int len, u8 *out)
 66 {
 67         sha512_block_fn *fn = crypto_simd_usable() ? sha512_ce_transform
 68                                                    : sha512_arm64_transform;
 69 
 70         sha512_base_do_update(desc, data, len, fn);
 71         sha512_base_do_finalize(desc, fn);
 72         return sha512_base_finish(desc, out);
 73 }
 74 
 75 static int sha512_ce_final(struct shash_desc *desc, u8 *out)
 76 {
 77         sha512_block_fn *fn = crypto_simd_usable() ? sha512_ce_transform
 78                                                    : sha512_arm64_transform;
 79 
 80         sha512_base_do_finalize(desc, fn);
 81         return sha512_base_finish(desc, out);
 82 }
 83 
 84 static struct shash_alg algs[] = { {
 85         .init                   = sha384_base_init,
 86         .update                 = sha512_ce_update,
 87         .final                  = sha512_ce_final,
 88         .finup                  = sha512_ce_finup,
 89         .descsize               = sizeof(struct sha512_state),
 90         .digestsize             = SHA384_DIGEST_SIZE,
 91         .base.cra_name          = "sha384",
 92         .base.cra_driver_name   = "sha384-ce",
 93         .base.cra_priority      = 200,
 94         .base.cra_blocksize     = SHA512_BLOCK_SIZE,
 95         .base.cra_module        = THIS_MODULE,
 96 }, {
 97         .init                   = sha512_base_init,
 98         .update                 = sha512_ce_update,
 99         .final                  = sha512_ce_final,
100         .finup                  = sha512_ce_finup,
101         .descsize               = sizeof(struct sha512_state),
102         .digestsize             = SHA512_DIGEST_SIZE,
103         .base.cra_name          = "sha512",
104         .base.cra_driver_name   = "sha512-ce",
105         .base.cra_priority      = 200,
106         .base.cra_blocksize     = SHA512_BLOCK_SIZE,
107         .base.cra_module        = THIS_MODULE,
108 } };
109 
110 static int __init sha512_ce_mod_init(void)
111 {
112         return crypto_register_shashes(algs, ARRAY_SIZE(algs));
113 }
114 
115 static void __exit sha512_ce_mod_fini(void)
116 {
117         crypto_unregister_shashes(algs, ARRAY_SIZE(algs));
118 }
119 
120 module_cpu_feature_match(SHA512, sha512_ce_mod_init);
121 module_exit(sha512_ce_mod_fini);
122 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php