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

TOMOYO Linux Cross Reference
Linux/arch/arm64/crypto/sm3-neon-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-or-later
  2 /*
  3  * sm3-neon-glue.c - SM3 secure hash using NEON instructions
  4  *
  5  * Copyright (C) 2022 Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
  6  */
  7 
  8 #include <asm/neon.h>
  9 #include <asm/simd.h>
 10 #include <asm/unaligned.h>
 11 #include <crypto/internal/hash.h>
 12 #include <crypto/internal/simd.h>
 13 #include <crypto/sm3.h>
 14 #include <crypto/sm3_base.h>
 15 #include <linux/cpufeature.h>
 16 #include <linux/crypto.h>
 17 #include <linux/module.h>
 18 
 19 
 20 asmlinkage void sm3_neon_transform(struct sm3_state *sst, u8 const *src,
 21                                    int blocks);
 22 
 23 static int sm3_neon_update(struct shash_desc *desc, const u8 *data,
 24                            unsigned int len)
 25 {
 26         if (!crypto_simd_usable()) {
 27                 sm3_update(shash_desc_ctx(desc), data, len);
 28                 return 0;
 29         }
 30 
 31         kernel_neon_begin();
 32         sm3_base_do_update(desc, data, len, sm3_neon_transform);
 33         kernel_neon_end();
 34 
 35         return 0;
 36 }
 37 
 38 static int sm3_neon_final(struct shash_desc *desc, u8 *out)
 39 {
 40         if (!crypto_simd_usable()) {
 41                 sm3_final(shash_desc_ctx(desc), out);
 42                 return 0;
 43         }
 44 
 45         kernel_neon_begin();
 46         sm3_base_do_finalize(desc, sm3_neon_transform);
 47         kernel_neon_end();
 48 
 49         return sm3_base_finish(desc, out);
 50 }
 51 
 52 static int sm3_neon_finup(struct shash_desc *desc, const u8 *data,
 53                           unsigned int len, u8 *out)
 54 {
 55         if (!crypto_simd_usable()) {
 56                 struct sm3_state *sctx = shash_desc_ctx(desc);
 57 
 58                 if (len)
 59                         sm3_update(sctx, data, len);
 60                 sm3_final(sctx, out);
 61                 return 0;
 62         }
 63 
 64         kernel_neon_begin();
 65         if (len)
 66                 sm3_base_do_update(desc, data, len, sm3_neon_transform);
 67         sm3_base_do_finalize(desc, sm3_neon_transform);
 68         kernel_neon_end();
 69 
 70         return sm3_base_finish(desc, out);
 71 }
 72 
 73 static struct shash_alg sm3_alg = {
 74         .digestsize             = SM3_DIGEST_SIZE,
 75         .init                   = sm3_base_init,
 76         .update                 = sm3_neon_update,
 77         .final                  = sm3_neon_final,
 78         .finup                  = sm3_neon_finup,
 79         .descsize               = sizeof(struct sm3_state),
 80         .base.cra_name          = "sm3",
 81         .base.cra_driver_name   = "sm3-neon",
 82         .base.cra_blocksize     = SM3_BLOCK_SIZE,
 83         .base.cra_module        = THIS_MODULE,
 84         .base.cra_priority      = 200,
 85 };
 86 
 87 static int __init sm3_neon_init(void)
 88 {
 89         return crypto_register_shash(&sm3_alg);
 90 }
 91 
 92 static void __exit sm3_neon_fini(void)
 93 {
 94         crypto_unregister_shash(&sm3_alg);
 95 }
 96 
 97 module_init(sm3_neon_init);
 98 module_exit(sm3_neon_fini);
 99 
100 MODULE_DESCRIPTION("SM3 secure hash using NEON instructions");
101 MODULE_AUTHOR("Jussi Kivilinna <jussi.kivilinna@iki.fi>");
102 MODULE_AUTHOR("Tianjia Zhang <tianjia.zhang@linux.alibaba.com>");
103 MODULE_LICENSE("GPL v2");
104 

~ [ 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