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

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

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ 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 #include <asm/neon.h>
  4 #include <asm/simd.h>
  5 #include <crypto/algapi.h>
  6 #include <crypto/sm4.h>
  7 #include <crypto/internal/simd.h>
  8 #include <linux/module.h>
  9 #include <linux/cpufeature.h>
 10 #include <linux/types.h>
 11 
 12 MODULE_ALIAS_CRYPTO("sm4");
 13 MODULE_ALIAS_CRYPTO("sm4-ce");
 14 MODULE_DESCRIPTION("SM4 symmetric cipher using ARMv8 Crypto Extensions");
 15 MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>");
 16 MODULE_LICENSE("GPL v2");
 17 
 18 asmlinkage void sm4_ce_do_crypt(const u32 *rk, void *out, const void *in);
 19 
 20 static int sm4_ce_setkey(struct crypto_tfm *tfm, const u8 *key,
 21                        unsigned int key_len)
 22 {
 23         struct sm4_ctx *ctx = crypto_tfm_ctx(tfm);
 24 
 25         return sm4_expandkey(ctx, key, key_len);
 26 }
 27 
 28 static void sm4_ce_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
 29 {
 30         const struct sm4_ctx *ctx = crypto_tfm_ctx(tfm);
 31 
 32         if (!crypto_simd_usable()) {
 33                 sm4_crypt_block(ctx->rkey_enc, out, in);
 34         } else {
 35                 kernel_neon_begin();
 36                 sm4_ce_do_crypt(ctx->rkey_enc, out, in);
 37                 kernel_neon_end();
 38         }
 39 }
 40 
 41 static void sm4_ce_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
 42 {
 43         const struct sm4_ctx *ctx = crypto_tfm_ctx(tfm);
 44 
 45         if (!crypto_simd_usable()) {
 46                 sm4_crypt_block(ctx->rkey_dec, out, in);
 47         } else {
 48                 kernel_neon_begin();
 49                 sm4_ce_do_crypt(ctx->rkey_dec, out, in);
 50                 kernel_neon_end();
 51         }
 52 }
 53 
 54 static struct crypto_alg sm4_ce_alg = {
 55         .cra_name                       = "sm4",
 56         .cra_driver_name                = "sm4-ce",
 57         .cra_priority                   = 300,
 58         .cra_flags                      = CRYPTO_ALG_TYPE_CIPHER,
 59         .cra_blocksize                  = SM4_BLOCK_SIZE,
 60         .cra_ctxsize                    = sizeof(struct sm4_ctx),
 61         .cra_module                     = THIS_MODULE,
 62         .cra_u.cipher = {
 63                 .cia_min_keysize        = SM4_KEY_SIZE,
 64                 .cia_max_keysize        = SM4_KEY_SIZE,
 65                 .cia_setkey             = sm4_ce_setkey,
 66                 .cia_encrypt            = sm4_ce_encrypt,
 67                 .cia_decrypt            = sm4_ce_decrypt
 68         }
 69 };
 70 
 71 static int __init sm4_ce_mod_init(void)
 72 {
 73         return crypto_register_alg(&sm4_ce_alg);
 74 }
 75 
 76 static void __exit sm4_ce_mod_fini(void)
 77 {
 78         crypto_unregister_alg(&sm4_ce_alg);
 79 }
 80 
 81 module_cpu_feature_match(SM4, sm4_ce_mod_init);
 82 module_exit(sm4_ce_mod_fini);
 83 

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