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

TOMOYO Linux Cross Reference
Linux/crypto/sm4_generic.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ 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.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /crypto/sm4_generic.c (Version linux-6.12-rc7) and /crypto/sm4_generic.c (Version linux-6.8.12)


  1 // SPDX-License-Identifier: GPL-2.0                 1 // SPDX-License-Identifier: GPL-2.0
  2                                                     2 
  3 /*                                                  3 /*
  4  * SM4 Cipher Algorithm.                            4  * SM4 Cipher Algorithm.
  5  *                                                  5  *
  6  * Copyright (C) 2018 ARM Limited or its affil      6  * Copyright (C) 2018 ARM Limited or its affiliates.
  7  * All rights reserved.                             7  * All rights reserved.
  8  */                                                 8  */
  9                                                     9 
 10 #include <crypto/algapi.h>                         10 #include <crypto/algapi.h>
 11 #include <crypto/sm4.h>                            11 #include <crypto/sm4.h>
 12 #include <linux/module.h>                          12 #include <linux/module.h>
 13 #include <linux/init.h>                            13 #include <linux/init.h>
 14 #include <linux/types.h>                           14 #include <linux/types.h>
 15 #include <linux/errno.h>                           15 #include <linux/errno.h>
 16 #include <asm/byteorder.h>                         16 #include <asm/byteorder.h>
 17 #include <linux/unaligned.h>                   !!  17 #include <asm/unaligned.h>
 18                                                    18 
 19 /**                                                19 /**
 20  * sm4_setkey - Set the SM4 key.                   20  * sm4_setkey - Set the SM4 key.
 21  * @tfm:        The %crypto_tfm that is used i     21  * @tfm:        The %crypto_tfm that is used in the context.
 22  * @in_key:     The input key.                     22  * @in_key:     The input key.
 23  * @key_len:    The size of the key.               23  * @key_len:    The size of the key.
 24  *                                                 24  *
 25  * This function uses sm4_expandkey() to expan     25  * This function uses sm4_expandkey() to expand the key.
 26  * &sm4_ctx _must_ be the private data embedde     26  * &sm4_ctx _must_ be the private data embedded in @tfm which is
 27  * retrieved with crypto_tfm_ctx().                27  * retrieved with crypto_tfm_ctx().
 28  *                                                 28  *
 29  * Return: 0 on success; -EINVAL on failure (o     29  * Return: 0 on success; -EINVAL on failure (only happens for bad key lengths)
 30  */                                                30  */
 31 static int sm4_setkey(struct crypto_tfm *tfm,      31 static int sm4_setkey(struct crypto_tfm *tfm, const u8 *in_key,
 32                        unsigned int key_len)       32                        unsigned int key_len)
 33 {                                                  33 {
 34         struct sm4_ctx *ctx = crypto_tfm_ctx(t     34         struct sm4_ctx *ctx = crypto_tfm_ctx(tfm);
 35                                                    35 
 36         return sm4_expandkey(ctx, in_key, key_     36         return sm4_expandkey(ctx, in_key, key_len);
 37 }                                                  37 }
 38                                                    38 
 39 /* encrypt a block of text */                      39 /* encrypt a block of text */
 40                                                    40 
 41 static void sm4_encrypt(struct crypto_tfm *tfm     41 static void sm4_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
 42 {                                                  42 {
 43         const struct sm4_ctx *ctx = crypto_tfm     43         const struct sm4_ctx *ctx = crypto_tfm_ctx(tfm);
 44                                                    44 
 45         sm4_crypt_block(ctx->rkey_enc, out, in     45         sm4_crypt_block(ctx->rkey_enc, out, in);
 46 }                                                  46 }
 47                                                    47 
 48 /* decrypt a block of text */                      48 /* decrypt a block of text */
 49                                                    49 
 50 static void sm4_decrypt(struct crypto_tfm *tfm     50 static void sm4_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
 51 {                                                  51 {
 52         const struct sm4_ctx *ctx = crypto_tfm     52         const struct sm4_ctx *ctx = crypto_tfm_ctx(tfm);
 53                                                    53 
 54         sm4_crypt_block(ctx->rkey_dec, out, in     54         sm4_crypt_block(ctx->rkey_dec, out, in);
 55 }                                                  55 }
 56                                                    56 
 57 static struct crypto_alg sm4_alg = {               57 static struct crypto_alg sm4_alg = {
 58         .cra_name               =       "sm4",     58         .cra_name               =       "sm4",
 59         .cra_driver_name        =       "sm4-g     59         .cra_driver_name        =       "sm4-generic",
 60         .cra_priority           =       100,       60         .cra_priority           =       100,
 61         .cra_flags              =       CRYPTO     61         .cra_flags              =       CRYPTO_ALG_TYPE_CIPHER,
 62         .cra_blocksize          =       SM4_BL     62         .cra_blocksize          =       SM4_BLOCK_SIZE,
 63         .cra_ctxsize            =       sizeof     63         .cra_ctxsize            =       sizeof(struct sm4_ctx),
 64         .cra_module             =       THIS_M     64         .cra_module             =       THIS_MODULE,
 65         .cra_u                  =       {          65         .cra_u                  =       {
 66                 .cipher = {                        66                 .cipher = {
 67                         .cia_min_keysize           67                         .cia_min_keysize        =       SM4_KEY_SIZE,
 68                         .cia_max_keysize           68                         .cia_max_keysize        =       SM4_KEY_SIZE,
 69                         .cia_setkey                69                         .cia_setkey             =       sm4_setkey,
 70                         .cia_encrypt               70                         .cia_encrypt            =       sm4_encrypt,
 71                         .cia_decrypt               71                         .cia_decrypt            =       sm4_decrypt
 72                 }                                  72                 }
 73         }                                          73         }
 74 };                                                 74 };
 75                                                    75 
 76 static int __init sm4_init(void)                   76 static int __init sm4_init(void)
 77 {                                                  77 {
 78         return crypto_register_alg(&sm4_alg);      78         return crypto_register_alg(&sm4_alg);
 79 }                                                  79 }
 80                                                    80 
 81 static void __exit sm4_fini(void)                  81 static void __exit sm4_fini(void)
 82 {                                                  82 {
 83         crypto_unregister_alg(&sm4_alg);           83         crypto_unregister_alg(&sm4_alg);
 84 }                                                  84 }
 85                                                    85 
 86 subsys_initcall(sm4_init);                         86 subsys_initcall(sm4_init);
 87 module_exit(sm4_fini);                             87 module_exit(sm4_fini);
 88                                                    88 
 89 MODULE_DESCRIPTION("SM4 Cipher Algorithm");        89 MODULE_DESCRIPTION("SM4 Cipher Algorithm");
 90 MODULE_LICENSE("GPL v2");                          90 MODULE_LICENSE("GPL v2");
 91 MODULE_ALIAS_CRYPTO("sm4");                        91 MODULE_ALIAS_CRYPTO("sm4");
 92 MODULE_ALIAS_CRYPTO("sm4-generic");                92 MODULE_ALIAS_CRYPTO("sm4-generic");
 93                                                    93 

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